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"lumen.log" log("MODULE", "INFO", "message")
calls the trace function.
Functions
displaylogger (module, severity, msg) | Default logger for instant display. |
storelogger (module, severity, msg) | Logger function for log storage. |
musttrace (module, severity) | Determines whether a log must be traced depending on its severity and the module. |
trace (module, severity, fmt, ...) | Prints out a log entry according to the module and the severity of the log entry. |
setlevel (slevel, ...) | Sets the log level for a list of module names. |
Tables
levels | Severity name <-> Severity numeric value translation table. |
modules | Per module verbosity levels. |
Fields
defaultlevel | Default verbosity level. |
timestampformat | The string format of the timestamp is the same as what os.date takes. |
format | Format is a string used to apply specific formating before the log is outputted. |
Functions
- displaylogger (module, 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:
- module string identifying the module that issues the log
- severity string representing the log level.
- msg string containing the message to log.
- storelogger (module, 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 musttrace) and after the log has been displayed using {displaylogger}.Parameters:
- module string identifying the module thats issues the log
- severity string representing the log level.
- msg string containing the message to log.
- musttrace (module, severity)
-
Determines whether a log must be traced depending on its severity and the module.
issuing the log.
Parameters:
- module string identifying the module that issues the log.
- severity string representing the log level.
Returns:
- `nil' if the message of the given severity by the given module should not be printed.
- true if the message should be printed.
- trace (module, severity, fmt, ...)
-
Prints out a log entry according to the module and the severity of the log entry.
This function uses format and timestampformat to create the final message string.
It calls displaylogger and storelogger.Parameters:
- module string identifying the module that issues the log.
- severity string representing the log level.
- fmt string format that holds the log text the same way as string.format does.
- ... additional arguments can be provided (as with string.format).
Usage:
trace("MODULE", "INFO", "message=%s", "sometext").
- setlevel (slevel, ...)
-
Sets the log level for a list of module names.
If no module name is given, the default log level is affected
Parameters:
- slevel level as in levels
- ... Optional list of modules names (string) to apply the level to.
Returns:
-
nothing.
Tables
- levels
-
Severity name <-> Severity numeric value translation table.
Built-in values (in order from the least verbose to the most):- 'NONE'
- 'ERROR'
- 'WARNING'
- 'INFO'
- 'DETAIL'
- 'DEBUG'
- 'ALL'
- modules
- Per module verbosity levels. See levels to see existing levels.
Fields
- defaultlevel
-
Default verbosity level.
Default value is 'WARNING'. See levels to see existing levels. - timestampformat
- The string format of the timestamp is the same as what os.date takes. Example: "%F %T"
- 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)- %l => the actual log (given in 3rd argument when calling log() function)
- %t => the current date
- %T => the current timestamp
- %m => module name
- %s => log level (severity)