I’d like to customize the response to @info, as in the long quote below. I find this useful for debugging package tests. This works in REPL (Julia 0.7) but not in Atom, where the current logger is wrapped in a JunoProgressLogger (Atom/src/comm.jl:96 or :109).
Since loggers are immutable, I believe the only way to do this is to define a new logger.
I have tried to detect Atom, and when in Atom setting the new logger like this:
Logging.global_logger(Atom.Progress.JunoProgressLogger(TESTLOGR))
…which works if the next logging event is initated from the Atom console, but reverts to JunoProgressLogger(ConsoleLogger) at the next evaluation.
Does Atom only check the current logger during precompilation?
How can I define my own logging customization in Atom?
import Logging
import Logging:default_logcolor,
LogLevel,
Info,
Warn,
Error
using Dates
const OLDLOGGER = Logging.global_logger()
const T0_TESTS = now()
"Return file, location and time since start of test in info messages"
function custom_metafmt(level, _module, group, id, file, line)
color = default_logcolor(level)
prefix = (level == Warn ? "WARNING" : string(level))*':'
suffix = ""
# Next line was 'Info <= level <' in default_metafmt.
# We exclude level = Info from this early return
Info <= level -1 < Warn && return color, prefix, suffix
_module !== nothing && (suffix *= "$(_module)")
if file !== nothing
_module !== nothing && (suffix *= " ")
suffix *= Base.contractuser(file)
if line !== nothing
suffix *= ":$(isa(line, UnitRange) ? "$(first(line))-$(last(line))" : line)"
end
suffix *= " $(Int(round((now() - T0_TESTS).value / 1000))) s"
end
!isempty(suffix) && (suffix = "@ " * suffix)
return color, prefix, suffix
end
const TESTLOGR = Logging.ConsoleLogger(meta_formatter = custom_metafmt)
Logging.global_logger(TESTLOGR)
@info """
The info logger now has a suffix (not in Atom).
To reinstate the original logger:
julia> Logging.global_logger(OLDLOGGER)
"""