# Creating a custom log message categorie

**URL:** https://discourse.julialang.org/t/creating-a-custom-log-message-categorie/29295
**Category:** General Usage
**Tags:** question
**Created:** [September 29, 2019, 3:23pm UTC](https://discourse.julialang.org/t/creating-a-custom-log-message-categorie/29295 "2019-09-29T15:23:32Z")
**Posts on this page:** 1
**Showing post:** 17

<div class="post-metadata">

### Author: ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)
#### Post date: [October 25, 2019, 4:25am UTC](https://discourse.julialang.org/t/creating-a-custom-log-message-categorie/29295/17 "2019-10-25T04:25:52Z")

</div>

Why not just define a new log level type? Since logging code mostly do duck typing, it works with a few methods and there is no need for type-piracy. The downside may be that some third-party loggers may explicitly expect `LogLevel`.

```julia
using Logging

struct MyLogLevel
    level::Int32
end

const Trace = MyLogLevel(-10_000)

Base.isless(a::MyLogLevel, b::LogLevel) = isless(a.level, b.level)
Base.isless(a::LogLevel, b::MyLogLevel) = isless(a.level, b.level)
Base.convert(::Type{LogLevel}, level::MyLogLevel) = LogLevel(level.level)
Base.show(io::IO, level::MyLogLevel) =
    if level == Trace
        print(io, "Trace")
    else
        show(io, LogLevel(level))
    end

Logging.disable_logging(Logging.BelowMinLevel)

with_logger(ConsoleLogger(stderr, convert(LogLevel, Trace))) do
    @logmsg Trace "message"
end

```

---

_[View the full topic](https://discourse.julialang.org/t/creating-a-custom-log-message-categorie/29295)._
