[icinga-checkins] icinga.org: icinga-core/mfriedrich/core: revamp logging somewhat ( Andreas Ericsson)

git at icinga.org git at icinga.org
Wed May 12 18:57:42 CEST 2010


Module: icinga-core
Branch: mfriedrich/core
Commit: abc17fbee8dd27a1c965cc8da9384c7f2e757b18
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=abc17fbee8dd27a1c965cc8da9384c7f2e757b18

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Wed May 12 17:00:21 2010 +0200

revamp logging somewhat (Andreas Ericsson)

[--snip--]
base/nagios.c was the last caller of write_to_logs_and_console().
Having gotten rid of that callsite we can revamp logging.c and
make write_to_logs_and_console(), write_to_console() and
write_to_all_logs_with_timestamp() static functions. This will
let the linker optimize them slightly better. We also change them
to be void, since they always returned "OK" earlier anyway.
[--snip--]

this is true for base/icinga.c too, patch modified and applied for Icinga, thanks.

fixes #393

---

 Changelog        |    1 +
 base/logging.c   |   61 ++++++++++++++++++++---------------------------------
 include/icinga.h |    3 --
 3 files changed, 24 insertions(+), 41 deletions(-)

diff --git a/Changelog b/Changelog
index f9c41d4..0c17270 100644
--- a/Changelog
+++ b/Changelog
@@ -24,6 +24,7 @@ FIXES
 * core: move cgiutils.h compile time option macros to config.h (Andreas Ericsson)
 * core: icinga.c: remove conditional main() configuration (Andreas Ericsson)
 * core: icinga.c: replace asprintf() + write_to_logs_and_console() with logit() (Andreas Ericsson)
+* core: revamp logging somewhat (Andreas Ericsson)
 
 * idoutils: Host DB inserts use string 'NULL\n' instead of NULL (William Preston)
 * idoutils: ndo2db_get_object_id fails to return existing IDs (William Preston)
diff --git a/base/logging.c b/base/logging.c
index 6bd8902..8adb0a4 100644
--- a/base/logging.c
+++ b/base/logging.c
@@ -68,29 +68,16 @@ FILE            *debug_file_fp=NULL;
 /************************ LOGGING FUNCTIONS ***********************/
 /******************************************************************/
 
-/* This needs to be a function rather than a macro. C99 introduces
- * variadic macros, but we need to support compilers that aren't
- * C99 compliant in that area, so a function it is. Hopefully most
- * compilers will just optimize this call away, as it's easily
- * recognizable as not doing anything at all */
-void logit(int data_type, int display, const char *fmt, ...){
-	int len;
-	va_list ap;
-	char *buffer=NULL;
-
-	va_start(ap,fmt);
-	if((len=vasprintf(&buffer,fmt,ap))>0){
-		write_to_logs_and_console(buffer,data_type,display);
-		free(buffer);
-		}
-	va_end(ap);
-
-	return;
-	}
+/* write something to the console */
+static void write_to_console(char *buffer){
+        /* should we print to the console? */
+        if(daemon_mode==FALSE)
+                printf("%s\n",buffer);
+}
 
 
 /* write something to the log file, syslog, and possibly the console */
-int write_to_logs_and_console(char *buffer, unsigned long data_type, int display){
+static void write_to_logs_and_console(char *buffer, unsigned long data_type, int display){
 	register int len=0;
 	register int x=0;
 
@@ -101,7 +88,7 @@ int write_to_logs_and_console(char *buffer, unsigned long data_type, int display
 			buffer[x]='\x0';
 		else
 			break;
-	        }
+	}
 
 	/* write messages to the logs */
 	write_to_all_logs(buffer,data_type);
@@ -111,24 +98,24 @@ int write_to_logs_and_console(char *buffer, unsigned long data_type, int display
 
 		/* don't display warnings if we're just testing scheduling */
 		if(test_scheduling==TRUE && data_type==NSLOG_VERIFICATION_WARNING)
-			return OK;
+			return;
 
 		write_to_console(buffer);
-	        }
-
-	return OK;
-        }
-
-
-/* write something to the console */
-int write_to_console(char *buffer){
+	}
+}
 
-	/* should we print to the console? */
-	if(daemon_mode==FALSE)
-		printf("%s\n",buffer);
 
-	return OK;
+/* The main logging function */
+void logit(int data_type, int display, const char *fmt, ...){
+        va_list ap;
+        char *buffer=NULL;
+        va_start(ap,fmt);
+        if (vasprintf(&buffer, fmt, ap) > 0) {
+                write_to_logs_and_console(buffer,data_type,display);
+                free(buffer);
         }
+        va_end(ap);
+}
 
 
 /* write something to the log file and syslog facility */
@@ -145,16 +132,14 @@ int write_to_all_logs(char *buffer, unsigned long data_type){
 
 
 /* write something to the log file and syslog facility */
-int write_to_all_logs_with_timestamp(char *buffer, unsigned long data_type, time_t *timestamp){
+static void write_to_all_logs_with_timestamp(char *buffer, unsigned long data_type, time_t *timestamp){
 
 	/* write to syslog */
 	write_to_syslog(buffer,data_type);
 
 	/* write to main log */
 	write_to_log(buffer,data_type,timestamp);
-
-	return OK;
-        }
+}
 
 
 /* write something to the icinga log file */
diff --git a/include/icinga.h b/include/icinga.h
index d2f7856..1a4e277 100644
--- a/include/icinga.h
+++ b/include/icinga.h
@@ -613,10 +613,7 @@ time_t get_next_service_notification_time(service *,time_t);			/* calculates nex
 /**** Logging Functions ****/
 void logit(int,int,const char *, ...)
 	__attribute__((__format__(__printf__, 3, 4)));
-int write_to_logs_and_console(char *,unsigned long,int);	/* writes a string to screen and logs */
-int write_to_console(char *);                           /* writes a string to screen */
 int write_to_all_logs(char *,unsigned long);            /* writes a string to main log file and syslog facility */
-int write_to_all_logs_with_timestamp(char *,unsigned long,time_t *);	/* writes a string to main log file and syslog facility */
 int write_to_log(char *,unsigned long,time_t *);       	/* write a string to the main log file */
 int write_to_syslog(char *,unsigned long);             	/* write a string to the syslog facility */
 int log_service_event(service *);			/* logs a service event */





More information about the icinga-checkins mailing list