Files in the top-level directory from the latest check-in
- build_syslog.sh
- log.lua
- log_syslog.c
- Readme.txt
log
===
The logger is initialized with a configuration (table) and
the init function will return a table with functions for each
log level.
configuration
-------------
The config table contains an asignment of the log level name to a file.
The name can be a wellknown (error, info, ...) or any custom value.
There is no structure/hierarchy in log level names.
A file is defined by its path: "/var/log/file.log" (stdout|stderr)
log open modes
--------------
For different modes apply:
| file -> pipe (|logger)
> new file (default append)
- open once, continuous write
= open once, continuous write, flush
log level format
----------------
To change the date or message format for one level,
these format strings can be used before the filename:
(d( date format )d)
(m( message format )m) -> =d= date, =l= level, =m= message
syslog
------
The syslog module can be compiled to use logging to syslog/journald:
log_level = string.format("%d:identifier", syslog.err)
syslog levels: syslog.[emerg|alert|crit|err|warning|notice|info|debug]
configuration (tuning)
----------------------
Special values in the config table:
["%d"] = "!%Y/%m/%d-%H:%M:%S" -- set the date format
["%m"] = "=d= =l= =m=\n" -- set the log message format (d: date, l: level m: message)
["%s"] = syslog -- the syslog module, if used
["%e"] = false -- read environment variables
if environment variables are used then
LOG_FORMAT_MESSAGE overwrites "%m"
LOG_FORMAT_DATE overwrites "%d"
LOG_level overwrites "level"
logging
-------
Calling a log function can either be with just a string:
log.error("System is running 100%")
or a format string with arguments:
log.error("System is running %d%%", num_percent)
example
-------
> export LOG_err="stderr"
-- if syslog is used
local syslog = require("log_syslog")
local log_config = {
file = "/var/log/file.log",
pipe = "|cat",
stdout = "(m(=d= =m=)m)(d(%s)d)=stdout",
-- if compiled with syslog
["%s"] = syslog,
syslog_err =string.format("%d:identifier", syslog.err),
-- table can contain optional fields for env and global format setup:
["%e"] = true,
["%d"] = "!%Y/%m/%d-%H:%M:%S",
["%m"] = "=d= =l= =m=\n",
}
local log = require("log").init(log_config)
log.err("Hello World!") -- will write to stderr (defined per env)
local name = "World"
log.file("Hello %s!", name)
log.notdefined("Hello") -- no output / no error