Skip to content

Commit

Permalink
Merge pull request #84 from rssdev10/fix/JULIA_DEBUG
Browse files Browse the repository at this point in the history
fixed usage with JULIA_DEBUG
  • Loading branch information
oxinabox authored Aug 31, 2023
2 parents d3b3a02 + 2f72a09 commit 13d85fa
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LoggingExtras"
uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36"
authors = ["Frames White <oxinabox@ucc.asn.au>", "Collaborators <https://github.com/JuliaLogging/LoggingExtras.jl/graphs/contributors>"]
version = "1.0.1"
version = "1.0.2"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
7 changes: 4 additions & 3 deletions src/CompositionalLoggers/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
# before passing anything on.

# For checking child logger, need to check both `min_enabled_level` and `shouldlog`
function comp_shouldlog(logger, args...)
level = first(args)
min_enabled_level(logger) <= level && shouldlog(logger, args...)
function comp_shouldlog(logger, level, _module, group, id)
(min_enabled_level(logger) <= level && shouldlog(logger, level, _module, group, id)) ||
Base.CoreLogging.env_override_minlevel(group, _module)
# `env_override_minlevel` is the internal function that makes JULIA_DEBUG environment variable work
end

# For checking if child logger will take the message you are sending
Expand Down
45 changes: 45 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,51 @@ end
@test length(logger.logs) == 1
end

# Define a module for testing conditional debug messages
module JuliaDebugTest

function debug_message(str)
@debug str
end

end

@testset "JULIA_DEBUG" begin
expected_messages = 0
logger = TestLogger(min_level=Info)
with_logger(logger) do
JuliaDebugTest.debug_message("debug")
end
@test length(logger.logs) == expected_messages

extra_logger = TransformerLogger(logger) do log
merge(log, (; message="New message"))
end
with_logger(extra_logger) do
JuliaDebugTest.debug_message("debug")
end
@test length(logger.logs) == expected_messages

ENV["JULIA_DEBUG"] = "JuliaDebugTest"
with_logger(logger) do
JuliaDebugTest.debug_message("debug")
expected_messages += 1
end
@test length(logger.logs) == expected_messages

with_logger(extra_logger) do
JuliaDebugTest.debug_message("debug")
expected_messages += 1
end
@test length(logger.logs) == expected_messages

delete!(ENV, "JULIA_DEBUG")
with_logger(extra_logger) do
JuliaDebugTest.debug_message("debug")
end
@test length(logger.logs) == expected_messages
end

@testset "Deprecations" begin
# Nothing is currently deprecated
end

2 comments on commit 13d85fa

@oxinabox
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/90535

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.2 -m "<description of version>" 13d85faf6aafdb7ee1cff41ef058c5a6144a5653
git push origin v1.0.2

Please sign in to comment.