Merge commit 'origin/ser_core_cvs'
[sip-router] / dprint.h
index 083bd2e..a4d1deb 100644 (file)
--- a/dprint.h
+++ b/dprint.h
 /*
  * Log levels
  */
-#define L_ALERT                -3
-#define L_CRIT         -2
+#define L_ALERT                -4
+#define L_CRIT2                -3  /* like L_CRIT, but not used for BUGs */
+#define L_CRIT         -2  /* used only for BUG */
 #define L_ERR          -1
 #define L_WARN         0
 #define L_NOTICE       1
 #define L_INFO         2
 #define L_DBG          3
 
+/* This is the facility value used to indicate that the caller of the macro
+ * did not override the facility. Value 0 (the defaul) is LOG_KERN on Linux
+ */
+#define DEFAULT_FACILITY 0
+
 #define LOG_LEVEL2NAME(level)  (log_level_info[(level) - (L_ALERT)].name)
 #define LOG2SYSLOG_LEVEL(level) \
        (log_level_info[(level) - (L_ALERT)].syslog_level)
@@ -100,6 +106,7 @@ struct log_level_info {
        int syslog_level;
 };
 
+#define is_printable(level) (cfg_get(core, core_cfg, debug)>=(level))
 extern struct log_level_info log_level_info[];
 
 #ifndef NO_SIG_DEBUG
@@ -123,11 +130,13 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
 #ifdef NO_LOG
 
 #      ifdef __SUNPRO_C
-#              define LOG_(level, prefix, fmt, ...)
+#              define LOG_(facility, level, prefix, fmt, ...)
 #              define LOG(level, fmt, ...)
+#              define LOG_FC(facility, level, fmt, ...)
 #      else
-#              define LOG_(level, prefix, fmt, args...)
+#              define LOG_(facility, level, prefix, fmt, args...)
 #              define LOG(level, fmt, args...)
+#              define LOG_FC(facility, level, fmt, args...)
 #      endif
 
 #else
@@ -143,7 +152,7 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
 #      endif
 
 #      ifdef __SUNPRO_C
-#              define LOG_(level, prefix, fmt, ...) \
+#              define LOG_(facility, level, prefix, fmt, ...) \
                        do { \
                                if (unlikely(cfg_get(core, core_cfg, debug) >= (level) && \
                                                DPRINT_NON_CRIT)) { \
@@ -156,7 +165,9 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
                                                                        __VA_ARGS__); \
                                                } else { \
                                                        syslog(LOG2SYSLOG_LEVEL(level) | \
-                                                                       cfg_get(core, core_cfg, log_facility),\
+                                                                  (((facility) != DEFAULT_FACILITY) ? \
+                                                                       (facility) : \
+                                                                       cfg_get(core, core_cfg, log_facility)), \
                                                                        "%s: %s" fmt, LOG_LEVEL2NAME(level),\
                                                                        (prefix), __VA_ARGS__); \
                                                } \
@@ -168,22 +179,29 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
                                                } else { \
                                                        if ((level)<L_ALERT) \
                                                                syslog(LOG2SYSLOG_LEVEL(L_ALERT) | \
-                                                                               cfg_get(core, core_cfg, log_facility),\
-                                                                               "%s" fmt, (prefix), __VA_ARGS__); \
+                                                                          (((facility) != DEFAULT_FACILITY) ? \
+                                                                               (facility) : \
+                                                                               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__); \
+                                                                          (((facility) != DEFAULT_FACILITY) ? \
+                                                                               (facility) : \
+                                                                               cfg_get(core, core_cfg, log_facility)),\
+                                                                          "%s" fmt, (prefix), __VA_ARGS__); \
                                                } \
                                        } \
                                        DPRINT_CRIT_EXIT; \
                                } \
                        } while(0)
                        
-#              define LOG(level, fmt, ...)  LOG_((level), LOC_INFO, fmt, __VA_ARGS__)
+#              define LOG(level, fmt, ...) \
+       LOG_(DEFAULT_FACILITY, (level), LOC_INFO, fmt, __VA_ARGS__)
+#              define LOG_FC(facility, level, fmt, ...) \
+       LOG_((facility), (level), LOC_INFO, fmt, __VA_ARGS__)
 
 #      else /* ! __SUNPRO_C */
-#              define LOG_(level, prefix, fmt, args...) \
+#              define LOG_(facility, level, prefix, fmt, args...) \
                        do { \
                                if (cfg_get(core, core_cfg, debug) >= (level) && \
                                                DPRINT_NON_CRIT) { \
@@ -195,7 +213,9 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
                                                                        LOG_LEVEL2NAME(level),(prefix), ## args);\
                                                } else { \
                                                        syslog(LOG2SYSLOG_LEVEL(level) |\
-                                                                       cfg_get(core, core_cfg, log_facility), \
+                                                                  (((facility) != DEFAULT_FACILITY) ? \
+                                                                       (facility) : \
+                                                                       cfg_get(core, core_cfg, log_facility)), \
                                                                        "%s: %s" fmt, LOG_LEVEL2NAME(level),\
                                                                        (prefix), ## args); \
                                                } \
@@ -207,11 +227,15 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
                                                } else { \
                                                        if ((level)<L_ALERT) \
                                                                syslog(LOG2SYSLOG_LEVEL(L_ALERT) | \
-                                                                               cfg_get(core, core_cfg, log_facility),\
+                                                                          (((facility) != DEFAULT_FACILITY) ? \
+                                                                               (facility) : \
+                                                                               cfg_get(core, core_cfg, log_facility)),\
                                                                                "%s" fmt, (prefix), ## args); \
                                                        else \
                                                                syslog(LOG2SYSLOG_LEVEL(L_DBG) | \
-                                                                               cfg_get(core, core_cfg, log_facility),\
+                                                                          (((facility) != DEFAULT_FACILITY) ? \
+                                                                               (facility) : \
+                                                                               cfg_get(core, core_cfg, log_facility)),\
                                                                                "%s" fmt, (prefix), ## args); \
                                                } \
                                        } \
@@ -219,7 +243,10 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
                                } \
                        } while(0)
                        
-#              define LOG(level, fmt, args...)  LOG_((level), LOC_INFO, fmt, ## args)
+#              define LOG(level, fmt, args...) \
+       LOG_(DEFAULT_FACILITY, (level), LOC_INFO, fmt, ## args)
+#              define LOG_FC(facility, level, fmt, args...) \
+       LOG_((facility), (level), LOC_INFO, fmt, ## args)
                
 #      endif /* __SUNPRO_C */
 #endif /* NO_LOG */
@@ -235,6 +262,7 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
 #      define WARN(...)   LOG(L_WARN,   __VA_ARGS__)
 #      define NOTICE(...) LOG(L_NOTICE, __VA_ARGS__)
 #      define INFO(...)   LOG(L_INFO,   __VA_ARGS__)
+#      define CRIT(...)    LOG(L_CRIT2,   __VA_ARGS__)
 
 #      ifdef NO_DEBUG
 #              define DBG(...)
@@ -244,14 +272,15 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
 
 /* obsolete, do not use */
 #      define DEBUG(...) DBG(__VA_ARGS__)
-               
-#else
+
+#else /* ! __SUNPRO_C */
 #      define ALERT(fmt, args...)  LOG(L_ALERT,  fmt, ## args)
 #      define BUG(fmt, args...)    LOG(L_CRIT,   fmt, ## args)
 #      define ERR(fmt, args...)    LOG(L_ERR,    fmt, ## args)
 #      define WARN(fmt, args...)   LOG(L_WARN,   fmt, ## args)
 #      define NOTICE(fmt, args...) LOG(L_NOTICE, fmt, ## args)
 #      define INFO(fmt, args...)   LOG(L_INFO,   fmt, ## args)
+#      define CRIT(fmt, args...)   LOG(L_CRIT2,   fmt, ## args)
 
 #      ifdef NO_DEBUG
 #              define DBG(fmt, args...)
@@ -265,4 +294,16 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val);
 #endif /* __SUNPRO_C */
 
 
+/* kamailio/openser compatibility */
+
+#define LM_GEN1 LOG
+#define LM_GEN2 LOG_FC
+#define LM_ALERT ALERT
+#define LM_CRIT  CRIT
+#define LM_ERR ERR
+#define LM_WARN WARN
+#define LM_NOTICE NOTICE
+#define LM_INFO INFO
+#define LM_DBG DEBUG
+
 #endif /* !dprint_h */