loggingmanager, mod_posix: Move syslog to core, fixes #541 (in a way)
authorMatthew Wild <mwild1@gmail.com>
Tue, 26 Mar 2019 14:48:21 +0000
changeset 9931 1460c4966262
parent 9930 1bfd28e774db
child 9932 d92ab8c8006a
loggingmanager, mod_posix: Move syslog to core, fixes #541 (in a way)
core/loggingmanager.lua
plugins/mod_posix.lua
--- a/core/loggingmanager.lua	Tue Mar 26 13:54:14 2019 +0000
+++ b/core/loggingmanager.lua	Tue Mar 26 14:48:21 2019 +0000
@@ -18,6 +18,9 @@
 local config = require "core.configmanager";
 local logger = require "util.logger";
 
+local have_pposix, pposix = pcall(require, "util.pposix");
+have_pposix = have_pposix and pposix._VERSION == "0.4.0";
+
 local _ENV = nil;
 -- luacheck: std none
 
@@ -232,6 +235,22 @@
 end
 log_sink_types.console = log_to_console;
 
+if have_pposix then
+	local syslog_opened;
+	local function log_to_syslog(sink_config) -- luacheck: ignore 212/sink_config
+		if not syslog_opened then
+			local facility = sink_config.syslog_facility or config.get("*", "syslog_facility");
+			pposix.syslog_open(sink_config.syslog_name or "prosody", facility);
+			syslog_opened = true;
+		end
+		local syslog = pposix.syslog_log;
+		return function (name, level, message, ...)
+			syslog(level, name, format(message, ...));
+		end;
+	end
+	log_sink_types.syslog = log_to_syslog;
+end
+
 local function register_sink_type(name, sink_maker)
 	local old_sink_maker = log_sink_types[name];
 	log_sink_types[name] = sink_maker;
--- a/plugins/mod_posix.lua	Tue Mar 26 13:54:14 2019 +0000
+++ b/plugins/mod_posix.lua	Tue Mar 26 14:48:21 2019 +0000
@@ -113,19 +113,6 @@
 	end
 end
 
-local syslog_opened;
-function syslog_sink_maker(config) -- luacheck: ignore 212/config
-	if not syslog_opened then
-		pposix.syslog_open("prosody", module:get_option_string("syslog_facility"));
-		syslog_opened = true;
-	end
-	local syslog = pposix.syslog_log;
-	return function (name, level, message, ...)
-		syslog(level, name, format(message, ...));
-	end;
-end
-require "core.loggingmanager".register_sink_type("syslog", syslog_sink_maker);
-
 local daemonize = module:get_option("daemonize", prosody.installed);
 
 local function remove_log_sinks()