Using @debug in Atom console

Including code vs. typing into console produces different behavior. Why?

The file debug.jl contains the following code.

using Base.CoreLogging: Debug, global_logger
using Logging: ConsoleLogger
global_logger(ConsoleLogger(stderr, Debug))
a = 1
@debug "debug test" a
@info "info test" a
@warn "warn test" a
@error "error test" a

In the console.

Press Enter to start Julia.
Starting Julia...
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.0.1 (2018-09-29)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> include("debug.jl")
┌ Info: info test
└   a = 1
┌ Warning: warn test
│   a = 1
└ @ Main C:\Users\Chris\Desktop\debug\debug.jl:7
┌ Error: error test
│   a = 1
└ @ Main C:\Users\Chris\Desktop\debug\debug.jl:8

julia> using Base.CoreLogging: Debug, global_logger

julia> using Logging: ConsoleLogger

julia> global_logger(ConsoleLogger(stderr, Debug))
ConsoleLogger(Base.TTY(Base.Libc.WindowsRawSocket(0x00000000000002b0) open, 0 bytes waiting), Debug, Logging.default_metafmt, true, 0, Dict{Any,Int64}())

julia> a = 1
1

julia> @debug "debug test" a
┌ Debug: debug test
│   a = 1
└ @ Main none:1

julia>

Why doesn’t the debug information display when the file is included?

That’s a bug in Atom.jl which should be fixed on master. See

for details.

Thank you!

Just updated Atom.jl to masterv 0.7.8+ and updated julia-client to 0.7.8. This did not fix the problem.

Why would there ever be a difference between including a file and typing in the content of the file?

Hm, indeed. What happens is that we eval all code wrapped in a with_logger(JuliaProgressLogger(current_logger())), where the progress logger only handles certain logs and pipes the rest of them to the (cached) current_logger(). So if you change the global logger inside of that with_logger block it’ll never be called.
I don’t think there’s a good way to handle this on our end – you’ll either need to wrap your code in e.g.

with_logger(ConsoleLogger(stderr, Debug)) do
    @debug "debug test" a
    @info "info test" a
    @warn "warn test" a
    @error "error test" a
end

or set the global logger separately.

1 Like

That works. Thank You!