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

fix: Fix typo in set_logger! #2

Merged
merged 1 commit into from
Jun 7, 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 src/hierarchical_logger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function set_logger!(h::HierarchicalLogger, key::Vector{SubString{String}}, logg
if haskey(h, key)
existing_logger = h[key]
new_level = max(min_enabled_level(existing_logger), min_enabled_level(logger))
return h.loggers[key] = MutableLogLevel(logger, new_level, join(key, h.delimiter))
return h.loggers[key] = MutableLogLevelLogger(logger, new_level, join(key, h.delimiter))
else
return insert_logger!(h, key, logger)
end
Expand Down
18 changes: 16 additions & 2 deletions test/TestHierarchicalLogging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ A2_B1_logger_name = "ModuleA2.ModuleB1"
h = HierarchicalLogger(root_logger)

insert_logger!(h, A_logger_name, logger1)
@test_throws ErrorException insert_logger!(h, A_logger_name, logger1)
@Test h[root_logger_id].base_logger == root_logger
@Test h[A2_logger_name].base_logger == root_logger
@Test h[A2_B1_logger_name].base_logger == root_logger
Expand Down Expand Up @@ -299,7 +300,20 @@ A2_B1_logger_name = "ModuleA2.ModuleB1"
for (k,logger) in pairs(all_loggers)
@Test logger.messages == ref_messages[k]
end


# Old logger is discarded and no longer receives messages
new_logger1 = BaseLogger(; current_level=MutableLogLevel(Info))
set_logger!(h, A_logger_name, new_logger1)

@test underlying_logger(h[A_logger_name]) === new_logger1

handle_message(h, Info, "New", ModuleA, nothing, nothing, "a.jl", 1)

@Test new_logger1.messages == [SampleRecord(Info, "New", "ModuleA", nothing, nothing, "a.jl", 1)]

for (k,logger) in pairs(all_loggers)
@Test logger.messages == ref_messages[k]
end
end
@testset "Root has depth > 1 children" begin
root_logger = BaseLogger(; current_level=MutableLogLevel(Info))
Expand Down Expand Up @@ -463,7 +477,7 @@ A2_B1_logger_name = "ModuleA2.ModuleB1"
@error "Errored" _module=ModuleA.ModuleB _file=_file _line=_line _group=_group _id=_id
@error "Errored" _module=ModuleA _file=_file _line=_line _group=_group _id=_id
@error "Errored" _module=ModuleA2.ModuleB1 _file=_file _line=_line _group=_group _id=_id

push!(ref_messages[A2_logger_name], SampleRecord(Error, "Errored", A2_B1_logger_name,nothing, nothing, "a.jl", 4))
push!(ref_messages[A_B_C_logger_name], SampleRecord(Error, "Errored", A_B_C_logger_name,nothing, nothing, "a.jl", 4))
push!(ref_messages[A_B_C_logger_name], SampleRecord(Error, "Errored", A_B_logger_name,nothing, nothing, "a.jl", 4))
Expand Down