Skip to content

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

Closed
@IanButterworth

Description

@IanButterworth
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>

Activity

YellowFoxH4XOR

YellowFoxH4XOR commented on Dec 6, 2019

@YellowFoxH4XOR

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

IanButterworth commented on Dec 6, 2019

@IanButterworth
SponsorMemberAuthor

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

IanButterworth commented on Dec 6, 2019

@IanButterworth
SponsorMemberAuthor

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

YellowFoxH4XOR

YellowFoxH4XOR commented on Dec 6, 2019

@YellowFoxH4XOR

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

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

added
docsThis change adds or pertains to documentation
on Nov 20, 2022
added
bugIndicates an unexpected problem or unintended behavior
on Nov 19, 2023
JimCircadian

JimCircadian commented on Mar 21, 2025

@JimCircadian

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?

added a commit that references this issue on Apr 3, 2025
IanButterworth

IanButterworth commented on Apr 3, 2025

@IanButterworth
SponsorMemberAuthor

A clarifying note added to #57591

added a commit that references this issue on Apr 4, 2025
added a commit that references this issue on Apr 9, 2025
added a commit that references this issue on Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviordocsThis change adds or pertains to documentationloggingThe logging framework

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @JimCircadian@IanButterworth@DilumAluthge@brenhinkeller@YellowFoxH4XOR

      Issue actions

        Logging.disable_logging() either broken or docs not clear on usage · Issue #34037 · JuliaLang/julia