[Freeciv-Dev] freelog and LOG_DEBUG
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
I noticed most freelog(LOG_DEBUG, ... instances are like:
if (0) freelog(LOG_DEBUG, ...);
You don't get any debug information when you define -d 2.
There is also situations like:
if(0 && some_func(args)) freelog(LOG_DEBUG, ...);
This is generally bad because you have to be sure there is no
side effects at some_func. Or else if you enable that particular
debugging message your code acts differently.
Could you consider following patch, please?
If the patch is ok, I can submit actual if(0) eliminations.
ChangeLog entry.
------------------------------------------------------------------------
1999-05-20 Markus Linnala <maage@xxxxxxxxx>
* common/log.(c|h> (freelog): change to real_freelog
* common/log.h: If DEBUG is not defined, don't compile
in logging with level LOG_DEBUG.
------------------------------------------------------------------------
--
//Markus
------------------------------------------------------------------------
diff --unified --recursive --new-file --exclude-from=.diffignore
freeciv/common/log.c freeciv-maage/common/log.c
--- freeciv/common/log.c Tue Apr 27 15:17:52 1999
+++ freeciv-maage/common/log.c Wed May 19 23:31:32 1999
@@ -63,7 +63,7 @@
"last message repeated ..." at some later time.
Calls log_callback if non-null, else prints to stderr.
**************************************************************************/
-int freelog(int level, char *message, ...)
+int real_freelog(int level, char *message, ...)
{
static char bufbuf[2][512];
char buf[512];
diff --unified --recursive --new-file --exclude-from=.diffignore
freeciv/common/log.h freeciv-maage/common/log.h
--- freeciv/common/log.h Tue Apr 27 15:17:53 1999
+++ freeciv-maage/common/log.h Wed May 19 23:57:44 1999
@@ -14,6 +14,7 @@
#define FC__LOG_H
#include "attribute.h"
+#include <stdarg.h>
#define LOG_FATAL 0
#define LOG_NORMAL 1
@@ -28,7 +29,26 @@
void log_init(char *filename, int initial_level, log_callback_fn callback);
void log_set_level(int level);
-int freelog(int level, char *message, ...)
+int real_freelog(int level, char *message, ...)
fc__attribute((format (printf, 2, 3)));
+
+#ifdef __GNUC__
+#ifdef DEBUG
+#define freelog(level, args...) real_freelog((level), ##args)
+#else /* DEBUG */
+#define freelog(level, args...) do { if((level) != LOG_DEBUG) {
real_freelog((level),##args); } } while(0);
+#endif /* DEBUG */
+#else /* __GNUC__ */
+inline static void freelog (int level, char *message, ...)
+{
+ va_list args;
+#ifndef DEBUG
+ if (level == LOG_DEBUG) return;
+#endif /* DEBUG */
+ va_start (args, message);
+ real_freelog(level, message, args);
+ va_end (args);
+}
+#endif /* __GNUC__ */
#endif
- [Freeciv-Dev] freelog and LOG_DEBUG,
Markus Linnala <=
|
|