Class Logger

extends Object
A logger that logs messages to a given target.
A logger can have a name set in the constructor (Logger level_ target_ name). Sub-loggers with sub-names are created with with-name.
A logger can be associated with a set of tags that are added to all logged messages (see with-tag).

Class summary


constructor level_/int target_/Target --name/string=
Constructs a logger with the given level_ and target_.

Constructors

constructor level_/int target_/Target --name/string=null
Constructs a logger with the given level_ and target_.
All log messages below the level_ are discarded.
The log is associated with the name.

Methods

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

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

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

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

The level of the logger.

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

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

Stringifies this object.
Inheritance
Objects that need a human-friendly string representation should overwrite this method. The default string is based on the internal class-ID.

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

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

Adds the level to a copy of this logger.
The level can only be increased to log fewer messages.

with-level level/int [block] -> none
Calls the block if level is enabled by the logger. Can be useful to avoid heavy computations at disabled log levels.
The block is called with the logger as argument.

Adds the name to a copy of this logger.

with-tag key/string value/any -> Logger
Adds the tag composed by the key and the value to a copy of this logger.