Module: sip-router
Branch: master
Commit: 43181b6bc1c50b8456c4c4b5bceda5a99ef0c417
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=43181b6…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Thu Feb 26 23:14:12 2009 +0000
log/dbg: level is not limited anymore
The recent changes to LOG() added a new limitation: the log level
was restricted to one of the L_ macros. Using another level (e.g.
L_DBG+1) would trigger an assert(). Now any level is allowed. If
the level is not among the defined range (L_ALERT - L_DBG), the
prefix will be skipped (e.g. "DBG") and the syslog level will be
set to either the L_ALERT or the L_DBG one. This fixes problems
with log() from the script, or when using a very high debug level
and something like memdbg=7.
---
cfg.y | 3 +-
dprint.h | 76 ++++++++++++++++++++++++++++++++++++++++++++-----------------
2 files changed, 57 insertions(+), 22 deletions(-)
diff --git a/cfg.y b/cfg.y
index 8408e1d..8d56371 100644
--- a/cfg.y
+++ b/cfg.y
@@ -2207,7 +2207,8 @@ cmd:
| RETURN NUMBER {$$=mk_action(DROP_T, 2, NUMBER_ST, (void*)$2, NUMBER_ST,
(void*)RETURN_R_F);}
| RETURN RETCODE {$$=mk_action(DROP_T, 2, RETCODE_ST, 0, NUMBER_ST,
(void*)RETURN_R_F);}
| BREAK {$$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)RETURN_R_F); }
- | LOG_TOK LPAREN STRING RPAREN {$$=mk_action(LOG_T, 2, NUMBER_ST, (void*)4, STRING_ST,
$3); }
+ | LOG_TOK LPAREN STRING RPAREN {$$=mk_action(LOG_T, 2, NUMBER_ST,
+ (void*)(L_DBG+1), STRING_ST, $3); }
| LOG_TOK LPAREN NUMBER COMMA STRING RPAREN {$$=mk_action(LOG_T, 2, NUMBER_ST,
(void*)$3, STRING_ST, $5); }
| LOG_TOK error { $$=0; yyerror("missing '(' or ')' ?"); }
| LOG_TOK LPAREN error RPAREN { $$=0; yyerror("bad log argument"); }
diff --git a/dprint.h b/dprint.h
index 6a9806d..6b66427 100644
--- a/dprint.h
+++ b/dprint.h
@@ -32,6 +32,7 @@
#include <syslog.h>
#include <stdio.h> /* stderr, fprintf() */
+#include "compiler_opt.h"
#include "cfg_core.h"
@@ -144,19 +145,36 @@ int log_facility_fixup(void *handle, str *name, void **val);
# ifdef __SUNPRO_C
# define LOG_(level, prefix, fmt, ...) \
do { \
- if (cfg_get(core, core_cfg, debug) >= (level) && \
- DPRINT_NON_CRIT) { \
+ if (unlikely(cfg_get(core, core_cfg, debug) >= (level) && \
+ DPRINT_NON_CRIT)) { \
DPRINT_CRIT_ENTER; \
- assert(((level) >= L_ALERT) && ((level) <= L_DBG)); \
- if (log_stderr) { \
- fprintf(stderr, "%2d(%d) %s: %s" fmt, \
- process_no, my_pid(), LOG_LEVEL2NAME(level),\
- (prefix), __VA_ARGS__); \
+ if (likely(((level) >= L_ALERT) && ((level) <= L_DBG))){ \
+ if (unlikely(log_stderr)) { \
+ fprintf(stderr, "%2d(%d) %s: %s" fmt, \
+ process_no, my_pid(), \
+ LOG_LEVEL2NAME(level), (prefix), \
+ __VA_ARGS__); \
+ } else { \
+ syslog(LOG2SYSLOG_LEVEL(level) | \
+ cfg_get(core, core_cfg, log_facility),\
+ "%s: %s" fmt, LOG_LEVEL2NAME(level),\
+ (prefix), __VA_ARGS__); \
+ } \
} else { \
- syslog(LOG2SYSLOG_LEVEL(level) | \
- cfg_get(core, core_cfg, log_facility), \
- "%s: %s" fmt, LOG_LEVEL2NAME(level),\
- (prefix), __VA_ARGS__); \
+ if (log_stderr) { \
+ fprintf(stderr, "%2d(%d) %s" fmt, \
+ process_no, my_pid(), \
+ (prefix), __VA_ARGS__); \
+ } else { \
+ if ((level)<L_ALERT) \
+ syslog(LOG2SYSLOG_LEVEL(L_ALERT) | \
+ cfg_get(core, core_cfg, log_facility),\
+ "%s" fmt, (prefix), __VA_ARGS__); \
+ else \
+ syslog(LOG2SYSLOG_LEVEL(L_DBG) | \
+ cfg_get(core, core_cfg, log_facility),\
+ "%s" fmt, (prefix), __VA_ARGS__); \
+ } \
} \
DPRINT_CRIT_EXIT; \
} \
@@ -164,22 +182,38 @@ int log_facility_fixup(void *handle, str *name, void **val);
# define LOG(level, fmt, ...) LOG_((level), LOC_INFO, fmt, __VA_ARGS__)
-# else
+# else /* ! __SUNPRO_C */
# define LOG_(level, prefix, fmt, args...) \
do { \
if (cfg_get(core, core_cfg, debug) >= (level) && \
DPRINT_NON_CRIT) { \
DPRINT_CRIT_ENTER; \
- assert(((level) >= L_ALERT) && ((level) <= L_DBG)); \
- if (log_stderr) { \
- fprintf(stderr, "%2d(%d) %s: %s" fmt, \
- process_no, my_pid(), LOG_LEVEL2NAME(level),\
- (prefix), ## args); \
- } else { \
- syslog(LOG2SYSLOG_LEVEL(level) |\
+ if (likely(((level) >= L_ALERT) && ((level) <= L_DBG))){ \
+ if (unlikely(log_stderr)) { \
+ fprintf(stderr, "%2d(%d) %s: %s" fmt, \
+ process_no, my_pid(), \
+ LOG_LEVEL2NAME(level),(prefix), ## args);\
+ } else { \
+ syslog(LOG2SYSLOG_LEVEL(level) |\
cfg_get(core, core_cfg, log_facility), \
- "%s: %s" fmt, LOG_LEVEL2NAME(level),\
- (prefix), ## args); \
+ "%s: %s" fmt, LOG_LEVEL2NAME(level),\
+ (prefix), ## args); \
+ } \
+ } else { \
+ if (log_stderr) { \
+ fprintf(stderr, "%2d(%d) %s" fmt, \
+ process_no, my_pid(), \
+ (prefix), ## args); \
+ } else { \
+ if ((level)<L_ALERT) \
+ syslog(LOG2SYSLOG_LEVEL(L_ALERT) | \
+ cfg_get(core, core_cfg, log_facility),\
+ "%s" fmt, (prefix), ## args); \
+ else \
+ syslog(LOG2SYSLOG_LEVEL(L_DBG) | \
+ cfg_get(core, core_cfg, log_facility),\
+ "%s" fmt, (prefix), ## args); \
+ } \
} \
DPRINT_CRIT_EXIT; \
} \