Skip to content

Commit

Permalink
Merge pull request #186 from invenia/rf/force-register
Browse files Browse the repository at this point in the history
Support forced re-registration
  • Loading branch information
rofinn committed Jul 5, 2022
2 parents 916ea2e + 1fc552b commit d73d2da
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Memento"
uuid = "f28f55f0-a522-5efc-85c2-fe41dfb9b2d9"
license = "MIT"
authors = ["Invenia Technical Computing"]
version = "1.3.1"
version = "1.4.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
13 changes: 9 additions & 4 deletions src/loggers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,20 @@ Get the available log levels for a logger and their associated priorities.
getlevels(logger::Logger) = logger.levels

"""
register(::Logger)
register(::Logger; force=false)
Register an existing logger with Memento if it has not already been registered.
!!! note `force=true`
You can re-register a logger with `force=true`.
This may be necessary if you want to explicitly register a parent logger after
registering the child one, such as in submodule `__init__` functions.
"""
function register(logger::Logger)
if !haskey(_loggers, logger.name)
function register(logger::Logger; force=false)
if !haskey(_loggers, logger.name) || force
_loggers[logger.name] = logger
else
debug(LOGGER, "$logger is already registered.")
debug(LOGGER, "$logger is already registered and force=false.")
end

# Call getpath to potentially register any missing parent loggers.
Expand Down
4 changes: 4 additions & 0 deletions test/loggers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@
Memento.register(Logger("new_logger"))
logger = getlogger("new_logger")
@test logger == original_logger

# Test forced re-registration
logger = Memento.register(Logger("new_logger"; level="debug"); force=true)
@test logger != original_logger
end

@testset "No parent logger registered" begin
Expand Down

2 comments on commit d73d2da

@rofinn
Copy link
Member Author

@rofinn rofinn commented on d73d2da Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/63726

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.4.0 -m "<description of version>" d73d2da6803048baf9edca609708bb925420d833
git push origin v1.4.0

Please sign in to comment.