Fix logging

This commit is contained in:
crater2150 2015-05-24 23:47:19 +02:00
parent 758dd8348d
commit 890bdf1866
2 changed files with 12 additions and 7 deletions

5
rc.lua
View file

@ -13,9 +13,8 @@ layouts = require('layouts')
-- {{{ Logging -- {{{ Logging
log = require("simplelog") log = require("simplelog")
log.add_logger(log.loggers.stdio, log.level.debug) log.add_logger(log.loggers.stdio, log.level.DEBUG)
log.add_logger(log.loggers.naughty, log.level.warn) log.add_logger(log.loggers.naughty, log.level.WARNING)
-- }}} -- }}}
-- {{{ Tags -- {{{ Tags

View file

@ -1,4 +1,5 @@
local naughty = require("naughty") local naughty = require("naughty")
local awful = require("awful")
local simplelog = { loggers = {}, mt = {}} local simplelog = { loggers = {}, mt = {}}
@ -12,13 +13,12 @@ for key, value in pairs(defaults) do
settings[key] = value settings[key] = value
end end
local level = { simplelog.level = {
ERROR = 3, ERROR = 3,
WARNING = 2, WARNING = 2,
NORMAL = 1, NORMAL = 1,
DEBUG = 0 DEBUG = 0
} }
simplelog.level = level
local function loglv(msg, level) local function loglv(msg, level)
for _,logger in ipairs(settings.loggers) do for _,logger in ipairs(settings.loggers) do
@ -54,18 +54,24 @@ function simplelog.add_logger(logger, level)
end end
function simplelog.loggers.naughty(msg, severity) function simplelog.loggers.naughty(msg, severity)
if severity == level.WARNING then if severity == simplelog.level.WARNING then
msg = "<span color=\"#ff6\">".. msg .. "</span>" msg = "<span color=\"#ff6\">".. msg .. "</span>"
elseif severity == level.ERROR then elseif severity == simplelog.level.ERROR then
msg = "<span color=\"#f66\">".. msg .. "</span>" msg = "<span color=\"#f66\">".. msg .. "</span>"
end end
naughty.notify({ text = msg }) naughty.notify({ text = msg })
end end
function simplelog.spawn(command)
simplelog.dbg("Executing: " .. command)
awful.util.spawn(command)
end
function simplelog.loggers.stdio(msg, severity) function simplelog.loggers.stdio(msg, severity)
print(msg) print(msg)
end end
simplelog.mt.__call = function(t,message) simplelog.log(message) end simplelog.mt.__call = function(t,message) simplelog.log(message) end
return setmetatable(simplelog, simplelog.mt) return setmetatable(simplelog, simplelog.mt)