Comparison

core/loggingmanager.lua @ 9902:3eea63a68e0f

util.queue: Update :items() to consistently use private data directly It will perform better this way, and we were accessing private variables already within the iterator.
author Matthew Wild <mwild1@gmail.com>
date Sat, 23 Mar 2019 08:52:57 +0000
parent 8750:7ae09468ad92
child 9925:8d0112413997
comparison
equal deleted inserted replaced
9901:c8b75239846c 9902:3eea63a68e0f
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
21 local _ENV = nil; 24 local _ENV = nil;
22 -- luacheck: std none 25 -- luacheck: std none
23 26
24 -- The log config used if none specified in the config file (see reload_logging for initialization) 27 -- The log config used if none specified in the config file (see reload_logging for initialization)
25 local default_logging; 28 local default_logging;
43 46
44 -- Create sink 47 -- Create sink
45 local sink = sink_maker(sink_config); 48 local sink = sink_maker(sink_config);
46 49
47 -- Set sink for all chosen levels 50 -- Set sink for all chosen levels
48 for level in pairs(get_levels(sink_config.levels or logging_levels)) do 51 local levels = get_levels(sink_config.levels or logging_levels);
52 for level in pairs(levels) do
49 logger.add_level_sink(level, sink); 53 logger.add_level_sink(level, sink);
50 end 54 end
51 end 55 end
52 56
53 -- Search for all rules using a particular sink type, and apply 57 -- Search for all rules using a particular sink type, and apply
230 return logstdout(name, level, message, ...); 234 return logstdout(name, level, message, ...);
231 end 235 end
232 end 236 end
233 log_sink_types.console = log_to_console; 237 log_sink_types.console = log_to_console;
234 238
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
235 local function register_sink_type(name, sink_maker) 254 local function register_sink_type(name, sink_maker)
236 local old_sink_maker = log_sink_types[name]; 255 local old_sink_maker = log_sink_types[name];
237 log_sink_types[name] = sink_maker; 256 log_sink_types[name] = sink_maker;
238 return old_sink_maker; 257 return old_sink_maker;
239 end 258 end