# Controlling the new Logger (@debug messages)

**URL:** <https://discourse.julialang.org/t/controlling-the-new-logger-debug-messages/13732>\
**Category:** General Usage\
**Tags:** debug\
**Created:** [August 19, 2018, 9:11pm UTC](https://discourse.julialang.org/t/controlling-the-new-logger-debug-messages/13732 "2018-08-19T21:11:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glen/32/3583_2.png) [@Glen](https://discourse.julialang.org/u/Glen)\
**Post date:** [August 19, 2018, 9:11pm UTC](https://discourse.julialang.org/t/controlling-the-new-logger-debug-messages/13732/1 "2018-08-19T21:11:45Z")

</div>

In 1.0 the new logging system has the `@debug` macro which only gets run if you turn on debug logging so no loss in performance. I can’t however figure out how to change the log level to get `@debug` messages to be printed. I’ve tried:

```julia
julia> using Logger

julia> disable_logging(LogLevel(-100000))
LogLevel(-99999)

julia> @debug "hi"

```

But still can’t turn on logging of `@debug` messages. I’ve tried searching github but can’t find anyone using `@debug` logging macros. I would like so see a few examples:

1. How to turn on `@debug` macros for a single function body?
2. How to turn it on globally?
3. How to enable it in the REPL for all future commands?

Glen

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [August 19, 2018, 10:19pm UTC](https://discourse.julialang.org/t/controlling-the-new-logger-debug-messages/13732/2 "2018-08-19T22:19:05Z")

</div>

You need to establish a new logger, since they are immutable:

```julia

julia-1.0> logger=Logging.SimpleLogger(stderr,Logging.Debug)
Base.CoreLogging.SimpleLogger(Base.TTY(RawFD(0x0000000f) open, 0 bytes waiting), Debug, Dict{Any,Int64}())

julia-1.0> function foo(x)
           if x<5
           @debug "small"
           else
           @info "big"
           end
           end
foo (generic function with 1 method)

julia-1.0> Logging.with_logger(logger) do
           foo(10)
           foo(3)
           end
┌ Info: big
└ @ Main REPL[37]:5
┌ Debug: small
└ @ Main REPL[37]:3

```

You can swap out the one generally in use with `global_logger` (save the normal one with `current_logger`).

---

<div class="post-metadata">

**Author:** ![ctroupin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctroupin/32/8909_2.png) [@ctroupin](https://discourse.julialang.org/u/ctroupin)\
**Post date:** [October 15, 2018, 6:34pm UTC](https://discourse.julialang.org/t/controlling-the-new-logger-debug-messages/13732/3 "2018-10-15T18:34:30Z")

</div>

> [@Glen](#):
>
> How to turn it on globally?

I had the same doubt, so I tried to modify the environment variable like this:

```julia
ENV["JULIA_DEBUG"] = "all"

```

(see doc here: [Logging · The Julia Language](https://docs.julialang.org/en/v1/stdlib/Logging/#Environment-variables-1))  
and now the `@debug` messages are always visible.
