-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
77 lines (60 loc) · 1.41 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
local naughty = require("naughty")
local awful = require("awful")
local talkative = { loggers = {}, mt = {}}
local defaults = {}
local settings = {}
defaults.loggers = { }
defaults.defaultlevel = 0
for key, value in pairs(defaults) do
settings[key] = value
end
talkative.level = {
ERROR = 3,
WARNING = 2,
NORMAL = 1,
DEBUG = 0
}
local function loglv(msg, level)
for _,logger in ipairs(settings.loggers) do
logger(msg, level)
end
end
function talkative.dbg(msg)
loglv(msg, 0)
end
function talkative.log(msg)
loglv(msg, 1)
end
function talkative.warn(msg)
loglv(msg, 2)
end
function talkative.error(msg)
loglv(msg, 3)
end
function talkative.add_logger(logger, level)
if level == nil then
level = settings.defaultlevel
end
table.insert(settings.loggers, function(msg, severity)
if severity >= level then
logger(msg, severity)
end
end)
end
function talkative.loggers.naughty(msg, severity)
if severity == talkative.level.WARNING then
msg = "<span color=\"#ff6\">".. msg .. "</span>"
elseif severity == talkative.level.ERROR then
msg = "<span color=\"#f66\">".. msg .. "</span>"
end
naughty.notify({ text = msg })
end
function talkative.spawn(command)
talkative.dbg("Executing: " .. command)
awful.spawn(command)
end
function talkative.loggers.stdio(msg, severity)
print(msg)
end
talkative.mt.__call = function(t,message) talkative.log(message) end
return setmetatable(talkative, talkative.mt)