MiniLoggers.jl
MiniLoggers.MiniLogger
— MethodMiniLogger(; <keyword arguments>)
MiniLogger constructor creates custom logger which can be used with usual @info
, @debug
commands.
Supported keyword arguments include:
io
(defaultstdout
): IO stream which is used to output log messages belowerrlevel
level. Can be eitherIO
orString
, in the latter case it is treated as a name of the output file.ioerr
(defaultstderr
): IO stream which is used to output log messages aboveerrlevel
level. Can be eitherIO
orString
, in the latter case it is treated as a name of the output file.errlevel
(defaultError
): determines which output IO to use for log messages. If you want for all messages to go toio
, set this parameter toMiniLoggers.AboveMaxLevel
. If you want for all messages to go toioerr
, set this parameter toMiniLoggers.BelowMinLevel
.minlevel
(default:Info
): messages below this level are ignored. For example with default setting@debug "foo"
is ignored.append
(default:false
): defines whether to append to output stream or to truncate file initially. Used only ifio
orioerr
is a file path.message_mode
(default::squash
): choose how message is transformed before being printed out. Following modes are supported::notransformations
: message printed out as is, without any extra transformations:squash
: message is squashed to a single line, i.e. all\n
are changed tosquash_delimiter
and\r
are removed.:fullsquash
: all messages including error stacktraces are squashed to a single line, i.e. all\n
are changed tosquash_delimiter
and\r
are removed:markdown
: message is treated as if it is written in markdown
squash_delimiter
: (default: "\t"): defines which delimiter to use in squash mode.flush
(default:true
): whether toflush
IO stream for each log message. Flush behaviour also affected byflush_threshold
argument.flush_threshold::Union{Integer, TimePeriod}
(default: 0): if this argument is nonzero andflush
istrue
, thenio
is flushed only once perflush_threshold
milliseconds. I.e. if time between two consecutive log messages is less thenflush_threshold
, then second message is not flushed and will have to wait for the next log event.dtformat
(default: "yyyy-mm-dd HH:MM:SS"): ifdatetime
parameter is used informat
argument, this dateformat is applied for output timestamps.format
(default: "[{timestamp:func}] {level:func}: {message}"): format for output log message. It accepts following keywords, which should be provided in curly brackets:timestamp
: timestamp of the log messagelevel
: name of log level (Debug, Info, etc)filepath
: filepath of the file, which produced log messagebasename
: basename of the filepath of the file, which produced log messageline
: line number of the log command in the file, which produced log messagegroup
: log groupmodule
: name of the module, which contains log commandid
: log message idmessage
: message itself
Each keyword accepts color information, which should be added after colon inside curly brackets. Colors can be either from Base.text_colors
or special keyword func
, in which case is used automated coloring. Additionaly, bold
modifier is accepted by the format
argument. For example: {line:red}
, {module:cyan:bold}
, {group:func}
are all valid parts of the format command.
Colour information is applied recursively without override, so {{line} {module:cyan} {group}:red}
is equivalent to {line:red} {module:cyan} {group:red}
.
If part of the format is not a recognised keyword, then it is just used as is, for example {foo:red}
means that output log message contain word "foo" printed in red.