Comparison

plugins/mod_admin_shell.lua @ 12399:d99772b739e0

mod_admin_shell: Add watch:log() command to tail logs in realtime
author Matthew Wild <mwild1@gmail.com>
date Thu, 17 Mar 2022 10:24:38 +0000
parent 12398:478fff93ac37
child 12464:f4c59af273a3
comparison
equal deleted inserted replaced
12398:478fff93ac37 12399:d99772b739e0
34 local async = require "util.async"; 34 local async = require "util.async";
35 local serialization = require "util.serialization"; 35 local serialization = require "util.serialization";
36 local serialize_config = serialization.new ({ fatal = false, unquoted = true}); 36 local serialize_config = serialization.new ({ fatal = false, unquoted = true});
37 local time = require "util.time"; 37 local time = require "util.time";
38 local promise = require "util.promise"; 38 local promise = require "util.promise";
39 local logger = require "util.logger";
39 40
40 local t_insert = table.insert; 41 local t_insert = table.insert;
41 local t_concat = table.concat; 42 local t_concat = table.concat;
42 43
43 local format_number = require "util.human.units".format; 44 local format_number = require "util.human.units".format;
1587 print("HTTP requests to unknown hosts will be handled by "..default_host); 1588 print("HTTP requests to unknown hosts will be handled by "..default_host);
1588 end 1589 end
1589 return true; 1590 return true;
1590 end 1591 end
1591 1592
1593 def_env.watch = {};
1594
1595 function def_env.watch:log()
1596 local writing = false;
1597 local sink = logger.add_simple_sink(function (source, level, message)
1598 if writing then return; end
1599 writing = true;
1600 self.session.print(source, level, message);
1601 writing = false;
1602 end);
1603
1604 while self.session.is_connected() do
1605 async.sleep(3);
1606 end
1607 if not logger.remove_sink(sink) then
1608 module:log("warn", "Unable to remove watch:log() sink");
1609 end
1610 end
1611
1612
1592 def_env.debug = {}; 1613 def_env.debug = {};
1593 1614
1594 function def_env.debug:logevents(host) 1615 function def_env.debug:logevents(host)
1595 helpers.log_host_events(host); 1616 helpers.log_host_events(host);
1596 return true; 1617 return true;