From d0c385eec43c560146d690dc054d0e6c0969159f Mon Sep 17 00:00:00 2001 From: Roman Samarev Date: Mon, 28 Aug 2023 19:09:49 -0700 Subject: [PATCH 1/2] fixed usage with JULIA_DEBUG --- Project.toml | 2 +- src/CompositionalLoggers/common.jl | 6 ++-- test/runtests.jl | 45 ++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index a375136..867ae5a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "LoggingExtras" uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36" authors = ["Frames White ", "Collaborators "] -version = "1.0.1" +version = "1.0.2" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/src/CompositionalLoggers/common.jl b/src/CompositionalLoggers/common.jl index 3e1c054..bb6c799 100644 --- a/src/CompositionalLoggers/common.jl +++ b/src/CompositionalLoggers/common.jl @@ -4,9 +4,9 @@ # 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) end # For checking if child logger will take the message you are sending diff --git a/test/runtests.jl b/test/runtests.jl index 0f84798..f57d785 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 From 2f72a099df0803668ba4ef1217227b8996a64f25 Mon Sep 17 00:00:00 2001 From: Frames White Date: Thu, 31 Aug 2023 12:28:46 +0800 Subject: [PATCH 2/2] tweaks --- src/CompositionalLoggers/common.jl | 1 + test/runtests.jl | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/CompositionalLoggers/common.jl b/src/CompositionalLoggers/common.jl index bb6c799..af69af5 100644 --- a/src/CompositionalLoggers/common.jl +++ b/src/CompositionalLoggers/common.jl @@ -7,6 +7,7 @@ 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 diff --git a/test/runtests.jl b/test/runtests.jl index f57d785..1c9b2fc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -300,9 +300,9 @@ end # Define a module for testing conditional debug messages module JuliaDebugTest -function debug_message(str) - @debug str -end + function debug_message(str) + @debug str + end end