[Asterisk-code-review] logger: Console sessions will now respect logger.conf dateformat= option (asterisk[18])

George Joseph asteriskteam at digium.com
Mon Mar 22 11:18:03 CDT 2021


George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/15683 )

Change subject: logger: Console sessions will now respect logger.conf dateformat= option
......................................................................

logger: Console sessions will now respect logger.conf dateformat= option

The 'core' console (ie: asterisk -c) does read logger.conf and does
use the dateformat= option.

Whereas 'remote' consoles (ie: asterisk -r -T) does not read logger.conf
and uses a hard coded dateformat option for printing received verbose messages:
  main/logger.c: static char dateformat[256] = "%b %e %T"

This change will load logger.conf for each remote console session and
use the dateformat= option to set the per-line timestamp for verbose messages

Change-Id: I3ea10990dbd920e9f7ce8ff771bc65aa7f4ea8c1
ASTERISK-25358: #close
Reported-by: Igor Liferenko
---
A doc/CHANGES-staging/logger_dateformat.txt
M include/asterisk/logger.h
M main/asterisk.c
M main/logger.c
4 files changed, 71 insertions(+), 0 deletions(-)

Approvals:
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/doc/CHANGES-staging/logger_dateformat.txt b/doc/CHANGES-staging/logger_dateformat.txt
new file mode 100644
index 0000000..efeb118
--- /dev/null
+++ b/doc/CHANGES-staging/logger_dateformat.txt
@@ -0,0 +1,47 @@
+Subject: logger
+
+The dateformat option in logger.conf will now control the remote
+console (asterisk -r -T) timestamp format.  Previously, dateformat only
+controlled the formatting of the timestamp going to log files and the
+main console (asterisk -c) but only for non-verbose messages.
+
+Internally, Asterisk does not send the logging timestamp with verbose
+messages to console clients. It's up to the Asterisk remote consoles
+to format verbose messages.  Asterisk remote consoles previously did
+not load dateformat from logger.conf.
+
+Previously there was a non-configurable and hard-coded "%b %e %T"
+dateformat that would be used no matter what on all verbose console
+messages printed on remote consoles.
+
+Example:
+logger.conf
+ dateformat=%F %T.%3q
+
+# asterisk -rvvv -T
+[2021-03-19 09:54:19.760-0400]  Loading res_stasis_answer.so.
+[Mar 19 09:55:43]     -- Goto (dialExten,s,1)
+
+Given the following example configuration in logger.conf, Asterisk log
+files and the console, will log verbose messages using the given
+timestamp.  Now ensuring that all remote console messages are logged
+with the same dateformat as other log streams.
+
+---
+[general]
+dateformat=%F %T.%3q
+
+[logfiles]
+console  => notice,warning,error,verbose
+full     => notice,warning,error,debug,verbose
+---
+
+Now we have a globally-defined dateformat that will be used
+consistently across the Asterisk main console, remote consoles, and
+log files.
+
+Now we have consistent logging:
+
+# asterisk -rvvv -T
+[2021-03-19 09:54:19.760-0400]  Loading res_stasis_answer.so.
+[2021-03-19 09:55:43.920-0400]     -- Goto (dialExten,s,1)
diff --git a/include/asterisk/logger.h b/include/asterisk/logger.h
index 6ab55f7..d823ed4 100644
--- a/include/asterisk/logger.h
+++ b/include/asterisk/logger.h
@@ -621,6 +621,11 @@
  */
 unsigned int ast_trace_get_by_module(const char *module);
 
+/*!
+ * \brief load logger.conf configuration for console socket connections
+ */
+void ast_init_logger_for_socket_console(void);
+
 #define TRACE_ATLEAST(level) \
 	(option_trace >= (level) \
 		|| (ast_opt_trace_module \
diff --git a/main/asterisk.c b/main/asterisk.c
index b42e596..f53c781 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -3254,6 +3254,8 @@
 	}
 
 	ast_verbose("Connected to Asterisk %s currently running on %s (pid = %d)\n", version, hostname, pid);
+	ast_init_logger_for_socket_console();
+
 	remotehostname = hostname;
 	if (el_hist == NULL || el == NULL)
 		ast_el_initialize();
diff --git a/main/logger.c b/main/logger.c
index 5562bf3..457a6fb 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -679,6 +679,23 @@
 	return chan;
 }
 
+void ast_init_logger_for_socket_console(void)
+{
+	struct ast_config *cfg;
+	const char *s;
+	struct ast_flags config_flags = { 0 };
+
+	if (!(cfg = ast_config_load2("logger.conf", "logger", config_flags)) || cfg == CONFIG_STATUS_FILEINVALID) {
+		return;
+	}
+
+	if ((s = ast_variable_retrieve(cfg, "general", "dateformat"))) {
+		ast_copy_string(dateformat, s, sizeof(dateformat));
+	}
+
+	ast_config_destroy(cfg);
+}
+
 /*!
  * \brief Read config, setup channels.
  * \param altconf Alternate configuration file to read.

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15683
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I3ea10990dbd920e9f7ce8ff771bc65aa7f4ea8c1
Gerrit-Change-Number: 15683
Gerrit-PatchSet: 2
Gerrit-Owner: Mark Murawski <markm at intellasoft.net>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210322/5da5c4c6/attachment.html>


More information about the asterisk-code-review mailing list