Mercurial > prosody-hg
comparison core/loggingmanager.lua @ 4797:e239668aa6d2
Merge 0.9->trunk
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 29 Apr 2012 02:10:55 +0100 |
| parents | b046cafc81a8 |
| children | 78a3d275715a |
comparison
equal
deleted
inserted
replaced
| 4796:04a34287dc12 | 4797:e239668aa6d2 |
|---|---|
| 39 local logging_config; | 39 local logging_config; |
| 40 | 40 |
| 41 local apply_sink_rules; | 41 local apply_sink_rules; |
| 42 local log_sink_types = setmetatable({}, { __newindex = function (t, k, v) rawset(t, k, v); apply_sink_rules(k); end; }); | 42 local log_sink_types = setmetatable({}, { __newindex = function (t, k, v) rawset(t, k, v); apply_sink_rules(k); end; }); |
| 43 local get_levels; | 43 local get_levels; |
| 44 local logging_levels = { "debug", "info", "warn", "error", "critical" } | 44 local logging_levels = { "debug", "info", "warn", "error" } |
| 45 | 45 |
| 46 -- Put a rule into action. Requires that the sink type has already been registered. | 46 -- Put a rule into action. Requires that the sink type has already been registered. |
| 47 -- This function is called automatically when a new sink type is added [see apply_sink_rules()] | 47 -- This function is called automatically when a new sink type is added [see apply_sink_rules()] |
| 48 local function add_rule(sink_config) | 48 local function add_rule(sink_config) |
| 49 local sink_maker = log_sink_types[sink_config.to]; | 49 local sink_maker = log_sink_types[sink_config.to]; |
| 50 if sink_maker then | 50 if sink_maker then |
| 51 if sink_config.levels and not sink_config.source then | 51 -- Create sink |
| 52 -- Create sink | 52 local sink = sink_maker(sink_config); |
| 53 local sink = sink_maker(sink_config); | 53 |
| 54 | 54 -- Set sink for all chosen levels |
| 55 -- Set sink for all chosen levels | 55 for level in pairs(get_levels(sink_config.levels or logging_levels)) do |
| 56 for level in pairs(get_levels(sink_config.levels)) do | 56 logger.add_level_sink(level, sink); |
| 57 logger.add_level_sink(level, sink); | |
| 58 end | |
| 59 elseif sink_config.source and not sink_config.levels then | |
| 60 logger.add_name_sink(sink_config.source, sink_maker(sink_config)); | |
| 61 elseif sink_config.source and sink_config.levels then | |
| 62 local levels = get_levels(sink_config.levels); | |
| 63 local sink = sink_maker(sink_config); | |
| 64 logger.add_name_sink(sink_config.source, | |
| 65 function (name, level, ...) | |
| 66 if levels[level] then | |
| 67 return sink(name, level, ...); | |
| 68 end | |
| 69 end); | |
| 70 else | |
| 71 -- All sources | |
| 72 -- Create sink | |
| 73 local sink = sink_maker(sink_config); | |
| 74 | |
| 75 -- Set sink for all levels | |
| 76 for _, level in pairs(logging_levels) do | |
| 77 logger.add_level_sink(level, sink); | |
| 78 end | |
| 79 end | 57 end |
| 80 else | 58 else |
| 81 -- No such sink type | 59 -- No such sink type |
| 82 end | 60 end |
| 83 end | 61 end |
