summaryrefslogtreecommitdiff
path: root/lib/gitano/log.lua
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2014-03-06 15:09:14 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2014-03-06 15:09:14 +0000
commit72828dc0db2ac09ab93f4a6631c9da77e5534a55 (patch)
treefb204bdb229601c36aa470902fa7ee1a32f11595 /lib/gitano/log.lua
parent499505b70acc410cbf41ce6bf37416738851f49f (diff)
parentf0822b03e200b808588e5a016d188d179f9c0432 (diff)
downloadgitano-72828dc0db2ac09ab93f4a6631c9da77e5534a55.tar.gz
Merge branch 'richardipsum/http' which contains the HTTP work from Richard
Ipsum done for Baserock but rebased to remove Baserock-specific content.
Diffstat (limited to 'lib/gitano/log.lua')
-rw-r--r--lib/gitano/log.lua57
1 files changed, 53 insertions, 4 deletions
diff --git a/lib/gitano/log.lua b/lib/gitano/log.lua
index f243b87..e1df00b 100644
--- a/lib/gitano/log.lua
+++ b/lib/gitano/log.lua
@@ -14,6 +14,7 @@ local prefix = "[gitano] "
local transactionid = nil
local stream = sio.stderr
+local is_buffered = false
local ERRS = 0
local WARN = 1
@@ -24,6 +25,40 @@ local DEEPDEBUG = 5
local level = ERRS
+local LogBuf = {}
+LogBuf.__index = LogBuf
+
+function LogBuf:new()
+ return setmetatable({strings = {}}, self)
+end
+
+function LogBuf:write(s)
+ table.insert(self.strings, s)
+end
+
+function LogBuf:get()
+ return table.concat(self.strings)
+end
+
+local function is_buffered_output()
+ return is_buffered
+end
+
+local function buffer_output()
+ if not is_buffered_output() then
+ stream = LogBuf:new()
+ is_buffered = true
+ end
+end
+
+local function get_buffered_output()
+ if is_buffered_output() then
+ return stream:get()
+ else
+ return nil
+ end
+end
+
local function syslog_write(priority, ...)
local strs = {...}
@@ -98,15 +133,26 @@ end
local function stdout(...)
local savedstream, savedprefix = stream, prefix
- stream, prefix = sio.stdout, ""
+
+ prefix = ""
+ if not is_buffered_output() then
+ stream = sio.stdout
+ end
+
state(...)
stream, prefix = savedstream, savedprefix
end
local function fatal(...)
- syslog_write(luxio.LOG_EMERG, ...)
+ syslog_write(luxio.LOG_CRIT, ...)
AT(ERRS, "FATAL:", ...)
- stream:close()
+
+ if is_buffered_output() then
+ sio.stderr:write(get_buffered_output())
+ else
+ stream:close()
+ end
+
luxio._exit(1)
end
@@ -244,5 +290,8 @@ return {
info = syslog_info,
debug = syslog_debug,
close = syslog_close,
- }
+ },
+ buffer_output = buffer_output,
+ is_buffered_output = is_buffered_output,
+ get_buffered_output = get_buffered_output
}