Software /
code /
prosody
Comparison
core/loggingmanager.lua @ 1024:1bcc8ca57a7c
core.loggingmanager: Add default logging settings (to console) and fill out code for adding sinks which catch all sources
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 21 Apr 2009 21:10:42 +0100 |
parent | 1021:f9122efeaadd |
child | 1031:ec013f93de81 |
comparison
equal
deleted
inserted
replaced
1021:f9122efeaadd | 1024:1bcc8ca57a7c |
---|---|
6 local tostring = tostring; | 6 local tostring = tostring; |
7 local math_max = math.max; | 7 local math_max = math.max; |
8 | 8 |
9 local logger = require "util.logger"; | 9 local logger = require "util.logger"; |
10 | 10 |
11 local default_logging = { { to = "console" } }; | |
12 | |
11 -- Global log function, because some people are too | 13 -- Global log function, because some people are too |
12 -- lazy to get their own... | 14 -- lazy to get their own... |
13 _G.log = logger.init("general"); | 15 _G.log = logger.init("general"); |
14 | 16 |
15 local log_sink_types = {}; | 17 local log_sink_types = {}; |
16 local get_levels; | 18 local get_levels; |
19 local logging_levels = { "debug", "info", "warn", "error", "critical" } | |
17 | 20 |
18 --- Main function to read config, create the appropriate sinks and tell logger module | 21 --- Main function to read config, create the appropriate sinks and tell logger module |
19 function setup_logging(log) | 22 function setup_logging(log) |
20 log = log or config.get("*", "core", "log") or default_logging; | 23 log = log or config.get("*", "core", "log") or default_logging; |
21 -- Set default logger | 24 -- Set default logger |
45 if levels[level] then | 48 if levels[level] then |
46 return sink(name, level, ...); | 49 return sink(name, level, ...); |
47 end | 50 end |
48 end); | 51 end); |
49 else | 52 else |
50 -- All sources | 53 -- All sources |
54 -- Create sink | |
55 local sink = sink_maker(sink_config); | |
56 | |
57 -- Set sink for all levels | |
58 for _, level in pairs(logging_levels) do | |
59 logger.add_level_sink(level, sink); | |
60 end | |
51 end | 61 end |
52 else | 62 else |
53 -- No such sink type | 63 -- No such sink type |
54 end | 64 end |
55 end | 65 end |
127 | 137 |
128 function log_sink_types.syslog() | 138 function log_sink_types.syslog() |
129 end | 139 end |
130 | 140 |
131 --- Helper function to get a set of levels given a "criteria" table | 141 --- Helper function to get a set of levels given a "criteria" table |
132 local logging_levels = { "debug", "info", "warn", "error", "critical" } | |
133 | |
134 function get_levels(criteria, set) | 142 function get_levels(criteria, set) |
135 set = set or {}; | 143 set = set or {}; |
136 if type(criteria) == "string" then | 144 if type(criteria) == "string" then |
137 set[criteria] = true; | 145 set[criteria] = true; |
138 return set; | 146 return set; |