Module rspamd_logger
Module rspamd_logger
Rspamd logger module is used to log messages from LUA API to the main rspamd logger. It supports legacy and modern interfaces allowing highly customized an convenient log functions. Here is an example of logger usage:
Example:
local rspamd_logger = require "rspamd_logger"
local a = 'string'
local b = 1.5
local c = 100
local d = {
'aa',
1,
'bb'
local e = {
key = 'value',
key2 = 1.0
-- New extended interface
-- Positional arguments: %<number> (e.g., %1, %2, %3)
-- Sequential arguments: %s (uses the next argument)
-- Type specifiers can be combined with positional or sequential:
-- %d - signed integer
-- %ud - unsigned integer
-- %f - double (floating point)
-- %.Nf - double with N decimal places (e.g., %.2f for 2 decimals)
-- Default formatting (automatic type detection)
rspamd_logger.info('a=%1, b=%2, c=%3, d=%4, e=%s', a, b, c, d, e)
-- Output: a=string, b=1.500000, c=100, d={[1] = aa, [2] = 1, [3] = bb} e={[key]=value, [key2]=1.0}
-- Using type specifiers
rspamd_logger.info('count=%1d, price=%.2f, name=%3', c, b, a)
-- Output: count=100, price=1.50, name=string
-- Sequential formatting with types
rspamd_logger.info('int=%d, float=%.3f, str=%s', c, b, a)
-- Output: int=100, float=1.500, str=string
-- Create string using logger API
local str = rspamd_logger.slog('value=%1d, percent=%.1f%%', c, b)
print(str)
-- Output: value=100, percent=1.5%
Brief content:
Functions:
| Function | Description |
|---|---|
logger.err(msg) | Log message as an error. |
logger.warn(msg) | Log message as a warning. |
logger.info(msg) | Log message as an informational message. |
logger.message(msg) | Log message as an notice message. |
logger.debug(msg) | Log message as a debug message. |
logger.errx(fmt[, args) | Extended interface to make an error log message. |
logger.warn(fmt[, args) | Extended interface to make a warning log message. |
logger.infox(fmt[, args) | Extended interface to make an informational log message. |
logger.messagex(fmt[, args) | Extended interface to make a notice log message. |
logger.debugx(fmt[, args) | Extended interface to make a debug log message. |
logger.debugm(module, id, fmt[, args) | Extended interface to make a debug log message. |
logger.slog(fmt[, args) | Create string replacing percent params with corresponding arguments. |
logger.logx(level, module, id, fmt[, args) | Extended interface to make a generic log message on any level. |
logger.log_level() | Returns log level for a logger. |
Functions
The module rspamd_logger defines the following functions.
Function logger.err(msg)
Log message as an error
Parameters:
msg {string}: string to be logged
Returns:
No return
Back to module description.
Function logger.warn(msg)
Log message as a warning
Parameters:
msg {string}: string to be logged
Returns:
No return
Back to module description.
Function logger.info(msg)
Log message as an informational message
Parameters:
msg {string}: string to be logged
Returns:
No return
Back to module description.
Function logger.message(msg)
Log message as an notice message
Parameters:
msg {string}: string to be logged
Returns:
No return
Back to module description.
Function logger.debug(msg)
Log message as a debug message
Parameters:
msg {string}: string to be logged
Returns:
No return
Back to module description.
Function logger.errx(fmt[, args)
Extended interface to make an error log message
- Positional arguments: %
(e.g., %1, %2, %3) - Sequential arguments: %s
- Type specifiers: %d (int), %ud (unsigned), %f (float), %.Nf (float with precision)
- Combined: %1d, %2f, %.2f
Parameters:
fmt {string}: format string supporting:args {any}: list of arguments to be formatted
Returns:
No return
Back to module description.
Function logger.warn(fmt[, args)
Extended interface to make a warning log message
- Positional arguments: %
(e.g., %1, %2, %3) - Sequential arguments: %s
- Type specifiers: %d (int), %ud (unsigned), %f (float), %.Nf (float with precision)
- Combined: %1d, %2f, %.2f
Parameters:
fmt {string}: format string supporting:args {any}: list of arguments to be formatted
Returns:
No return
Back to module description.
Function logger.infox(fmt[, args)
Extended interface to make an informational log message
- Positional arguments: %
(e.g., %1, %2, %3) - Sequential arguments: %s
- Type specifiers: %d (int), %ud (unsigned), %f (float), %.Nf (float with precision)
- Combined: %1d, %2f, %.2f
Parameters:
fmt {string}: format string supporting:args {any}: list of arguments to be formatted
Returns:
No return
Back to module description.
Function logger.messagex(fmt[, args)
Extended interface to make a notice log message
- Positional arguments: %
(e.g., %1, %2, %3) - Sequential arguments: %s
- Type specifiers: %d (int), %ud (unsigned), %f (float), %.Nf (float with precision)
- Combined: %1d, %2f, %.2f
Parameters:
fmt {string}: format string supporting:args {any}: list of arguments to be formatted
Returns:
No return
Back to module description.
Function logger.debugx(fmt[, args)
Extended interface to make a debug log message
- Positional arguments: %
(e.g., %1, %2, %3) - Sequential arguments: %s
- Type specifiers: %d (int), %ud (unsigned), %f (float), %.Nf (float with precision)
- Combined: %1d, %2f, %.2f
Parameters:
fmt {string}: format string supporting:args {any}: list of arguments to be formatted
Returns:
No return
Back to module description.
Function logger.debugm(module, id, fmt[, args)
Extended interface to make a debug log message
Parameters:
module {string}: debug moduleid {task|cfg|pool|string}: id to logfmt {string}: format string supporting type specifiers (%d, %ud, %f, %.Nf)args {any}: list of arguments to be formatted
Returns:
No return
Back to module description.
Function logger.slog(fmt[, args)
Create string replacing percent params with corresponding arguments
- Positional arguments: %
(e.g., %1, %2, %3) - Sequential arguments: %s
- Type specifiers: %d (int), %ud (unsigned), %f (float), %.Nf (float with precision)
- Combined: %1d, %2f, %.2f
Parameters:
fmt {string}: format string supporting:args {any}: list of arguments to be formatted
Returns:
{string}: string with percent parameters substituted
Back to module description.
Function logger.logx(level, module, id, fmt[, args)
Extended interface to make a generic log message on any level
Parameters:
log {number}: level as a number (see GLogLevelFlags enum for values)id {task|cfg|pool|string}: id to logfmt {string}: format string supporting type specifiers (%d, %ud, %f, %.Nf)args {any}: list of arguments to be formatted
Returns:
No return
Back to module description.
Function logger.log_level()
Returns log level for a logger
Parameters:
No parameters
Returns:
{string}: current log level
Back to module description.
Back to top.