Wrote a patch today trying to deal with issue 868. (Rookie effort alert)

It seems to me that it is working good enough as a first iteration of the 
issue at least. When I run "prosodyctl about" the output prints the 
locations of log files, specified in the "prosody.cfg.lua" file.

It is going through luacheck. Also read the coding style section at the 
documentation, I think it is respecting all the rules, as far as i can see.

It might be more verbose than it needs to be though. Here are my 
considerations when i wrote it:


   - The code checks "prosody.cfg.lua" for log files paths
   - Only paths inside the log section are collected
   - I am specifically looking for files with the ".log" extension
   - Log locations will always be in the log section. I'm considering that 
   section starts with the string "log = {" and ends with a "}"
   - A log path will always be enclosed by double quotes 
   - I ignore strings that start with a comment, inside the log section. 
   - There can be valid strings that have comments at the end. 
   - The user can write the complete path or just type the name of the log 
   file

I detected at least one case where the code is malfunctioning. Consider 
that I have this string in the log section:

         anystring = "anything.anything" -- I am starting a neat comment 
and suddenly "a_file_here_for_some_reason.log"

The "prosodyctl about" command will also print "anything.anything" in this 
case. I noticed this kind of problem just when i was about to send this 
patch. Since I suspect the code is getting a bit verbose, and I'm not sure 
If these kind of situations need to be addressed I decided to post the 
patch first, just to collect some feedback, and then adjust it as necessary.

Thanks everyone for the patience!

Cheers,

João Duarte

-- 
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/prosody-dev.
For more options, visit https://groups.google.com/d/optout.
# HG changeset patch
# User João Duarte <[email protected]>
# Date 1554845976 25200
#      Tue Apr 09 14:39:36 2019 -0700
# Node ID 1b4b94da77e47abcd454a5278866202b633eaffc
# Parent  581188752c01fef3c4b8239e142c5d733557d902
Dealing with issue 863. Output of 'prosodyctl about' now includes log files' locations.

diff -r 581188752c01 -r 1b4b94da77e4 prosodyctl
--- a/prosodyctl	Mon Apr 08 14:08:58 2019 -0700
+++ b/prosodyctl	Tue Apr 09 14:39:36 2019 -0700
@@ -363,6 +363,22 @@
 				.."\n  ";
 		end)));
 	print("");
+	print("# Paths to log files");
+	local inside_log_section = false;
+	for line in io.lines("prosody.cfg.lua") do
+		if line ==  "log = {" then
+			 inside_log_section = true;
+		elseif line == "}" and inside_log_section then
+			 inside_log_section = false;
+		end
+		if string.match(line, "%.log") and inside_log_section then
+			-- Only names inside double quotes are considered valid. Lines starting with comments are ignored. Lines that have comments at the end are valid
+			if string.match(line, "\"(.-)\"") and (line:gsub('[%s]', '')):find("^%-%-") == nil then
+				print("  "..relpath(pwd, string.match(line, "\"(.-)\"")));
+			end
+		end
+	end
+	print("");
 	local have_pposix, pposix = pcall(require, "util.pposix");
 	if have_pposix and pposix.uname then
 		print("# Operating system");

Reply via email to