summaryrefslogtreecommitdiff
path: root/log.lua
diff options
context:
space:
mode:
Diffstat (limited to 'log.lua')
-rw-r--r--log.lua12
1 files changed, 8 insertions, 4 deletions
diff --git a/log.lua b/log.lua
index 3d04bfc..550a4bd 100644
--- a/log.lua
+++ b/log.lua
@@ -2,6 +2,8 @@ local pprint = require 'pprint'
local class = require 'r.class'
local qw = require 'r.qw'
+local levels = qw"debug proto info warn error"
+
local Log = class()
function Log.make(cls, name, level)
return setmetatable({
@@ -9,12 +11,14 @@ function Log.make(cls, name, level)
level = level or 'info',
},cls)
end
-local levels = qw"debug info warn error"
+local colours = {debug="\x1b[38;5;8m",error="\x1b[31m"}
function Log.format(self, level, ...)
local vals = {} for i=1,select('#',...) do
- vals[i] = tostring(select(i,...)) end
- return (level == 'error' and '\x1b[31m' or '')
- ..os.date"%Y-%m-%d %H:%M:%S%z"
+ local v = (select(i,...))
+ vals[i] = type(v) == 'string' and v or pprint.pformat(v)
+ end
+ return (colours[level] or '')
+ .. os.date"%Y-%m-%d %H:%M:%S%z"
.. ' ' .. level .. (" "):rep(5-#level)
.. ' [' .. self.name .. '] '
.. table.concat(vals,' ') .. '\x1b[0m' .. '\n'