Skip to content

Logging.disable_logging() either broken or docs not clear on usage #34037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
IanButterworth opened this issue Dec 6, 2019 · 6 comments · Fixed by #57591
Closed

Logging.disable_logging() either broken or docs not clear on usage #34037

IanButterworth opened this issue Dec 6, 2019 · 6 comments · Fixed by #57591
Labels
bug Indicates an unexpected problem or unintended behavior docs This change adds or pertains to documentation logging The logging framework

Comments

@IanButterworth
Copy link
Member

From the docs on disable_logging() I believe this should be able to enable the debug logging. Either it's broken or the docs aren't clear on correct usage

julia> using Logging
julia> @debug "hello"

julia> Logging.disable_logging(Logging.BelowMinLevel)
LogLevel(-1000000)
julia> @debug "hello"

julia>
@YellowFoxH4XOR
Copy link

YellowFoxH4XOR commented Dec 6, 2019

So first of all to see the logs in realtime use ENV["JULIA_DEBUG"] = "all"

julia> using Logging

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

julia> @debug "hello"
┌ Debug: hello
└ @ Main REPL[3]:1

julia> @info "hello"
[ Info: hello

julia> disable_logging(LogLevel(-1))   # **FOR INFO**
Info

julia> @info "hello"
[ Info: hello

julia> @debug "hello"

julia> disable_logging(LogLevel(-1001))  # **FOR DEBUG**
Debug

julia> @debug "hello"
┌ Debug: hello
└ @ Main REPL[9]:1

julia> @info "hello"
[ Info: hello

hope this resolves your issue 😄

@IanButterworth
Copy link
Member Author

I see. So JULIA_DEBUG overrules the loglevel system for @debug.

Instead of the docstring here:

Disable all log messages at log levels equal to or less than level. This is a global 
setting, intended to make debug logging extremely cheap when disabled.

Perhaps it's more accurate to say

Disable all log messages at log levels equal to or less than level. This is a global 
setting, intended to make debug logging extremely cheap when disabled. 
Note that for `@debug` logging, the code source must be covered under `ENV["JULIA_DEBUG"]` 
i.e. `ENV["JULIA_DEBUG"] = "all"` or `ENV["JULIA_DEBUG"] = "YourPackage"` must be set

I can PR if you agree?

@IanButterworth
Copy link
Member Author

I have to say I do find that setup a bit inelegant/unclear

@YellowFoxH4XOR
Copy link

YellowFoxH4XOR commented Dec 6, 2019

`ENV["JULIA_DEBUG"] = "YourPackage" makes more sense

Also, need a clear picture of how disable_logging() affects debug, info, warn and error

@brenhinkeller brenhinkeller added the docs This change adds or pertains to documentation label Nov 20, 2022
@DilumAluthge DilumAluthge added the logging The logging framework label Nov 19, 2023
@DilumAluthge DilumAluthge added the bug Indicates an unexpected problem or unintended behavior label Nov 19, 2023
@JimCircadian
Copy link

JimCircadian commented Mar 21, 2025

I'm keen on this change @IanButterworth. It feels quite unclear to be unable to enable debug logging during development without resorting to environment variable changes, especially when it effectively means the disable_logging becomes redundant.

julia> using Logging

julia> @info "test"
[ Info: test

julia> @debug "test"

julia> Base.disable_logging(LogLevel(-1001))
Debug

julia> @debug "test"

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

julia> @debug "test"
┌ Debug: test
└ @ Main REPL[7]:1

EDIT: Appreciate that brute forcing all modules to log debug might be a bit naff, so also happy to look at a PR, perhaps with some addition that allows registration of the necessary modules? A enable_debug for modules imported / used, perhaps?

IanButterworth added a commit to IanButterworth/julia that referenced this issue Apr 3, 2025
@IanButterworth
Copy link
Member Author

A clarifying note added to #57591

kpamnany pushed a commit to RelationalAI/julia that referenced this issue Apr 7, 2025
Closes JuliaLang#57376
Closes JuliaLang#34037

- Adds a lock in `SimpleLogger` and `ConsoleLogger` for use on maxlog
tracking and stream writes to improve threadsafety.
Closely similar to JuliaLang#54497

- Turns the internal `_min_enabled_level` into a `Threads.Atomic`. There
are [some direct
interactions](https://juliahub.com/ui/Search?type=code&q=_min_enabled_level&w=true)
to this internal in the ecosystem, but they should still work
```
julia> Base.CoreLogging._min_enabled_level[] = Logging.Info+1
LogLevel(1)
```

- Brings tests over from JuliaLang#57448

Performance seems highly similar:

```
julia> @time for i in 1:10000
          @info "foo" maxlog=10000000
       end
[ Info: foo
...
  0.481446 seconds (1.33 M allocations: 89.226 MiB, 0.49% gc time)
```

```
  0.477235 seconds (1.31 M allocations: 79.002 MiB, 1.77% gc time)
```
KristofferC pushed a commit that referenced this issue Apr 9, 2025
Closes #57376
Closes #34037

- Adds a lock in `SimpleLogger` and `ConsoleLogger` for use on maxlog
tracking and stream writes to improve threadsafety.
Closely similar to #54497

- Turns the internal `_min_enabled_level` into a `Threads.Atomic`. There
are [some direct
interactions](https://juliahub.com/ui/Search?type=code&q=_min_enabled_level&w=true)
to this internal in the ecosystem, but they should still work
```
julia> Base.CoreLogging._min_enabled_level[] = Logging.Info+1
LogLevel(1)
```

- Brings tests over from #57448

Performance seems highly similar:

### Master
```
julia> @time for i in 1:10000
          @info "foo" maxlog=10000000
       end
[ Info: foo
...
  0.481446 seconds (1.33 M allocations: 89.226 MiB, 0.49% gc time)
```

### This PR
```
  0.477235 seconds (1.31 M allocations: 79.002 MiB, 1.77% gc time)
```

(cherry picked from commit 9af9650)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior docs This change adds or pertains to documentation logging The logging framework
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants