Makefile
to reflect your
installation of Lua. Then run make. This will build the library and run a simple test.
syslog.so
somewhere in your
LUA_CPATH
.
openlog(ident, option[, facility])
syslog(priority, message)
closelog()
See test.lua
, which shows the library in action.
You may want to wap the standard assert
and
error
Lua calls so that they log the assertion or error before
aborting the program. This can be useful for post-mortem analysis of
embedded or unattended Lua applications. You can append this code at the end of
strict.lua
, a module that can be found in the
etc
directory of the Lua sources, and which is worth including
anyway.
require "syslog" -- set the ident string to the filename that first included this module syslog.openlog(debug.getinfo(3, "S").short_src, syslog.LOG_ODELAY, "LOG_USER") local _error = error error = function(txt, level) if level then level = level + 1 else level = 2 end local info = debug.getinfo(level, "Sl") local msg if info.what == "C" then msg = "[C function] " else msg = string.format("[%s]:%d ", info.short_src, info.currentline) end syslog.syslog("LOG_ERR", msg .. (txt or "")) _error(txt, level) end _G.assert = function (...) local cond, txt = ... if not cond then error(txt or "assertion failed!", 2) end return ... endThen call
require "strict"
at the top of your code.