From fef8b98cc5c1eb4b917dca31a5be64f6a1b459a4 Mon Sep 17 00:00:00 2001 From: Marnix Kraus Date: Tue, 19 Dec 2023 09:26:45 +0100 Subject: [PATCH] Fix last test wrt logging --- core/src/logging.jl | 12 +++++------- core/test/logging_test.jl | 3 +-- core/test/run_models_test.jl | 6 ++++-- core/test/validation_test.jl | 4 ++-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/core/src/logging.jl b/core/src/logging.jl index 7e65f03e6..de4dcad96 100644 --- a/core/src/logging.jl +++ b/core/src/logging.jl @@ -1,16 +1,14 @@ """ - The type of message that is sent to is_current_module. - The information is generated in LoggingExtras.EarlyFilteredLogger. + is_current_module(log::LogMessageType)::Bool + Returns true if the log message is from the current module or a submodule. See https://github.com/JuliaLogging/LoggingExtras.jl/blob/d35e7c8cfc197853ee336ace17182e6ed36dca24/src/CompositionalLoggers/earlyfiltered.jl#L39 + for the information available in log. """ -const LogMessageType = - @NamedTuple{level::LogLevel, _module::Module, group::Symbol, id::Symbol} - -function is_current_module(log::LogMessageType)::Bool +function is_current_module(log)::Bool (log._module == @__MODULE__) || (parentmodule(log._module) == @__MODULE__) || - log._module == OrdinaryDiffEq# for the progress bar + log._module == OrdinaryDiffEq # for the progress bar end function setup_logger(; diff --git a/core/test/logging_test.jl b/core/test/logging_test.jl index de687a85e..7b142065b 100644 --- a/core/test/logging_test.jl +++ b/core/test/logging_test.jl @@ -55,8 +55,7 @@ end logger = Ribasim.setup_logger(; verbosity = Logging.Debug, stream = io, - module_filter_function = log::Ribasim.LogMessageType -> - log._module == @__MODULE__, + module_filter_function = log -> log._module == @__MODULE__, ) with_logger(logger) do diff --git a/core/test/run_models_test.jl b/core/test/run_models_test.jl index a9d5a5766..0a03bb112 100644 --- a/core/test/run_models_test.jl +++ b/core/test/run_models_test.jl @@ -98,6 +98,7 @@ end @testitem "basic model" begin using Logging: Debug, with_logger + using LoggingExtras using SciMLBase: successful_retcode import Tables using Dates @@ -105,8 +106,9 @@ end toml_path = normpath(@__DIR__, "../../generated_testmodels/basic/ribasim.toml") @test ispath(toml_path) - logger = TestLogger() - model = with_logger(logger) do + logger = TestLogger(; min_level = Debug) + filtered_logger = LoggingExtras.EarlyFilteredLogger(Ribasim.is_current_module, logger) + model = with_logger(filtered_logger) do Ribasim.run(Ribasim.Config(toml_path)) end diff --git a/core/test/validation_test.jl b/core/test/validation_test.jl index 41a6396f6..1d6dd4ce4 100644 --- a/core/test/validation_test.jl +++ b/core/test/validation_test.jl @@ -8,7 +8,7 @@ level = [[0.0, 0.0, 1.0]] area = [[0.0, 100.0, 90]] - logger = TestLogger() + logger = TestLogger(; min_level = Debug) with_logger(logger) do @test !valid_profiles(node_id, level, area) end @@ -124,7 +124,7 @@ end fractional_flow = Ribasim.FractionalFlow([NodeID(5)], [1.0], Dict{Tuple{Int, String}, NamedTuple}()) - logger = TestLogger() + logger = TestLogger(; min_level = Debug) with_logger(logger) do @test !Ribasim.valid_n_neighbors(fractional_flow, graph) end