Library log

To use this library in your code:

import log
Logging support.
Each application has a default logger, default, that is global to the application. By default it is set to log all messages at DEBUG-LEVEL. To log all messages including trace, set the level to TRACE-LEVEL.
Messages on the default logger are created by calling log, trace, debug, info, warn, error or fatal. The same functions exist as methods on the Logger class as well.
Instead of creating strings that contain context relevant information, it is possible to add tags to the log message. Tags are key/value pairs that are added to the log message. For example:

import log

main:
  log.info "Hello world" --tags={"name": "world"}
The default logger can be set with set-default. For example:

import log

main:
  log.set-default (log.default.with-level log.INFO_LEVEL)
It is common to create a logger for parts of a program. In that case, use .with --name=<part-name> to create a sub-logger. Often, the class does this in its constructor:

import log

class Connectivity:
  logger_/log.Logger

  constructor --logger/log.Logger=log.default:
    logger_ = logger.with-name "connectivity"

Exported interfaces

Classes

A logger that logs messages to a given target.

Exported classes

Functions

debug message/string --tags/Map=null -> none
Logs the message to the default logger at debug level (DEBUG-LEVEL).
Includes the given tags in the log message.

The default logger.

error message/string --tags/Map=null -> none
Logs the message to the default logger at error level (ERROR-LEVEL).
Includes the given tags in the log message.

fatal message/string --tags/Map=null -> none
Logs the message to the default logger at fatal level (FATAL-LEVEL).
Includes the given tags in the log message.

info message/string --tags/Map=null -> none
Logs the message to the default logger at info level (INFO-LEVEL).
Includes the given tags in the log message.

log level/int message/string --tags/Map=null -> none
Logs the message at the given level to the default logger.
Includes the given tags in the log message.

set-default logger/Logger -> none
Sets the logger as the default.

trace message/string --tags/Map=null -> none
Logs the message to the default logger at trace level (TRACE-LEVEL).
Includes the given tags in the log message.

warn message/string --tags/Map=null -> none
Logs the message to the default logger at warning level (WARN-LEVEL).
Includes the given tags in the log message.

Exported functions