Skip to content
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

fixed usage with JULIA_DEBUG #84

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
oxinabox marked this conversation as resolved.
Show resolved Hide resolved
# `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