changeset 899:40d5e8002b12

Disable all logs by default, activate required logs by command-line switch. To be improved when file logging is supported
author Sebastien Decugis <sdecugis@freediameter.net>
date Mon, 03 Dec 2012 21:53:16 +0100
parents c2ecce3fb928
children a7e0a7ab769c
files freeDiameterd/main.c include/freeDiameter/libfdproto.h
diffstat 2 files changed, 50 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/freeDiameterd/main.c	Mon Dec 03 21:27:19 2012 +0100
+++ b/freeDiameterd/main.c	Mon Dec 03 21:53:16 2012 +0100
@@ -48,6 +48,7 @@
 
 static char *conffile = NULL;
 static int gnutls_debug = 0;
+static int fd_msg_log_enabled = 0; /* all logs disabled by default, this field is a bitfield of enabled FD_MSG_LOG_* */
 
 /* gnutls debug */
 static void fd_gnutls_debug(int level, const char * str) {
@@ -85,6 +86,25 @@
 		gnutls_global_set_log_level (gnutls_debug);
 		TRACE_DEBUG(INFO, "Enabled GNUTLS debug at level %d", gnutls_debug);
 	}
+	
+	/* set messages logging */
+	if (fd_msg_log_enabled) {
+		if (fd_msg_log_enabled & (1 << FD_MSG_LOG_DROPPED)) {
+			CHECK_FCT( fd_msg_log_config(FD_MSG_LOG_DROPPED, FD_MSG_LOGTO_DEBUGONLY, NULL) );
+		}
+		if (fd_msg_log_enabled & (1 << FD_MSG_LOG_RECEIVED)) {
+			CHECK_FCT( fd_msg_log_config(FD_MSG_LOG_RECEIVED, FD_MSG_LOGTO_DEBUGONLY, NULL) );
+		}
+		if (fd_msg_log_enabled & (1 << FD_MSG_LOG_SENT)) {
+			CHECK_FCT( fd_msg_log_config(FD_MSG_LOG_SENT, FD_MSG_LOGTO_DEBUGONLY, NULL) );
+		}
+		if (fd_msg_log_enabled & (1 << FD_MSG_LOG_NODELIVER)) {
+			CHECK_FCT( fd_msg_log_config(FD_MSG_LOG_NODELIVER, FD_MSG_LOGTO_DEBUGONLY, NULL) );
+		}
+		if (fd_msg_log_enabled & (1 << FD_MSG_LOG_TIMING)) {
+			CHECK_FCT( fd_msg_log_config(FD_MSG_LOG_TIMING, FD_MSG_LOGTO_DEBUGONLY, NULL) );
+		}
+	}
 		
 	/* Allow SIGINT and SIGTERM from this point to terminate the application */
 	CHECK_POSIX( pthread_create(&signals_thr, NULL, catch_signals, NULL) );
@@ -148,7 +168,9 @@
 	printf( "  -h, --help             Print help and exit\n"
   		"  -V, --version          Print version and exit\n"
   		"  -c, --config=filename  Read configuration from this file instead of the \n"
-		"                           default location (" DEFAULT_CONF_PATH "/" FD_DEFAULT_CONF_FILENAME ").\n");
+		"                           default location (" DEFAULT_CONF_PATH "/" FD_DEFAULT_CONF_FILENAME ").\n"
+		"  -M, --enable_msg_log=( DROPPED | RECEIVED | SENT | NODELIVER | TIMING )\n"
+		"                         Disable logging of these messages in the output.\n");
  	printf( "\nDebug:\n"
   		"  These options are mostly useful for developers\n"
   		"  -l, --dbglocale        Set the locale for error messages\n"
@@ -174,12 +196,13 @@
 		{ "dbg_func",	required_argument, 	NULL, 'f' },
 		{ "dbg_file",	required_argument, 	NULL, 'F' },
 		{ "dbg_gnutls",	required_argument, 	NULL, 'g' },
+		{ "enable_msg_log",	optional_argument, 	NULL, 'M' },
 		{ NULL,		0, 			NULL, 0 }
 	};
 	
 	/* Loop on arguments */
 	while (1) {
-		c = getopt_long (argc, argv, "hVc:dql:", long_options, &option_index);
+		c = getopt_long (argc, argv, "hVc:dql:M:", long_options, &option_index);
 		if (c == -1) 
 			break;	/* Exit from the loop.  */
 		
@@ -207,6 +230,30 @@
 					return EINVAL;
 				}
 				break;
+				
+			case 'M':	/* disable logging of these messages */
+				if (optarg) {
+					if (!strcmp(optarg, "DROPPED")) {
+						fd_msg_log_enabled |= 1 << FD_MSG_LOG_DROPPED;
+					} else
+					if (!strcmp(optarg, "RECEIVED")) {
+						fd_msg_log_enabled |= 1 << FD_MSG_LOG_RECEIVED;
+					} else
+					if (!strcmp(optarg, "SENT")) {
+						fd_msg_log_enabled |= 1 << FD_MSG_LOG_SENT;
+					} else
+					if (!strcmp(optarg, "NODELIVER")) {
+						fd_msg_log_enabled |= 1 << FD_MSG_LOG_NODELIVER;
+					} else
+					if (!strcmp(optarg, "TIMING")) {
+						fd_msg_log_enabled |= 1 << FD_MSG_LOG_TIMING;
+					} else {
+						main_help();
+						exit(0);
+					}
+				} else {
+					fd_msg_log_enabled = -1; /* all logs enabled */
+				}
 
 			case 'd':	/* Increase verbosity of debug messages.  */
 				fd_g_debug_lvl++;
--- a/include/freeDiameter/libfdproto.h	Mon Dec 03 21:27:19 2012 +0100
+++ b/include/freeDiameter/libfdproto.h	Mon Dec 03 21:53:16 2012 +0100
@@ -2235,7 +2235,7 @@
  *   -
  */
 enum fd_msg_log_cause {
-	FD_MSG_LOG_DROPPED = 0,  /* message has been dropped by the framework */ 
+	FD_MSG_LOG_DROPPED = 1,  /* message has been dropped by the framework */ 
 	FD_MSG_LOG_RECEIVED,     /* message received from the network */ 
 	FD_MSG_LOG_SENT,         /* message sent to another peer */ 
 	FD_MSG_LOG_NODELIVER,    /* message could not be delivered to any peer */
"Welcome to our mercurial repository"