Skip to content

Commit

Permalink
More backend interface renaming
Browse files Browse the repository at this point in the history
Use handle_message rather than dispatch_message, as not all message
handling is pure dispatch (the message may be stored rather than sent
elsewhere).

Reuse the name dispatch_message internally.
  • Loading branch information
c42f committed Oct 1, 2017
1 parent 656f937 commit 761fa54
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/memento.jl
Expand Up @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions src/MicroLogging.jl
Expand Up @@ -15,7 +15,7 @@ export
# Logger type
AbstractLogger,
# Logger methods
dispatch_message, shouldlog,
handle_message, shouldlog,
# Example loggers
SimpleLogger, InteractiveLogger

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


"""
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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")


"""
Expand All @@ -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

Expand Down
16 changes: 8 additions & 8 deletions src/loggers.jl
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Expand Up @@ -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
Expand Down

0 comments on commit 761fa54

Please sign in to comment.