]> git.lizzy.rs Git - luairc.git/blob - src/irc/debug.lua
2e03d7452f3433c3cc64001b6f2a7743c79f3592
[luairc.git] / src / irc / debug.lua
1 -- initialization {{{
2 local base = _G
3 local io =   require 'io'
4 -- }}}
5
6 module 'irc.debug'
7
8 -- defaults {{{
9 COLOR = true
10 -- }}}
11
12 -- local variables {{{
13 local ON = false
14 local outfile = io.output()
15 -- }}}
16
17 -- public functions {{{
18 -- enable {{{
19 function enable()
20     ON = true
21 end
22 -- }}}
23
24 -- disable {{{
25 function disable()
26     ON = false
27 end
28 -- }}}
29
30 -- set_output {{{
31 function set_output(file)
32     outfile = base.assert(io.open(file))
33 end
34 -- }}}
35
36 -- message {{{
37 function message(msg_type, msg, color)
38     if ON then
39         local endcolor = ""
40         if COLOR then
41             color = color or "\027[1;30m"
42             endcolor = "\027[0m"
43         else
44             color = ""
45             endcolor = ""
46         end
47         outfile:write(color .. msg_type .. ": " .. msg .. endcolor .. "\n")
48     end
49 end
50 -- }}}
51
52 -- err {{{
53 function err(msg)
54     message("ERR", msg, "\027[0;31m")
55     base.error(msg, 2)
56 end
57 -- }}}
58
59 -- warn {{{
60 function warn(msg)
61     message("WARN", msg, "\027[0;33m")
62 end
63 -- }}}
64 -- }}}