[Asterisk-code-review] logger: Add custom logging level (asterisk[master])

N A asteriskteam at digium.com
Sun Jul 25 17:20:59 CDT 2021


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/16222 )


Change subject: logger: Add custom logging level
......................................................................

logger: Add custom logging level

Adds a custom logging level to which Asterisk itself
never logs anything, which may be used for logging
custom events to an Asterisk log file.

ASTERISK-29529

Change-Id: If082703cf81a436ae5a565c75225fa8c0554b702
---
M apps/app_verbose.c
M configs/samples/logger.conf.sample
A doc/CHANGES-staging/logger.txt
M include/asterisk/logger.h
M main/logger.c
5 files changed, 26 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/22/16222/1

diff --git a/apps/app_verbose.c b/apps/app_verbose.c
index 5b78e18..8a60514 100644
--- a/apps/app_verbose.c
+++ b/apps/app_verbose.c
@@ -61,7 +61,7 @@
 		<syntax>
 			<parameter name="level" required="true">
 				<para>Level must be one of <literal>ERROR</literal>, <literal>WARNING</literal>, <literal>NOTICE</literal>,
-				<literal>DEBUG</literal>, <literal>VERBOSE</literal> or <literal>DTMF</literal>.</para>
+				<literal>DEBUG</literal>, <literal>VERBOSE</literal>, <literal>DTMF</literal>, or <literal>CUSTOM</literal>.</para>
 			</parameter>
 			<parameter name="message" required="true">
 				<para>Output text message.</para>
@@ -134,11 +134,15 @@
 		lnum = __LOG_VERBOSE;
 	} else if (!strcasecmp(args.level, "DTMF")) {
 		lnum = __LOG_DTMF;
+	} else if (!strcasecmp(args.level, "CUSTOM")) {
+		lnum = __LOG_CUSTOM;
 	} else {
 		ast_log(LOG_ERROR, "Unknown log level: '%s'\n", args.level);
 	}
 
-	if (lnum > -1) {
+	if (lnum == __LOG_CUSTOM) {
+		ast_log(lnum, "", ast_channel_priority(chan), "", "%s\n", args.msg);
+	} else if (lnum > -1) {
 		snprintf(context, sizeof(context), "@ %s", ast_channel_context(chan));
 		snprintf(extension, sizeof(extension), "Ext. %s", ast_channel_exten(chan));
 
diff --git a/configs/samples/logger.conf.sample b/configs/samples/logger.conf.sample
index 295b863..df56693 100644
--- a/configs/samples/logger.conf.sample
+++ b/configs/samples/logger.conf.sample
@@ -128,6 +128,7 @@
 ;    error
 ;    verbose(<level>)
 ;    dtmf
+;    custom
 ;    fax
 ;    security
 ;
@@ -168,7 +169,7 @@
 console => notice,warning,error
 ;console => notice,warning,error,debug
 messages.log => notice,warning,error
-;full.log => notice,warning,error,debug,verbose,dtmf,fax
+;full.log => notice,warning,error,debug,verbose,dtmf,custom,fax
 ;
 ;full-json.log => [json]debug,verbose,notice,warning,error,dtmf,fax
 ;
diff --git a/doc/CHANGES-staging/logger.txt b/doc/CHANGES-staging/logger.txt
new file mode 100644
index 0000000..ecb6adc
--- /dev/null
+++ b/doc/CHANGES-staging/logger.txt
@@ -0,0 +1,5 @@
+Subject: logger
+
+Adds a custom logging level that may be used
+for custom logging, that is, a level to which
+Asterisk itself never logs anything.
diff --git a/include/asterisk/logger.h b/include/asterisk/logger.h
index d823ed4..14916f8 100644
--- a/include/asterisk/logger.h
+++ b/include/asterisk/logger.h
@@ -311,6 +311,17 @@
 #endif
 #define AST_LOG_DTMF    __LOG_DTMF, _A_
 
+#ifdef LOG_CUSTOM
+#undef LOG_CUSTOM
+#endif
+#define __LOG_CUSTOM  7
+#define LOG_CUSTOM    __LOG_CUSTOM, _A_
+
+#ifdef AST_LOG_CUSTOM
+#undef AST_LOG_CUSTOM
+#endif
+#define AST_LOG_CUSTOM    __LOG_CUSTOM, _A_
+
 #define NUMLOGLEVELS 32
 
 /*!
diff --git a/main/logger.c b/main/logger.c
index 457a6fb..f171963 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -209,6 +209,7 @@
 	"ERROR",
 	"VERBOSE",
 	"DTMF",
+	"CUSTOM",
 };
 
 /*! \brief Colors used in the console for logging */
@@ -220,7 +221,7 @@
 	COLOR_RED,
 	COLOR_GREEN,
 	COLOR_BRGREEN,
-	0,
+	COLOR_MAGENTA,
 	0,
 	0,
 	0,

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: If082703cf81a436ae5a565c75225fa8c0554b702
Gerrit-Change-Number: 16222
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210725/9f043773/attachment.html>


More information about the asterisk-code-review mailing list