Module log Log library provides logging facilities.
The module exposes extension points. It is possible to provide both the custom printing function and the custom log saving function.
The module is callable. Thus:
local log = require"log" log("MODULE", "INFO", "message")

calls the #log.trace function.

Type levels

levels.ALL 7
levels.DEBUG 6
levels.DETAIL 5
levels.ERROR 2
levels.INFO 4
levels.NONE 1
levels.WARNING 3

Type log

log.defaultlevel Default verbosity level.
log.displaylogger(severity, msg) Default logger for instant display.
log.format Format is a string used to apply specific formating before the log is outputted.
log.modules Per module verbosity levels.
log.musttrace(severity) Determines whether a log must be traced depending on its severity and the module.
log.setlevel(slevel, varargs) Sets the log level for a list of module names.
log.storelogger(severity, msg) Logger function for log storage.
log.trace(severity, fmt) Prints out a log entry according to the module and the severity of the log entry.

Type levels

Severity name <-> Severity numeric value translation table.

Built-in values (in order from the least verbose to the most):

Field(s)

#number levels.ALL

7

#number levels.DEBUG

6

#number levels.DETAIL

5

#number levels.ERROR

2

#number levels.INFO

4

#number levels.NONE

1

#number levels.WARNING

3

Type log

Field(s)

#levels log.defaultlevel

Default verbosity level.
Default value is 'WARNING'.

log.displaylogger(severity, msg)

Default logger for instant display.
This logger can be replaced by a custom function.
It is called only if the log needs to be traced.

Parameters

#string log.format

Format is a string used to apply specific formating before the log is outputted.
Within a format, the following tokens are available (in addition to standard text)

log.modules

Per module verbosity levels.

log.musttrace(severity)

Determines whether a log must be traced depending on its severity and the module.
issuing the log.

Parameter

Return values

  1. `nil' if the message of the given severity by the given module should not be printed.
  2. true if the message should be printed.

log.setlevel(slevel, varargs)

Sets the log level for a list of module names.
If no module name is given, the default log level is affected

Parameters

Return value

nothing.

log.storelogger(severity, msg)

Logger function for log storage.
This logger can be replaced by a custom function.
There is no default logger.
It is called only if the log needs to be traced (see #log.musttrace) and after the log has been displayed using {displaylogger}.

Parameters

log.trace(severity, fmt)

Prints out a log entry according to the module and the severity of the log entry.

This function uses #log.format and #log.timestampformat to create the final message string.
It calls #log.displaylogger and #log.storelogger.

Parameters

Usage:

trace("MODULE", "INFO", "message=%s", "sometext").