JULIA_DEBUG environment variable

I don’t understand how JULIA_DEBUG environment variable works.

module A
foo() = @debug "foo"
end

A.foo() # nothing printed

ENV["JULIA_DEBUG"] = Main.A

A.foo() # nothing printed

Why nothing is printed there?
However if I do:

ENV["JULIA_DEBUG"] = Main

A.foo()

Then there is the debug message printed.

It seems that the documentation
https://docs.julialang.org/en/v1.7/stdlib/Logging/#Environment-variables
is not clear enough or perhaps a bit wrong.
You may open an issue.

I think the proper way of setting ENV[“JULIA_DEBUG”] are perhaps string values, but I am not sure here and didn’t dive into code:

julia> module A
       foo() = @debug "foo"
       end
Main.A

julia> A.foo()

julia> @debug "foo"

julia> ENV["JULIA_DEBUG"] = "A"
"A"

julia> A.foo()
┌ Debug: foo
└ @ Main.A REPL[1]:2

julia> @debug "foo"

julia> ENV["JULIA_DEBUG"] = "Main"
"Main"

julia> A.foo()
┌ Debug: foo
└ @ Main.A REPL[1]:2

julia> @debug "foo"
┌ Debug: foo
└ @ Main REPL[19]:1

That ENV["JULIA_DEBUG"] = "Main" switches debug on for Main.A too, seems also something to argue about.

Setting the environment variable with the module, it automatically sets it as String:

julia> ENV["JULIA_DEBUG"]=Main
Main

julia> typeof(ENV["JULIA_DEBUG"])
String

Therefore

julia> ENV["JULIA_DEBUG"]=A
Main.A

is not the same as

julia> ENV["JULIA_DEBUG"]="A"
A

and only the later works for the module A.
This all is an issue in my opinion, which should be opened.
Or you can add to this discussions:
https://github.com/JuliaLang/julia/issues/28930
https://github.com/JuliaLang/julia/issues/42903

According to the document “julia-1.7.2.pdf” page 1147 I should be able to set the environment variable on startup but I get an error as shown.

Microsoft Windows [Version 10.0.19044.1645]
(c) Microsoft Corporation. All rights reserved.

C:\Users\MyPC>JULIA_DEBUG=loading julia -e 'using DSP'
'JULIA_DEBUG' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\MyPC>

However starting julia and executing the following commands seems to work

julia> using DSP

julia> ENV["JULIA_DEBUG"] = DSP
DSP

Is this a windows anomaly or a documentation error?

That’s a windows thing - in cmd, you’d use set JULIA_DEBUG="value" or in powershell you’d do $env:JULIA_DEBUG="value".

Can you link where in the online manual (docs.julialang.org) that suggestion is? Probably worth a small doc PR, to amend the case for windows.

In the manual julia-1.7.2.pdf it is section 76.4.

This is found online at Logging · The Julia Language under Environment Variables with a copy shown below:

$ JULIA_DEBUG=loading julia -e 'using OhMyREPL'
┌ Debug: Rejecting cache file /home/user/.julia/compiled/v0.7/OhMyREPL.ji due to it containing an invalid cache header
└ @ Base loading.jl:1328
[ Info: Recompiling stale cache file /home/user/.julia/compiled/v0.7/OhMyREPL.ji for module OhMyREPL
┌ Debug: Rejecting cache file /home/user/.julia/compiled/v0.7/Tokenize.ji due to it containing an invalid cache header
└ @ Base loading.jl:1328
...

Since it is shell (terminal) specific a note that the julia solution is universal may be helpful.

ENV["JULIA_DEBUG"] = Main