Module tch.logger
Logging module.
Intended way of using:
- Load it using require():
local logger = require("tch.logger")
- Initialize using logger.init. Pass the name of your module,
the desired global log level (1 to 6), syslog options of interest
and default syslog facility.
local posix = require("tch.posix") logger.init("mymodule", 3, posix.LOG_PID + posix.LOG_CONS, posix.LOG_USER)
- Create zero or more logging objects for different parts of your application
where each object can optionally have its own name and log level. On that
object you have a log function for each log level and a function to change
the log level. You can also clear the specific log level and fall back to
the global log level.
local log = logger.new("mymodule", 2) log:critical("%s:%d", "oops", 42) log:error(....) log:warning(....) log:notice(....) log:info(....) log:debug(....) log:set_log_level(4)
- Use the methods on the global logging object to send log output. The
global logging object is the module itself.
logger:critical(....) logger:error(....)
See also:
Functions
init(name, log_level[, syslog_options=0[, syslog_facility=tch.posix.LOG_DAEMON]]) | Initialize the logger module. |
new(modname, log_level) | Create a new logger object with its own log level and optionally a name. |
Class logger
logger:critical(fmt[, ...]) | Log a critical message. |
logger:debug(fmt[, ...]) | Log a debug message. |
logger:error(fmt[, ...]) | Log an error message. |
logger:info(fmt[, ...]) | Log an informational message. |
logger:notice(fmt[, ...]) | Log a notice message. |
logger:set_log_level(log_level) | Change or clear the log level of this logger. |
logger:warning(fmt[, ...]) | Log a warning message. |
Functions
- init(name, log_level[, syslog_options=0[, syslog_facility=tch.posix.LOG_DAEMON]])
-
Initialize the logger module.
This isn't strictly necessary but it allows you configure a name
that is prepended to every log message, a different default log level,
additional syslog options or a different default syslog facility.
The function may be called multiple times.
Parameters:
- name string This name will be prepended to every log message, including those generated using logger objects created with new.
- log_level int The global log level as a number from 1 to 6. 1 is the most important level, 6 the least. A level outside this range will be ignored and the default level (3) will be used.
- syslog_options int Bitwise OR of syslog option constants. (default 0)
- syslog_facility int Syslog facility to use. (default tch.posix.LOG_DAEMON)
See also:
- new(modname, log_level)
-
Create a new logger object with its own log level and optionally a name.
Parameters:
- modname string Optional name of the module using the logger. It will be added to each log message, if present. This name is in addition to the global name set in init.
- log_level int The initial log level. If not given then the global log level will be used.
Returns:
-
logger
The newly created logger instance.
Class logger
Logger methods.
- logger:critical(fmt[, ...])
-
Log a critical message.
Parameters:
- fmt string Format of the log message of critical severity.
- ... Arguments of the format string, if any. (optional)
See also:
- logger:debug(fmt[, ...])
-
Log a debug message.
Parameters:
- fmt string Format of the log message of debug severity.
- ... Arguments of the format string, if any. (optional)
See also:
- logger:error(fmt[, ...])
-
Log an error message.
Parameters:
- fmt string Format of the log message of error severity.
- ... Arguments of the format string, if any. (optional)
See also:
- logger:info(fmt[, ...])
-
Log an informational message.
Parameters:
- fmt string Format of the log message of info severity.
- ... Arguments of the format string, if any. (optional)
See also:
- logger:notice(fmt[, ...])
-
Log a notice message.
Parameters:
- fmt string Format of the log message of notice severity.
- ... Arguments of the format string, if any. (optional)
See also:
- logger:set_log_level(log_level)
-
Change or clear the log level of this logger.
Parameters:
- log_level
int
The new log level. It must be a number from 1 to 6.
A level outside this range will be ignored.
Pass
nil
to clear this logger's specific log level and use the global log level.
- log_level
int
The new log level. It must be a number from 1 to 6.
A level outside this range will be ignored.
Pass
- logger:warning(fmt[, ...])
-
Log a warning message.
Parameters:
- fmt string Format of the log message of warning severity.
- ... Arguments of the format string, if any. (optional)
See also: