Comparison

core/loggingmanager.lua @ 9925:8d0112413997

Backed out changeset 3eea63a68e0f Commit included intended changes to loggingmanager
author Matthew Wild <mwild1@gmail.com>
date Tue, 26 Mar 2019 13:51:06 +0000
parent 9902:3eea63a68e0f
child 9927:1460c4966262
comparison
equal deleted inserted replaced
9924:5a2e53bef031 9925:8d0112413997
16 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring; 16 local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
17 17
18 local config = require "core.configmanager"; 18 local config = require "core.configmanager";
19 local logger = require "util.logger"; 19 local logger = require "util.logger";
20 20
21 local have_pposix, pposix = pcall(require, "util.pposix");
22 have_pposix = have_pposix and pposix._VERSION == "0.4.4";
23
24 local _ENV = nil; 21 local _ENV = nil;
25 -- luacheck: std none 22 -- luacheck: std none
26 23
27 -- The log config used if none specified in the config file (see reload_logging for initialization) 24 -- The log config used if none specified in the config file (see reload_logging for initialization)
28 local default_logging; 25 local default_logging;
46 43
47 -- Create sink 44 -- Create sink
48 local sink = sink_maker(sink_config); 45 local sink = sink_maker(sink_config);
49 46
50 -- Set sink for all chosen levels 47 -- Set sink for all chosen levels
51 local levels = get_levels(sink_config.levels or logging_levels); 48 for level in pairs(get_levels(sink_config.levels or logging_levels)) do
52 for level in pairs(levels) do
53 logger.add_level_sink(level, sink); 49 logger.add_level_sink(level, sink);
54 end 50 end
55 end 51 end
56 52
57 -- Search for all rules using a particular sink type, and apply 53 -- Search for all rules using a particular sink type, and apply
234 return logstdout(name, level, message, ...); 230 return logstdout(name, level, message, ...);
235 end 231 end
236 end 232 end
237 log_sink_types.console = log_to_console; 233 log_sink_types.console = log_to_console;
238 234
239 if have_pposix then
240 local syslog_opened;
241 local function log_to_syslog(sink_config) -- luacheck: ignore 212/sink_config
242 if not syslog_opened then
243 pposix.syslog_open(sink_config.syslog_name or "prosody", sink_config.syslog_facility or config.get("*", "syslog_facility"));
244 syslog_opened = true;
245 end
246 local syslog = pposix.syslog_log;
247 return function (name, level, message, ...)
248 syslog(level, name, format(message, ...));
249 end;
250 end
251 log_sink_types.syslog = log_to_syslog;
252 end
253
254 local function register_sink_type(name, sink_maker) 235 local function register_sink_type(name, sink_maker)
255 local old_sink_maker = log_sink_types[name]; 236 local old_sink_maker = log_sink_types[name];
256 log_sink_types[name] = sink_maker; 237 log_sink_types[name] = sink_maker;
257 return old_sink_maker; 238 return old_sink_maker;
258 end 239 end