Logging.jl
Logging.@logmsg — Macro@debug message [key=value | value ...]
@info message [key=value | value ...]
@warn message [key=value | value ...]
@error message [key=value | value ...]
@logmsg level message [key=value | value ...]Create a log record with an informational message. For convenience, four logging macros @debug, @info, @warn and @error are defined which log at the standard severity levels Debug, Info, Warn and Error. @logmsg allows level to be set programmatically to any LogLevel or custom log level types.
message should be an expression which evaluates to a string which is a human readable description of the log event. By convention, this string will be formatted as markdown when presented.
The optional list of key=value pairs supports arbitrary user defined metadata which will be passed through to the logging backend as part of the log record. If only a value expression is supplied, a key representing the expression will be generated using Symbol. For example, x becomes x=x, and foo(10) becomes Symbol("foo(10)")=foo(10). For splatting a list of key value pairs, use the normal splatting syntax, @info "blah" kws....
There are some keys which allow automatically generated log data to be overridden:
_module=modcan be used to specify a different originating module from the source location of the message._group=symbolcan be used to override the message group (this is normally derived from the base name of the source file)._id=symbolcan be used to override the automatically generated unique message identifier. This is useful if you need to very closely associate messages generated on different source lines._file=stringand_line=integercan be used to override the apparent source location of a log message.
There's also some key value pairs which have conventional meaning:
maxlog=integershould be used as a hint to the backend that the message should be displayed no more thanmaxlogtimes.exception=exshould be used to transport an exception with a log message, often used with@error. An associated backtracebtmay be attached using the tupleexception=(ex,bt).
Examples
@debug "Verbose debugging information. Invisible by default"
@info "An informational message"
@warn "Something was odd. You should pay attention"
@error "A non fatal error occurred"
x = 10
@info "Some variables attached to the message" x a=42.0
@debug begin
sA = sum(A)
"sum(A) = $sA is an expensive operation, evaluated only when `shouldlog` returns true"
end
for i=1:10000
@info "With the default backend, you will only see (i = $i) ten times" maxlog=10
@debug "Algorithm1" i progress=i/10000
endLogging.SimpleLogger — TypeSimpleLogger(stream=stderr, min_level=Info)Simplistic logger for logging all messages with level greater than or equal to min_level to stream.
Logging.ConsoleLogger — TypeConsoleLogger(stream=stderr, min_level=Info; meta_formatter=default_metafmt,
show_limited=true, right_justify=0)Logger with formatting optimized for readability in a text console, for example interactive work with the Julia REPL.
Log levels less than min_level are filtered out.
Message formatting can be controlled by setting keyword arguments:
meta_formatteris a function which takes the log event metadata(level, _module, group, id, file, line)and returns a color (as would be passed to printstyled), prefix and suffix for the log message. The default is to prefix with the log level and a suffix containing the module, file and line location.show_limitedlimits the printing of large data structures to something which can fit on the screen by setting the:limitIOContextkey during formatting.right_justifyis the integer column which log metadata is right justified at. The default is zero (metadata goes on its own line).