diff options
-rw-r--r-- | lib/gitano/log.lua | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/lib/gitano/log.lua b/lib/gitano/log.lua index f243b87..38a4d37 100644 --- a/lib/gitano/log.lua +++ b/lib/gitano/log.lua @@ -24,6 +24,41 @@ local DEEPDEBUG = 5 local level = ERRS +local StringBuf = { + strings = {} +} + +function StringBuf:new() + t = {} + setmetatable(t, self) + self.__index = self + return t +end + +function StringBuf:write(s) + table.insert(self.strings, s) +end + +function StringBuf:get() + return table.concat(self.strings) +end + +function StringBuf:close() + return +end + +local function buffer_output() + stream = StringBuf:new() +end + +local function is_buffered_output() + return stream.strings ~= nil +end + +local function get_buffered_output() + return stream:get() +end + local function syslog_write(priority, ...) local strs = {...} @@ -98,7 +133,12 @@ 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 @@ -244,5 +284,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 } |