Addon for LuaLogging to log to the system log on unix systems. Can also be used without LuaLogging.
Simplest is to install via LuaRocks
luarocks install luasyslog
Alternatively clone the git repo and use the Makefile
.
see COPYING
- update the version + copyright years in
lsyslog.c
(year twice!) - update the version in
Makefile
- check copyright years in
LICENSE
- update changelog below
- update rockspecs
- commit as
release X.Y.Z
- tag as
X.Y.Z
- push commit and tags
- upload rock to LuaRocks
- fix possible memory corruption issue #1
- no longer rely on globals (only on Lua 5.1
lsyslog
sets a global) - added standard lualogging formatting options
syslog
now returns a module, same aslsyslog
- added new docs in
README.md
- added tests and CI
This library consists of two modules, lsyslog
and syslog
.
This is the library is a copy of lsyslog
, so it holds the same functions and
constants, but when 'required', it will add an appender to lualogging
. And
calling on the module table will create a new appender as well.
local lualogging = require "lualogging"
local syslog = require "syslog"
local logger = lualogging.syslog {
ident = "Lua-prog",
facility = syslog.FACILITY_USER,
}
-- or the shorter version without explicit LuaLogging references
local syslog = require "syslog"
local logger = syslog {
ident = "lua",
facility = syslog.FACILITY_USER,
}
-- Below are standard LuaLogging features, check its docs for more
logger:debug("some debug message")
-- logging tables
logger:debug({ a = 1, b = 2 })
-- use string.format() style formatting
logger:info("val1='%s', val2=%d", "string value", 1234)
Syslog appender parameters:
ident
: identifying string prepended to messages by syslog service (string
, default"lua"
).facility
: one of theFACILITY_XXX
constants (int
, defaultsyslog.FACILITY_USER
).logPattern
: the pattern to control how the message is written. The default value is"%message"
(additional plaeholders are"%date"
and"%level"
).timestampPattern
: This is an optional parameter that can be used to specify a date pattern that will be passed to theos.date
function to create the timestamp for the log message (the"%date"
placeholder).
This is the underlying binding to syslog
, it can be used to directly interact
with syslog
, without using lualogging
.
local lsyslog = require "lsyslog"
lsyslog.open("my-prog", lsyslog.FACILITY_USER)
lsyslog.log(lsyslog.DEBUG, "a debug message")
Opens connection to syslog.
ident
: identifying string prepended to messages (string
, required).facility
: one of theFACILITY_XXX
constants (int
, required).
Generates a log message.
level
: one of theLOG_XXX
constants (int
, required).message
: the message to log (string
, required).
Closes the file descriptor being used. Usage is optional.
Log level constants, to be used with log
:
lsyslog.LOG_EMERG
lsyslog.LOG_ALERT
lsyslog.LOG_CRIT
lsyslog.LOG_ERR
lsyslog.LOG_WARNING
lsyslog.LOG_NOTICE
lsyslog.LOG_INFO
lsyslog.LOG_DEBUG
Facility constants, to be used with open
:
lsyslog.FACILITY_KERN
lsyslog.FACILITY_USER
lsyslog.FACILITY_MAIL
lsyslog.FACILITY_DAEMON
lsyslog.FACILITY_AUTH
lsyslog.FACILITY_SYSLOG
lsyslog.FACILITY_LPR
lsyslog.FACILITY_NEWS
lsyslog.FACILITY_UUCP
lsyslog.FACILITY_CRON
lsyslog.FACILITY_AUTHPRIV
lsyslog.FACILITY_FTP
lsyslog.FACILITY_LOCAL0
lsyslog.FACILITY_LOCAL1
lsyslog.FACILITY_LOCAL2
lsyslog.FACILITY_LOCAL3
lsyslog.FACILITY_LOCAL4
lsyslog.FACILITY_LOCAL5
lsyslog.FACILITY_LOCAL6
lsyslog.FACILITY_LOCAL7