aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/loggingmanager.lua31
-rw-r--r--core/modulemanager.lua8
-rw-r--r--core/presencemanager.lua2
-rw-r--r--core/s2smanager.lua12
-rw-r--r--core/sessionmanager.lua7
5 files changed, 48 insertions, 12 deletions
diff --git a/core/loggingmanager.lua b/core/loggingmanager.lua
index 5dff6a34..13b091cc 100644
--- a/core/loggingmanager.lua
+++ b/core/loggingmanager.lua
@@ -6,7 +6,7 @@ local tostring, setmetatable, rawset, pairs, ipairs, type =
tostring, setmetatable, rawset, pairs, ipairs, type;
local io_open, io_write = io.open, io.write;
local math_max, rep = math.max, string.rep;
-local os_getenv = os.getenv;
+local os_date, os_getenv = os.date, os.getenv;
local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring;
local config = require "core.configmanager";
@@ -20,7 +20,7 @@ module "loggingmanager"
-- The log config used if none specified in the config file
local default_logging = { { to = "console" } };
local default_file_logging = { { to = "file", levels = { min = "info" } } };
-
+local default_timestamp = "%b %d %T";
-- The actual config loggingmanager is using
local logging_config = config.get("*", "core", "log") or default_logging;
@@ -130,9 +130,18 @@ end
local sourcewidth = 20;
function log_sink_types.stdout()
+ local timestamps = config.timestamps;
+
+ if timestamps == true then
+ timestamps = default_timestamp; -- Default format
+ end
+
return function (name, level, message, ...)
sourcewidth = math_max(#name+2, sourcewidth);
local namelen = #name;
+ if timestamps then
+ io_write(os_date(timestamps), " ");
+ end
if ... then
io_write(name, rep(" ", sourcewidth-namelen), level, "\t", format(message, ...), "\n");
else
@@ -156,9 +165,18 @@ do
return log_sink_types.stdout(config);
end
+ local timestamps = config.timestamps;
+
+ if timestamps == true then
+ timestamps = default_timestamp; -- Default format
+ end
+
return function (name, level, message, ...)
sourcewidth = math_max(#name+2, sourcewidth);
local namelen = #name;
+ if timestamps then
+ io_write(os_date(timestamps), " ");
+ end
if ... then
io_write(name, rep(" ", sourcewidth-namelen), getstring(logstyles[level], level), "\t", format(message, ...), "\n");
else
@@ -175,8 +193,17 @@ function log_sink_types.file(config)
return function () end
end
+ local timestamps = config.timestamps;
+
+ if timestamps == true then
+ timestamps = default_timestamp; -- Default format
+ end
+
local write, format, flush = logfile.write, format, logfile.flush;
return function (name, level, message, ...)
+ if timestamps then
+ write(logfile, os_date(timestamps), " ");
+ end
if ... then
write(logfile, name, "\t", level, "\t", format(message, ...), "\n");
else
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index a1d3bef3..cc48c2f6 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -123,6 +123,10 @@ function load(host, module_name, config)
-- Use modified host, if the module set one
modulemap[api_instance.host][module_name] = pluginenv;
+ if api_instance.host == "*" and host ~= "*" then
+ api_instance:set_global();
+ end
+
return true;
end
@@ -260,6 +264,10 @@ end
function api:set_global()
self.host = "*";
+ -- Update the logger
+ local _log = logger.init("mod_"..self.name);
+ self.log = function (self, ...) return _log(...); end;
+ self._log = _log;
end
local function _add_handler(module, origin_type, tag, xmlns, handler)
diff --git a/core/presencemanager.lua b/core/presencemanager.lua
index db6bbf9a..ae73d676 100644
--- a/core/presencemanager.lua
+++ b/core/presencemanager.lua
@@ -144,7 +144,7 @@ function send_presence_of_available_resources(user, host, jid, recipient_session
end
end
end
- log("info", "broadcasted presence of "..count.." resources from "..user.."@"..host.." to "..jid);
+ log("debug", "broadcasted presence of "..count.." resources from "..user.."@"..host.." to "..jid);
return count;
end
diff --git a/core/s2smanager.lua b/core/s2smanager.lua
index a16f8b02..b14f0e96 100644
--- a/core/s2smanager.lua
+++ b/core/s2smanager.lua
@@ -48,7 +48,7 @@ local function compare_srv_priorities(a,b) return a.priority < b.priority or a.w
local function bounce_sendq(session)
local sendq = session.sendq;
if sendq then
- session.log("debug", "sending error replies for "..#sendq.." queued stanzas because of failed outgoing connection to "..tostring(session.to_host));
+ session.log("info", "sending error replies for "..#sendq.." queued stanzas because of failed outgoing connection to "..tostring(session.to_host));
local dummy = {
type = "s2sin";
send = function(s)
@@ -199,9 +199,9 @@ function attempt_connection(host_session, err)
host_session.srv_choice = host_session.srv_choice + 1;
local srv_choice = host_session.srv_hosts[host_session.srv_choice];
connect_host, connect_port = srv_choice.target or to_host, srv_choice.port or connect_port;
- host_session.log("debug", "Connection failed (%s). Attempt #%d: This time to %s:%d", tostring(err), host_session.srv_choice, connect_host, connect_port);
+ host_session.log("info", "Connection failed (%s). Attempt #%d: This time to %s:%d", tostring(err), host_session.srv_choice, connect_host, connect_port);
else
- host_session.log("debug", "Out of connection options, can't connect to %s", tostring(host_session.to_host));
+ host_session.log("info", "Out of connection options, can't connect to %s", tostring(host_session.to_host));
-- We're out of options
return false;
end
@@ -216,7 +216,7 @@ function attempt_connection(host_session, err)
end
function try_connect(host_session, connect_host, connect_port)
- log("debug", "Beginning new connection attempt to %s (%s:%d)", host_session.to_host, connect_host, connect_port);
+ host_session.log("info", "Beginning new connection attempt to %s (%s:%d)", host_session.to_host, connect_host, connect_port);
-- Ok, we're going to try to connect
local from_host, to_host = host_session.from_host, host_session.to_host;
@@ -338,7 +338,7 @@ function make_authenticated(session, host)
else
return false;
end
- session.log("info", "connection is now authenticated");
+ session.log("debug", "connection %s->%s is now authenticated", session.from_host or "(unknown)", session.to_host or "(unknown)");
mark_connected(session);
@@ -350,7 +350,7 @@ function mark_connected(session)
local from, to = session.from_host, session.to_host;
- session.log("debug", session.direction.." s2s connection "..from.."->"..to.." is now complete");
+ session.log("info", session.direction.." s2s connection "..from.."->"..to.." complete");
local send_to_host = send_to_host;
function session.send(data) send_to_host(to, from, data); end
diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua
index 52e418cc..68493d87 100644
--- a/core/sessionmanager.lua
+++ b/core/sessionmanager.lua
@@ -45,7 +45,7 @@ function new_session(conn)
getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; end;
end
open_sessions = open_sessions + 1;
- log("info", "open sessions now: ".. open_sessions);
+ log("debug", "open sessions now: ".. open_sessions);
local w = conn.write;
session.send = function (t) w(tostring(t)); end
session.ip = conn.ip();
@@ -53,7 +53,7 @@ function new_session(conn)
end
function destroy_session(session, err)
- (session.log or log)("info", "Destroying session");
+ (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)");
-- Send unavailable presence
if session.presence then
@@ -94,6 +94,7 @@ function make_authenticated(session, username)
if session.type == "c2s_unauthed" then
session.type = "c2s";
end
+ session.log("info", "Authenticated as %s@%s", username or "(unknown)", session.host or "(unknown)");
return true;
end
@@ -176,7 +177,7 @@ function streamopened(session, attr)
send(features);
- (session.log or log)("info", "Sent reply <stream:stream> to client");
+ (session.log or log)("debug", "Sent reply <stream:stream> to client");
session.notopen = nil;
end