# How to Change LogLevel with Logging Package?

**URL:** <https://discourse.julialang.org/t/how-to-change-loglevel-with-logging-package/17501>\
**Category:** General Usage\
**Created:** [November 14, 2018, 4:09am UTC](https://discourse.julialang.org/t/how-to-change-loglevel-with-logging-package/17501 "2018-11-14T04:09:01Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [November 14, 2018, 5:20am UTC](https://discourse.julialang.org/t/how-to-change-loglevel-with-logging-package/17501/2 "2018-11-14T05:20:40Z")

</div>

First of all, welcome! Yes, this is the right place for such a question. 🙂

Logging in Julia works by having a Logger with certain properties do the actual logging. In case of the `SimpleLogger` from `Base`, you have to specify the minimum LogLevel at [creation of the logger](https://docs.julialang.org/en/v1/stdlib/Logging/#Base.CoreLogging.SimpleLogger):

```julia
julia> using Logging

julia> logger = SimpleLogger(stdout, Logging.Debug)
SimpleLogger(Base.TTY(RawFD(0x0000000d) open, 0 bytes waiting), Debug, Dict{Any,Int64}())

julia> @info "info level!"
[ Info: info level!

julia> @debug "debug level!"

julia> old_logger = global_logger(logger) # change the global logger to show debug output!
ConsoleLogger(Base.TTY(RawFD(0x0000000f) open, 0 bytes waiting), Info, Logging.default_metafmt, true, 0, Dict{Any,Int64}())

julia> @debug "debug level!"
┌ Debug: debug level!
└ @ Main REPL[7]:1

```

The predefined Loggers `ConsoleLogger` and `SimpleLogger` log messages with a LogLevel greater than or equal to the one specified during their creation - the default active logger only shows level `Info` and above:

```julia
julia> with_logger(old_logger) do
           @info "Info is here"
           @debug "Debug is not"
       end
[ Info: Info is here

```

Note also that `Logging.Debug` is a predefined `LogLevel` object:

```julia
help?> Logging.Debug
  No documentation found.

  Base.CoreLogging.Debug is of type LogLevel.

  Summary
  ≡≡≡≡≡≡≡≡≡

  struct LogLevel <: Any

  Fields
  ≡≡≡≡≡≡≡≡

  level :: Int32

```

There’s also a few packages providing more complex loggers, for example logging to any kind of IO based on the LogLevel ([IOLogging.jl](https://github.com/Seelengrab/IOLogging.jl)) or e.g. the `FilteredLogger` allowing better filtering of log messages when creating them ([LoggingExtras.jl](https://github.com/oxinabox/LoggingExtras.jl)).

---

_[View the full topic](https://discourse.julialang.org/t/how-to-change-loglevel-with-logging-package/17501)._
