aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2019-03-23 08:52:57 +0000
committerMatthew Wild <mwild1@gmail.com>2019-03-23 08:52:57 +0000
commit3c50aa4902aada8eccbdd32f359a0cd6a52aceae (patch)
treec1d72c0e25c39c1a1f62f34a815453b20565f677
parenta274eacbbc62164a6567faeaa8d18ea5993a133f (diff)
downloadprosody-3c50aa4902aada8eccbdd32f359a0cd6a52aceae.tar.gz
prosody-3c50aa4902aada8eccbdd32f359a0cd6a52aceae.zip
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.
-rw-r--r--core/loggingmanager.lua21
-rw-r--r--util/queue.lua9
2 files changed, 24 insertions, 6 deletions
diff --git a/core/loggingmanager.lua b/core/loggingmanager.lua
index cfa8246a..b510617f 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.4";
+
local _ENV = nil;
-- luacheck: std none
@@ -45,7 +48,8 @@ local function add_rule(sink_config)
local sink = sink_maker(sink_config);
-- Set sink for all chosen levels
- for level in pairs(get_levels(sink_config.levels or logging_levels)) do
+ local levels = get_levels(sink_config.levels or logging_levels);
+ for level in pairs(levels) do
logger.add_level_sink(level, sink);
end
end
@@ -232,6 +236,21 @@ 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
+ pposix.syslog_open(sink_config.syslog_name or "prosody", sink_config.syslog_facility or config.get("*", "syslog_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/util/queue.lua b/util/queue.lua
index e63b3f1c..66ed098b 100644
--- a/util/queue.lua
+++ b/util/queue.lua
@@ -52,16 +52,15 @@ local function new(size, allow_wrapping)
return t[tail];
end;
items = function (self)
- --luacheck: ignore 431/t
- return function (t, pos)
- if pos >= t:count() then
+ return function (_, pos)
+ if pos >= items then
return nil;
end
local read_pos = tail + pos;
- if read_pos > t.size then
+ if read_pos > self.size then
read_pos = (read_pos%size);
end
- return pos+1, t._items[read_pos];
+ return pos+1, t[read_pos];
end, self, 0;
end;
consume = function (self)