aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2019-03-26 14:48:21 +0000
committerMatthew Wild <mwild1@gmail.com>2019-03-26 14:48:21 +0000
commit0c7ea2e51a59a69ab23abc505bbcd9b6ba3722bc (patch)
treedec04f69a3ca0b8a0527ee31e08368b9c19660ba
parent8e20f176e04a261129c9d49705b72f9460999145 (diff)
downloadprosody-0c7ea2e51a59a69ab23abc505bbcd9b6ba3722bc.tar.gz
prosody-0c7ea2e51a59a69ab23abc505bbcd9b6ba3722bc.zip
loggingmanager, mod_posix: Move syslog to core, fixes #541 (in a way)
-rw-r--r--core/loggingmanager.lua19
-rw-r--r--plugins/mod_posix.lua13
2 files changed, 19 insertions, 13 deletions
diff --git a/core/loggingmanager.lua b/core/loggingmanager.lua
index cfa8246a..85a6380b 100644
--- a/core/loggingmanager.lua
+++ b/core/loggingmanager.lua
@@ -18,6 +18,9 @@ local getstyle, getstring = require "util.termcolours".getstyle, require "util.t
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 @@ local function log_to_console(sink_config)
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;
diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua
index 23df4d23..8367ae9e 100644
--- a/plugins/mod_posix.lua
+++ b/plugins/mod_posix.lua
@@ -113,19 +113,6 @@ local function write_pidfile()
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()