Introduction

Introduction

Logging levels

You can globally set the minimum logging level with Memento.config.

julia>Memento.config("debug")

Will log all messages for all loggers at or above "debug".

julia>Memento.config("warn")

Will only log message at or above the "warn" level.

We can also set the logging level for specific loggers or collections of loggers if we explicitly set the level on an existing logger.

julia>set_level(get_logger("Main"), "info")

Will only set the logging level to "info" for the "Main" logger and any future children of the "Main" logger.

By default Memento has 9 logging levels.

LevelNumberDescription
not_set0Will not log anything, but may still propagate messages to its parents.
debug10Log verbose message used for debugging.
info20Log general information about a program.
notice30Log important events that are still part of normal execution.
warn40Log warning that may cause the program to fail.
error50Log errors and throw or rethrow an error.
critical60Entire application has crashed.
alert70The entire application crashed and is not recoverable. Probably need to wake up the sysadmin.
emergency80System is unusable. Applications shouldn't need to call this so it may be removed in the future.

Formatting logs

Unless explicitly changed Memento will use a DefaultFormatter for handlers. This Formatter takes a format string for mapping log record fields into each log message. Desired fields are wrapped in curly brackets (ie: "{msg}")

The default format string is "[{level} | {name}]: {msg}", which produces messages that look like

[info | root]: my info message.
[warn | root]: my warning message.
...

However, you could change this string to just "{level}: {msg}", which would produce messages that look like

info: my info message.
warn: my warning message.
...

The simplest way to globally change the log format is with Memento.config

julia> Memento.config("debug"; fmt="[{level} | {name}]: {msg}")

The following fields are available via the DefaultRecord.

FieldDescription
dateThe log event date rounded to seconds
levelThe log event level as a string
levelnumThe integer value for the log event level
msgThe source log event message
nameThe name of the source logger
pidThe pid where the log event occured
lookupThe top StackFrame of the stacktrace for the log event
stacktraceA StackTrace for the log event

For more details on the DefaultFormatter and DefaultRecord please see the API docs. More general information on Formatters and Records will be discussed later in this manual.

Architecture

There are five main components of Memento.jl that you can manipulate:

  1. Loggers

  2. Handlers

  3. Formatters

  4. Records

  5. IO

The remainder of this manual will discuss how you can use these components to customize Memento to you particular application.