summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2013-10-02 18:33:30 +0100
committerRichard Ipsum <richard.ipsum@codethink.co.uk>2013-10-02 18:33:30 +0100
commitf59d7392f000a885e204ee10b05cab5801c5de54 (patch)
tree2f37aad2c325750c6a4249ef534612211c0fdd3e
parentb2532d86d95fa8ad9d21b7c31685d73da129485b (diff)
downloadgitano-f59d7392f000a885e204ee10b05cab5801c5de54.tar.bz2
Add syslog support to gitano.log
-rw-r--r--lib/gitano/log.lua62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/gitano/log.lua b/lib/gitano/log.lua
index e0e5648..f243b87 100644
--- a/lib/gitano/log.lua
+++ b/lib/gitano/log.lua
@@ -6,10 +6,12 @@
local luxio = require "luxio"
local sio = require "luxio.simple"
+local os = require "os"
local concat = table.concat
local prefix = "[gitano] "
+local transactionid = nil
local stream = sio.stderr
@@ -22,6 +24,53 @@ local DEEPDEBUG = 5
local level = ERRS
+local function syslog_write(priority, ...)
+ local strs = {...}
+
+ for i = 1, #strs do
+ strs[i] = tostring(strs[i]) or "?"
+ end
+
+ luxio.syslog(priority, transactionid .. ": " .. concat(strs, " ") .. "\n")
+end
+
+local function syslog_open()
+ local ident = "gitano"
+ transactionid = luxio.getenv("GITANO_TRANSACTION_ID")
+
+ if not transactionid then
+ transactionid = tostring(luxio.getpid()) .. "." .. os.date("%H%M%S")
+ end
+
+ luxio.openlog(ident, 0, luxio.LOG_DAEMON)
+
+ return transactionid
+end
+
+local function syslog_close()
+ luxio.closelog()
+end
+
+local function syslog_error(...)
+ syslog_write(luxio.LOG_ERR, ...)
+end
+
+local function syslog_warning(...)
+ syslog_write(luxio.LOG_WARNING, ...)
+end
+
+local function syslog_notice(...)
+ syslog_write(luxio.LOG_NOTICE, ...)
+end
+
+local function syslog_info(...)
+ syslog_write(luxio.LOG_INFO, ...)
+end
+
+local function syslog_debug(...)
+ syslog_write(luxio.LOG_DEBUG, ...)
+end
+
local function set_prefix(new_prefix)
if not new_prefix then
prefix = ""
@@ -55,12 +104,14 @@ local function stdout(...)
end
local function fatal(...)
+ syslog_write(luxio.LOG_EMERG, ...)
AT(ERRS, "FATAL:", ...)
stream:close()
luxio._exit(1)
end
local function critical(...)
+ syslog_write(luxio.LOG_CRIT, ...)
return AT(ERRS, "CRIT:", ...)
end
@@ -183,4 +234,15 @@ return {
fatal = fatal,
stdout = stdout,
set_prefix = set_prefix,
+ syslog = {
+ open = syslog_open,
+ err = syslog_error,
+ error = syslog_error,
+ warn = syslog_warning,
+ warning = syslog_warning,
+ notice = syslog_notice,
+ info = syslog_info,
+ debug = syslog_debug,
+ close = syslog_close,
+ }
}