Changeset

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
parents 9901:c8b75239846c
children 9903:2c5546cc5c70
files core/loggingmanager.lua util/queue.lua
diffstat 2 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/core/loggingmanager.lua	Sat Mar 23 08:47:55 2019 +0000
+++ b/core/loggingmanager.lua	Sat Mar 23 08:52:57 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.4";
+
 local _ENV = nil;
 -- luacheck: std none
 
@@ -45,7 +48,8 @@
 	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 @@
 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;
--- a/util/queue.lua	Sat Mar 23 08:47:55 2019 +0000
+++ b/util/queue.lua	Sat Mar 23 08:52:57 2019 +0000
@@ -52,16 +52,15 @@
 			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)