# Using @debug in Atom console

**URL:** <https://discourse.julialang.org/t/using-debug-in-atom-console/15833>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 3, 2018, 4:40pm UTC](https://discourse.julialang.org/t/using-debug-in-atom-console/15833 "2018-10-03T16:40:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstook](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstook/32/3731_2.png) [@cstook](https://discourse.julialang.org/u/cstook)\
**Post date:** [October 3, 2018, 4:40pm UTC](https://discourse.julialang.org/t/using-debug-in-atom-console/15833/1 "2018-10-03T16:40:55Z")

</div>

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

The file debug.jl contains the following code.

```julia
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.

```julia
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?

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [October 4, 2018, 12:15pm UTC](https://discourse.julialang.org/t/using-debug-in-atom-console/15833/2 "2018-10-04T12:15:18Z")

</div>

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

> [@Custom logger in Atom?](https://discourse.julialang.org/t/custom-logger-in-atom/15609):
>
> I’d like to customize the response to @info, as in the long quote below. I find this useful for debugging package tests. This works in REPL (Julia 0.7) but not in Atom, where the current logger is wrapped in a JunoProgressLogger (Atom/src/comm.jl:96 or :109). Since loggers are immutable, I believe the only way to do this is to define a new logger. I have tried to detect Atom, and when in Atom setting the new logger like this: Logging.global\_logger(Atom.Progress.JunoProgressLogger(TESTLOGR)) ……

for details.

---

<div class="post-metadata">

**Author:** ![cstook](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstook/32/3731_2.png) [@cstook](https://discourse.julialang.org/u/cstook)\
**Post date:** [October 4, 2018, 2:32pm UTC](https://discourse.julialang.org/t/using-debug-in-atom-console/15833/3 "2018-10-04T14:32:09Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![cstook](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstook/32/3731_2.png) [@cstook](https://discourse.julialang.org/u/cstook)\
**Post date:** [October 4, 2018, 4:04pm UTC](https://discourse.julialang.org/t/using-debug-in-atom-console/15833/4 "2018-10-04T16:04:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [October 4, 2018, 5:33pm UTC](https://discourse.julialang.org/t/using-debug-in-atom-console/15833/5 "2018-10-04T17:33:11Z")

</div>

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.

```julia
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.

---

<div class="post-metadata">

**Author:** ![cstook](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstook/32/3731_2.png) [@cstook](https://discourse.julialang.org/u/cstook)\
**Post date:** [October 4, 2018, 9:50pm UTC](https://discourse.julialang.org/t/using-debug-in-atom-console/15833/6 "2018-10-04T21:50:47Z")

</div>

That works. Thank You!
