Hi all, I've got a patch here to fix #868 (showing log file locations in prosodyctl about). Unfortunately it seems it doesn't actually work, because it's always printing out "console", which seems to indicate that I'm just reading the default config. Is there anything I'm doing that's obviously wrong here?
Cheers, William -- You received this message because you are subscribed to the Google Groups "prosody-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/prosody-dev/D9H4L757GNHI.8ROZ7GMZ9JOJ%40wbrawner.com.
# HG changeset patch # User William Brawner <[email protected]> # Date 1745696215 21600 # Sat Apr 26 13:36:55 2025 -0600 # Node ID 8e91868c19a26fc66479c2ed6ec9a59b1a113d23 # Parent 488483e1d915ecc17dde510c09c1a155ea19c908 prosodyctl about: Print log paths if configured (fixes #868) diff -r 488483e1d915 -r 8e91868c19a2 prosodyctl --- a/prosodyctl Fri Apr 18 12:25:38 2025 +0100 +++ b/prosodyctl Sat Apr 26 13:36:55 2025 -0600 @@ -496,6 +496,15 @@ print(name..":"..string.rep(" ", longest_name-#name), version); end print(""); + local logconfig = require "util.prosodyctl.logconfig"; + local log_paths = logconfig.paths(configmanager.get("*", "log")); + if #log_paths > 0 then + print("# Logging"); + for _, path in pairs(log_paths) do + print(" " .. path); + end + print(""); + end end function commands.version(arg) diff -r 488483e1d915 -r 8e91868c19a2 spec/util_prosodyctl_logconfig_spec.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spec/util_prosodyctl_logconfig_spec.lua Sat Apr 26 13:36:55 2025 -0600 @@ -0,0 +1,46 @@ +local logconfig = require "util.prosodyctl.logconfig"; + +describe("util.prosodyctl.logconfig", function() + it("parses default log config", function() + local config = { { to = "console" } }; + local paths = logconfig.paths(config); + assert.are.same( + { + "console", + }, + paths, + "Parsing default log config" + ); + end); + + it("parses simple log config", function() + local config = { info = "prosody.log", error = "prosody.err" }; + local paths = logconfig.paths(config); + table.sort(paths) -- needed to avoid flakiness due to table order + assert.are.same( + { + "prosody.err", + "prosody.log", + }, + paths, + "Parsing simple log config" + ); + end); + + it("parses advanced log config", function() + -- example from https://prosody.im/doc/advanced_logging + local config = { + { levels = { min = "error" }, to = "file", filename = "/var/log/prosody/prosody.err" }; + { levels = { min = "info" }, to = "file", filename = "/var/log/prosody/prosody.log" }; + }; + local paths = logconfig.paths(config); + assert.are.same( + { + "/var/log/prosody/prosody.err", + "/var/log/prosody/prosody.log", + }, + paths, + "Parsing advanced log config" + ); + end); +end); diff -r 488483e1d915 -r 8e91868c19a2 util/prosodyctl/logconfig.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/util/prosodyctl/logconfig.lua Sat Apr 26 13:36:55 2025 -0600 @@ -0,0 +1,25 @@ +local logconfig = {} + +local function path_from_table(config) + if config["to"] == "file" then + return config["filename"]; + else + return config["to"]; + end +end + +function logconfig.paths(config) + local paths = {}; + + for _, item in pairs(config) do + if type(item) == "table" then + paths[#paths + 1] = path_from_table(item); + elseif type(item) == "string" then + paths[#paths + 1] = item; + end + end + + return paths; +end + +return logconfig;
