core/loggingmanager.lua
changeset 9931 1460c4966262
parent 9929 8d0112413997
child 11645 b03053ec6dcf
equal deleted inserted replaced
9930:1bfd28e774db 9931:1460c4966262
    15 local os_date = os.date;
    15 local os_date = os.date;
    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 
       
    21 local have_pposix, pposix = pcall(require, "util.pposix");
       
    22 have_pposix = have_pposix and pposix._VERSION == "0.4.0";
    20 
    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)
   230 		return logstdout(name, level, message, ...);
   233 		return logstdout(name, level, message, ...);
   231 	end
   234 	end
   232 end
   235 end
   233 log_sink_types.console = log_to_console;
   236 log_sink_types.console = log_to_console;
   234 
   237 
       
   238 if have_pposix then
       
   239 	local syslog_opened;
       
   240 	local function log_to_syslog(sink_config) -- luacheck: ignore 212/sink_config
       
   241 		if not syslog_opened then
       
   242 			local facility = sink_config.syslog_facility or config.get("*", "syslog_facility");
       
   243 			pposix.syslog_open(sink_config.syslog_name or "prosody", 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