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 = 1
local d = {
	'aa',
	1,
	'bb'

local e = {
	key = 'value',
	key2 = 1.0


-- New extended interface
-- %<number> means numeric arguments and %s means the next argument
-- for example %1, %2, %s: %s would mean the third argument

rspamd_logger.info('a=%1, b=%2, c=%3, d=%4, e=%s', a, b, c, d, e)
-- Output: a=string, b=1.50000, c=1, d={[1] = aa, [2] = 1, [3] = bb} e={[key]=value, [key2]=1.0}

-- Create string using logger API
local str = rspamd_logger.slog('a=%1, b=%2, c=%3, d=%4, e=%5', a, b, c, d, e)

print(str)
-- Output: a=string, b=1.50000, c=1, d={[1] = aa, [2] = 1, [3] = bb} e={[key]=value, [key2]=1.0}

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.infox(fmt[, args) Extended interface to make an informational 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

Parameters:

  • fmt {string}: format string, arguments are encoded as %
  • args {any}: list of arguments to be replaced in % positions

Returns:

No return

Back to module description.

Function logger.warn(fmt[, args)

Extended interface to make a warning log message

Parameters:

  • fmt {string}: format string, arguments are encoded as %
  • args {any}: list of arguments to be replaced in % positions

Returns:

No return

Back to module description.

Function logger.infox(fmt[, args)

Extended interface to make an informational log message

Parameters:

  • fmt {string}: format string, arguments are encoded as %
  • args {any}: list of arguments to be replaced in % positions

Returns:

No return

Back to module description.

Function logger.infox(fmt[, args)

Extended interface to make an informational log message

Parameters:

  • fmt {string}: format string, arguments are encoded as %
  • args {any}: list of arguments to be replaced in % positions

Returns:

No return

Back to module description.

Function logger.debugx(fmt[, args)

Extended interface to make a debug log message

Parameters:

  • fmt {string}: format string, arguments are encoded as %
  • args {any}: list of arguments to be replaced in % positions

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 module
  • id {task|cfg|pool|string}: id to log
  • fmt {string}: format string, arguments are encoded as %
  • args {any}: list of arguments to be replaced in % positions

Returns:

No return

Back to module description.

Function logger.slog(fmt[, args)

Create string replacing percent params with corresponding arguments

Parameters:

  • fmt {string}: format string, arguments are encoded as %
  • args {any}: list of arguments to be replaced in % positions

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 log
  • fmt {string}: format string, arguments are encoded as %
  • args {any}: list of arguments to be replaced in % positions

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.