[Zrouter-src] ZRouter.org: push to ZRouter profiles/lua_web_ui/files/etc/www/l...
zrouter-src at zrouter.org
zrouter-src at zrouter.org
Mon Sep 24 11:23:53 UTC 2012
details: http://zrouter.org/hg/zrouter//rev/e895670bc057
changeset: 469:e895670bc057
user: Aleksandr Rybalko <ray at ddteam.net>
date: Mon Sep 24 14:21:43 2012 +0300
description:
Allow logging to syslog. Redefine lua function 'print' to use syslog.
diffstat:
profiles/lua_web_ui/files/etc/www/lib/lsyslog.lua | 100 ++++++++++++++++++++++
1 files changed, 100 insertions(+), 0 deletions(-)
diffs (104 lines):
diff -r f533387b0dd6 -r e895670bc057 profiles/lua_web_ui/files/etc/www/lib/lsyslog.lua
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/profiles/lua_web_ui/files/etc/www/lib/lsyslog.lua Mon Sep 24 14:21:43 2012 +0300
@@ -0,0 +1,100 @@
+--[[
+Usage:
+
+----------------------------------------
+dofile("lib/lsyslog.lua");
+
+print("hi");
+info("info");
+
+function dtest()
+ dbg("xxxxx");
+end
+
+dbg("first");
+dtest();
+----------------------------------------
+Output:
+
+lua syslog: hi
+lua syslog: info
+lua syslog: test.lua:19:<none>(): first
+lua syslog: test.lua:16:dtest(): xxxxx
+
+
+]]
+
+-- XXX: how to do syslog.closelog() ?
+
+function emerg(line)
+ syslog.syslog("LOG_EMERG", line);
+end
+
+function alert(line)
+ syslog.syslog("LOG_ALERT", line);
+end
+
+function crit(line)
+ syslog.syslog("LOG_CRIT", line);
+end
+
+function err(line)
+ syslog.syslog("LOG_ERR", line);
+end
+
+function warn(line)
+ syslog.syslog("LOG_WARNING", line);
+end
+
+function notice(line)
+ syslog.syslog("LOG_NOTICE", line);
+end
+
+function info(line)
+ syslog.syslog("LOG_INFO", line);
+end
+
+function dbg(line)
+ local caller, str;
+
+ caller = debug.getinfo(2);
+ str = string.format("%s:%d:%s(): %s", caller.short_src,
+ caller.currentline, caller.name or "<none>", line or "");
+
+ syslog.syslog("LOG_DEBUG", str);
+
+end
+
+function syslog_init(name, flags, facility)
+ _G.syslog = require "syslog";
+
+ -- Defaulting
+ name = name or "lua";
+ flags = flags or syslog.LOG_PID + syslog.LOG_PERROR +
+ syslog.LOG_ODELAY;
+ facility = facility or "LOG_USER";
+
+ if type(syslog) ~= "table" then
+ error("Can't use syslog module");
+ end
+
+ syslog.openlog(name, flags, facility);
+
+ _G.print_native = print;
+
+ _G.print = function (...)
+ -- "string.format" need raw string of "print" as a single string
+ -- info(table.concat(arg, "\t"):gsub("%%","%%%%") .. "\n");
+ -- XXX: return it to info
+ -- dbg(table.concat(arg, "\t"):gsub("%%","%%%%") .. "\n");
+
+ local caller, str;
+
+ caller = debug.getinfo(2);
+ str = string.format("%s:%d:%s(): %s", caller.short_src,
+ caller.currentline, caller.name or "<none>",
+ table.concat(arg, "\t"):gsub("%%","%%%%"));
+ syslog.syslog("LOG_DEBUG", str);
+ end
+
+end
More information about the Zrouter-src
mailing list