# JULIA\_DEBUG environment variable

**URL:** https://discourse.julialang.org/t/julia-debug-environment-variable/73278
**Category:** General Usage
**Tags:** question, debug
**Created:** [December 17, 2021, 6:05pm UTC](https://discourse.julialang.org/t/julia-debug-environment-variable/73278 "2021-12-17T18:05:04Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [December 17, 2021, 6:05pm UTC](https://discourse.julialang.org/t/julia-debug-environment-variable/73278/1 "2021-12-17T18:05:05Z")

</div>

I don’t understand how `JULIA_DEBUG` environment variable works.

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

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

A.foo()

```

Then there is the debug message printed.

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [December 19, 2021, 11:10am UTC](https://discourse.julialang.org/t/julia-debug-environment-variable/73278/2 "2021-12-19T11:10:40Z")

</div>

It seems that the documentation  
[https://docs.julialang.org/en/v1.7/stdlib/Logging/#Environment-variables](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
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.

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [December 19, 2021, 11:26am UTC](https://discourse.julialang.org/t/julia-debug-environment-variable/73278/3 "2021-12-19T11:26:25Z")

</div>

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

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

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

```

Therefore

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

```

is not the same as

```julia
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/28930)  
[https://github.com/JuliaLang/julia/issues/42903](https://github.com/JuliaLang/julia/issues/42903)

---

<div class="post-metadata">

### Author: ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)
#### Post date: [April 18, 2022, 9:49pm UTC](https://discourse.julialang.org/t/julia-debug-environment-variable/73278/4 "2022-04-18T21:49:52Z")

</div>

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.

```julia
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
julia> using DSP

julia> ENV["JULIA_DEBUG"] = DSP
DSP

```

Is this a windows anomaly or a documentation error?

---

<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: [April 18, 2022, 9:57pm UTC](https://discourse.julialang.org/t/julia-debug-environment-variable/73278/5 "2022-04-18T21:57:35Z")

</div>

> [@Jake](#):
>
> 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](http://docs.julialang.org)) that suggestion is? Probably worth a small doc PR, to amend the case for windows.

---

<div class="post-metadata">

### Author: ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)
#### Post date: [April 19, 2022, 3:05pm UTC](https://discourse.julialang.org/t/julia-debug-environment-variable/73278/6 "2022-04-19T15:05:30Z")

</div>

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

This is found online at [Logging · The Julia Language](https://docs.julialang.org/en/v1/stdlib/Logging/) under Environment Variables with a copy shown below:

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

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

```
