JSON structured logging with configurable log levels and output routing to stdout or stderr.
| Name | Signature |
|---|---|
logger:log | logger:log(msg, level) |
logger:level | logger:level() -> level |
logger:level_str | logger:level_str() -> name |
logger:set_level | logger:set_level(level) |
new | new(lvl, to_stderr, stdout, stderr) -> logger |
logger:log(
msg,level)
Write a log message at the given level
Writes a JSON-formatted log message. msg can also be a table
of fields to merge into the log entry. Level defaults to info (20)
and can be passed as a number or a string name ("debug", "info",
"warn", "error"). Messages at or above the to_stderr threshold
are written to stderr.
logger:level() ->
level
Get the current numeric log level
logger:level_str() ->
name
Get the current log level as a string name
Returns the current log level as a string name (e.g., "debug", "info", "warn", "error") based on the numeric level configured for this logger.
logger:set_level(
level)
Set the log level
Sets the log level for this logger. The level parameter can be passed
as a numeric value (0, 10, 20, 30, 40) or as a string name ("debug",
"info", "warn", "error"). Only messages at or above this level will be logged.
new(
lvl,to_stderr,stdout,stderr) ->logger
Create a new logger instance
Creates a logger that outputs JSON-formatted log messages.
Log levels: debug=0, access=10, info=20, warn=30, error=40.
Messages with level >= to_stderr are written to stderr.
Default level is info (20). to_stderr defaults to 100 (all to stdout).