aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2022-03-17 10:24:38 +0000
committerMatthew Wild <mwild1@gmail.com>2022-03-17 10:24:38 +0000
commit36fbcd47721f51abfd59ec3a58286c3c6aedd7e0 (patch)
treefbbf975cbde200a915777f273ff64254b985e9bf /plugins
parent119725bbe3a4182fc573a32805a46069d2affa0b (diff)
downloadprosody-36fbcd47721f51abfd59ec3a58286c3c6aedd7e0.tar.gz
prosody-36fbcd47721f51abfd59ec3a58286c3c6aedd7e0.zip
mod_admin_shell: Add watch:log() command to tail logs in realtime
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_admin_shell.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/plugins/mod_admin_shell.lua b/plugins/mod_admin_shell.lua
index 28536c53..9af77676 100644
--- a/plugins/mod_admin_shell.lua
+++ b/plugins/mod_admin_shell.lua
@@ -36,6 +36,7 @@ local serialization = require "util.serialization";
local serialize_config = serialization.new ({ fatal = false, unquoted = true});
local time = require "util.time";
local promise = require "util.promise";
+local logger = require "util.logger";
local t_insert = table.insert;
local t_concat = table.concat;
@@ -1589,6 +1590,26 @@ function def_env.http:list(hosts)
return true;
end
+def_env.watch = {};
+
+function def_env.watch:log()
+ local writing = false;
+ local sink = logger.add_simple_sink(function (source, level, message)
+ if writing then return; end
+ writing = true;
+ self.session.print(source, level, message);
+ writing = false;
+ end);
+
+ while self.session.is_connected() do
+ async.sleep(3);
+ end
+ if not logger.remove_sink(sink) then
+ module:log("warn", "Unable to remove watch:log() sink");
+ end
+end
+
+
def_env.debug = {};
function def_env.debug:logevents(host)