Skip to content

Commit

Permalink
fixed usage with JULIA_DEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
rssdev10 committed Aug 29, 2023
1 parent d3b3a02 commit 3472ee4
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)
Base.CoreLogging.env_override_minlevel(group, _module) ||
(min_enabled_level(logger) <= level &&
shouldlog(logger, level, _module, group, id))
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

0 comments on commit 3472ee4

Please sign in to comment.