diff --git a/examples/memento.jl b/examples/memento.jl index cedaf0e..94f8c13 100644 --- a/examples/memento.jl +++ b/examples/memento.jl @@ -12,7 +12,7 @@ using Memento immutable LogShim <: AbstractLogger end -function MicroLogging.dispatch_message(::LogShim, ml_level, msg, _module, group, id, filepath, line; kwargs...) +function MicroLogging.handle_message(::LogShim, ml_level, msg, _module, group, id, filepath, line; kwargs...) # TODO: Map the `group` keyword (or something equivalent) into the right logger. # For now, assume a module-based logger. logger = get_logger(_module) diff --git a/src/MicroLogging.jl b/src/MicroLogging.jl index 7687d8d..eef8f32 100644 --- a/src/MicroLogging.jl +++ b/src/MicroLogging.jl @@ -15,7 +15,7 @@ export # Logger type AbstractLogger, # Logger methods - dispatch_message, shouldlog, + handle_message, shouldlog, # Example loggers SimpleLogger, InteractiveLogger @@ -210,11 +210,11 @@ function logmsg_code(_module, file, line, level, message, exs...) # Use FastClosures.@closure to work around https://github.com/JuliaLang/julia/issues/15276 create_msg = @closure function cm(logger, level, _module, group, id, file, line) msg = $(esc(message)) - dispatch_message(logger, level, msg, _module, group, id, file, line; $(kwargs...)) + handle_message(logger, level, msg, _module, group, id, file, line; $(kwargs...)) end file = $file line = $line - gen_message(logger, level, _module, group, id, file, line, create_msg) + dispatch_message(logger, level, _module, group, id, file, line, create_msg) end end end @@ -323,14 +323,14 @@ macro error(message, exs...) logmsg_code((@sourceinfo)..., :Error, message, exs. """ - dispatch_message(logger, level, message, _module, group, id, file, line; key1=val1, ...) + handle_message(logger, level, message, _module, group, id, file, line; key1=val1, ...) Log a message to `logger` at `level`. The logicla location at which the message was generated is given by module `_module` and `group`; the source location by `file` and `line`. `id` is an arbitrary unique `Symbol` to be used as a key to identify the log statement when filtering. """ -function dispatch_message end +function handle_message end """ @@ -351,7 +351,7 @@ the log level below or equal to which all messages are filtered. min_enabled_level(logger::AbstractLogger) = Info -function gen_message(logger, level, _module, group, id, filepath, line, create_msg) +function dispatch_message(logger, level, _module, group, id, filepath, line, create_msg) # Catch all exceptions, to prevent log message generation from crashing # the program. This lets users confidently toggle little-used # functionality - such as debug logging - in a production system. @@ -365,7 +365,7 @@ function gen_message(logger, level, _module, group, id, filepath, line, create_m # progressively less information. try msg = ("Error formatting log message at location ($_module,$filepath,$line).", err) - dispatch_message(logger, Error, msg, _module, group, id, filepath, line) + handle_message(logger, Error, msg, _module, group, id, filepath, line) catch try # Give up and write to STDERR, in three independent calls to @@ -392,7 +392,7 @@ struct NullLogger <: AbstractLogger; end min_enabled_level(::NullLogger) = AboveMaxLevel shouldlog(::NullLogger, args...) = false -dispatch_message(::NullLogger, args...; kwargs...) = error("Null logger dispatch_message() should not be called") +handle_message(::NullLogger, args...; kwargs...) = error("Null logger handle_message() should not be called") """ @@ -415,8 +415,8 @@ shouldlog(logger::SimpleLogger, level, args...) = !(level < logger.min_level) min_enabled_level(logger::SimpleLogger) = logger.min_level -function dispatch_message(logger::SimpleLogger, level, msg, _module, group, id, - filepath, line; kwargs...) +function handle_message(logger::SimpleLogger, level, msg, _module, group, id, + filepath, line; kwargs...) println(logger.stream, "$level [$(basename(String(filepath))):$line]: $msg") end diff --git a/src/loggers.jl b/src/loggers.jl index d07400b..caa84ba 100644 --- a/src/loggers.jl +++ b/src/loggers.jl @@ -108,18 +108,18 @@ function levelstring(level::LogLevel) end end -function dispatch_message(logger::InteractiveLogger, level, msg, _module, group, - id, file, line; kwargs...) +function handle_message(logger::InteractiveLogger, level, msg, _module, group, + id, file, line; kwargs...) io = IOBuffer() formatmsg(logger, io, msg) - dispatch_message(logger, level, String(take!(io)), _module, group, id, - file, line; kwargs...) + handle_message(logger, level, String(take!(io)), _module, group, id, + file, line; kwargs...) end -function dispatch_message(logger::InteractiveLogger, level, msg::AbstractString, - _module, group, id, filepath, line; - progress=nothing, banner=false, once=nothing, - max_log=nothing, kwargs...) +function handle_message(logger::InteractiveLogger, level, msg::AbstractString, + _module, group, id, filepath, line; + progress=nothing, banner=false, once=nothing, + max_log=nothing, kwargs...) if max_log !== nothing count = get!(logger.message_counts, id, 0) count += 1 diff --git a/test/runtests.jl b/test/runtests.jl index ee9abd8..1c1198e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -48,8 +48,8 @@ function MicroLogging.shouldlog(logger::TestLogger, level, _module, group, id) true end -function MicroLogging.dispatch_message(logger::TestLogger, level, msg, _module, - group, id, file, line; kwargs...) +function MicroLogging.handle_message(logger::TestLogger, level, msg, _module, + group, id, file, line; kwargs...) push!(logger.records, LogRecord(level, msg, _module, group, id, file, line, kwargs, logger.shouldlog_args)) end