MiniLoggers.jl
MiniLoggers.JsonLogger — MethodJsonLogger(; <keyword arguments>)
JsonLogger constructor creates custom logger with json output, which can be used with usual @info, @debug commands. Supported keyword arguments include:
io(defaultstdout): IO stream which is used to output log messages belowerrlevellevel. Can be eitherIOorString, 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 aboveerrlevellevel. Can be eitherIOorString, 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 ifioorioerris a file path.flush(default:true): whether toflushIO stream for each log message. Flush behaviour also affected byflush_thresholdargument.squash_delimiter: (default: "\t"): defines which delimiter to use when squashing multilines messages.flush_threshold::Union{Integer, TimePeriod}(default: 0): if this argument is nonzero andflushistrue, theniois flushed only once perflush_thresholdmilliseconds. 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"): ifdatetimeparameter is used informatargument, this dateformat is applied for output timestamps.format: defines which keywords should be used in the output. If defined, should be a string which defines the structure of the output json. It should use keywords, and allowed keywords are: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
Format string should consists of comma separated tokens. In it's simplest form, tokens can be just keywords, then names of the keywords are used as a fieldnames. So, for example "timestamp,level,message" result in {"timestamp":"2023-01-01 12:34:56","level":"Debug","message":"some logging message"}. If fields must be renamed, then one should use <field name>:<keyword> form. For example, "severity:level" result in {"severity":"Debug"}, here field name is severity and the value is taken from the logging level. One can also create nested json, in order to do it one should use <field name>:{<format string>} form, where previous rules for format string also applies. For example, source:{line, file:basename} result in {"source":{"line":123,"file":"calculations.jl"}}
By default, format is timestamp,level,basename,line,message.
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 belowerrlevellevel. Can be eitherIOorString, 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 aboveerrlevellevel. Can be eitherIOorString, 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 ifioorioerris 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\nare changed tosquash_delimiterand\rare removed.:fullsquash: all messages including error stacktraces are squashed to a single line, i.e. all\nare changed tosquash_delimiterand\rare 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 toflushIO stream for each log message. Flush behaviour also affected byflush_thresholdargument.flush_threshold::Union{Integer, TimePeriod}(default: 0): if this argument is nonzero andflushistrue, theniois flushed only once perflush_thresholdmilliseconds. 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"): ifdatetimeparameter is used informatargument, 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.