Nice wee module! I've learned a lot from it. Many thanks.
Some minor changes you could make:
-
if you change function spec of log.level from log[x.name] = function(...) to log[x.name] = function(fmt, ...) you can then append fmt to your format string print(string.format("%s[%-6s%s]%s %s: " .. fmt, ...) and allow the calls to use param substitution e.g: log.error("Some error no: %d", errno)
-
Add export log.levels = levels so the list of level strings can be accessed and tested against : if log.levels[level] then etc
-
Add function log.log() where first param is level makes dynamic level change easy:
log.log = function(level, ...) if levels[level] then log[level](...) else log[log.level](...) end end
Nice wee module! I've learned a lot from it. Many thanks.
Some minor changes you could make:
if you change function spec of log.level from
log[x.name] = function(...)tolog[x.name] = function(fmt, ...)you can then append fmt to your format stringprint(string.format("%s[%-6s%s]%s %s: " .. fmt, ...)and allow the calls to use param substitution e.g:log.error("Some error no: %d", errno)Add export log.levels = levels so the list of level strings can be accessed and tested against :
if log.levels[level] thenetcAdd function log.log() where first param is level makes dynamic level change easy:
log.log = function(level, ...) if levels[level] then log[level](...) else log[log.level](...) end end