Software /
code /
prosody
Annotate
core/loggingmanager.lua @ 1021:f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 21 Apr 2009 20:30:29 +0100 |
parent | 1016:73afe3e30e97 |
child | 1024:1bcc8ca57a7c |
rev | line source |
---|---|
1016
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local format, rep = string.format, string.rep; |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local io_write = io.write; |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local pcall = pcall; |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local debug = debug; |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local tostring = tostring; |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local math_max = math.max; |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local logger = require "util.logger"; |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 -- Global log function, because some people are too |
1021
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
12 -- lazy to get their own... |
1016
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 _G.log = logger.init("general"); |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
1021
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
15 local log_sink_types = {}; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
16 local get_levels; |
1016
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
1021
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
18 --- Main function to read config, create the appropriate sinks and tell logger module |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
19 function setup_logging(log) |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
20 log = log or config.get("*", "core", "log") or default_logging; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
21 -- Set default logger |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
22 if type(log) == "string" then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
23 if not log:match("^%*") then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
24 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
25 elseif type(log) == "table" then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
26 -- Advanced configuration chosen |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
27 for i, sink_config in ipairs(log) do |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
28 local sink_maker = log_sink_types[sink_config.to]; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
29 if sink_maker then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
30 if sink_config.levels and not sink_config.source then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
31 -- Create sink |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
32 local sink = sink_maker(sink_config); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
33 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
34 -- Set sink for all chosen levels |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
35 for level in pairs(get_levels(sink_config.levels)) do |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
36 logger.add_level_sink(level, sink); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
37 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
38 elseif sink_config.source and not sink_config.levels then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
39 logger.add_name_sink(sink_config.source, sink_maker(sink_config)); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
40 elseif sink_config.source and sink_config.levels then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
41 local levels = get_levels(sink_config.levels); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
42 local sink = sink_maker(sink_config); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
43 logger.add_name_sink(sink_config.source, |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
44 function (name, level, ...) |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
45 if levels[level] then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
46 return sink(name, level, ...); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
47 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
48 end); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
49 else |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
50 -- All sources |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
51 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
52 else |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
53 -- No such sink type |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
54 end |
1016
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 end |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 end |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 end |
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 |
1021
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
59 --- Definition of built-in logging sinks --- |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
60 local math_max, rep = math.max, string.rep; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
61 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
62 -- Column width for "source" (used by stdout and console) |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
63 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
64 function log_sink_types.nowhere() |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
65 return function () return false; end; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
66 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
67 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
68 local sourcewidth = 20; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
69 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
70 function log_sink_types.stdout() |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
71 return function (name, level, message, ...) |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
72 sourcewidth = math_max(#name+2, sourcewidth); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
73 local namelen = #name; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
74 if ... then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
75 io_write(name, rep(" ", sourcewidth-namelen), level, "\t", format(message, ...), "\n"); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
76 else |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
77 io_write(name, rep(" ", sourcewidth-namelen), level, "\t", message, "\n"); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
78 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
79 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
80 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
81 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
82 do |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
83 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
84 local do_pretty_printing = not os.getenv("WINDIR"); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
85 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
86 local logstyles = {}; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
87 if do_pretty_printing then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
88 logstyles["info"] = getstyle("bold"); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
89 logstyles["warn"] = getstyle("bold", "yellow"); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
90 logstyles["error"] = getstyle("bold", "red"); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
91 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
92 function log_sink_types.console(config) |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
93 -- Really if we don't want pretty colours then just use plain stdout |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
94 if not do_pretty_printing then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
95 return log_sink_types.stdout(config); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
96 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
97 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
98 return function (name, level, message, ...) |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
99 sourcewidth = math_max(#name+2, sourcewidth); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
100 local namelen = #name; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
101 if ... then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
102 io_write(name, rep(" ", sourcewidth-namelen), getstring(logstyles[level], level), "\t", format(message, ...), "\n"); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
103 else |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
104 io_write(name, rep(" ", sourcewidth-namelen), getstring(logstyles[level], level), "\t", message, "\n"); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
105 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
106 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
107 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
108 end |
1016
73afe3e30e97
core.loggingmanager: A new manager (yay!) to manage log output
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 |
1021
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
110 function log_sink_types.file(config) |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
111 local log = config.filename; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
112 local logfile = io.open(log, "a+"); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
113 if not logfile then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
114 return function () end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
115 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
116 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
117 local write, format, flush = logfile.write, string.format, logfile.flush; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
118 return function (name, level, message, ...) |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
119 if ... then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
120 write(logfile, name, "\t", level, "\t", format(message, ...), "\n"); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
121 else |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
122 write(logfile, name, "\t" , level, "\t", message, "\n"); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
123 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
124 flush(logfile); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
125 end; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
126 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
127 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
128 function log_sink_types.syslog() |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
129 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
130 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
131 --- Helper function to get a set of levels given a "criteria" table |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
132 local logging_levels = { "debug", "info", "warn", "error", "critical" } |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
133 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
134 function get_levels(criteria, set) |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
135 set = set or {}; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
136 if type(criteria) == "string" then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
137 set[criteria] = true; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
138 return set; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
139 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
140 local min, max = criteria.min, criteria.max; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
141 if min or max then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
142 local in_range; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
143 for _, level in ipairs(logging_levels) do |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
144 if min == level then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
145 set[level] = true; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
146 in_range = true; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
147 elseif max == level then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
148 set[level] = true; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
149 return set; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
150 elseif in_range then |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
151 set[level] = true; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
152 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
153 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
154 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
155 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
156 for _, level in ipairs(criteria) do |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
157 set[level] = true; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
158 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
159 return set; |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
160 end |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
161 |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
162 --- Set up logging |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
163 setup_logging(); |
f9122efeaadd
core.loggingmanager: Filled out most code, and cleaned up
Matthew Wild <mwild1@gmail.com>
parents:
1016
diff
changeset
|
164 |