- ipv6 support (-DUSE_IPV6)
[sip-router] / dprint.h
1 /*
2  * $Id$
3  */
4
5
6 #ifndef dprint_h
7 #define dprint_h
8
9 #include <syslog.h>
10
11
12 #define L_ALERT -3
13 #define L_CRIT  -2
14 #define L_ERR   -1
15 #define L_WARN   1
16 #define L_NOTICE 2
17 #define L_INFO   3
18 #define L_DBG    4
19
20 /* vars:*/
21
22 extern int debug;
23 extern int log_stderr;
24
25
26 #define DPRINT_LEV      1
27 /* log facility (see syslog(3)) */
28 #define L_FAC  LOG_DAEMON
29 /* priority at which we log */
30 #define DPRINT_PRIO LOG_DEBUG
31
32
33 void dprint (char* format, ...);
34
35 #ifdef NO_DEBUG
36         #ifdef __SUNPRO_C
37                 #define DPrint(...)
38         #else
39                 #define DPrint(fmt, args...)
40         #endif
41 #else
42         #ifdef __SUNPRO_C
43                 #define DPrint( ...) \
44                         do{ \
45                                 if (debug>=DPRINT_LEV){ \
46                                         if (log_stderr){ \
47                                                 dprint (__VA_ARGS__); \
48                                         }else{ \
49                                                 syslog(DPRINT_LEV|L_FAC,  __VA_ARGS__); \
50                                         }\
51                                 } \
52                         }while(0)
53         #else
54                         #define DPrint(fmt,args...) \
55                         do{ \
56                                 if (debug>=DPRINT_LEV){ \
57                                         if (log_stderr){ \
58                                                 dprint (fmt, ## args); \
59                                         }else{ \
60                                                 syslog(DPRINT_LEV|L_FAC, fmt, ## args); \
61                                         }\
62                                 } \
63                         }while(0)
64         #endif
65
66 #endif
67
68 #ifndef NO_DEBUG
69         #undef NO_LOG
70 #endif
71
72 #ifdef NO_LOG
73         #ifdef __SUNPRO_C
74                 #define LOG(lev, ...)
75         #else
76                 #define LOG(lev, fmt, args...)
77         #endif
78 #else
79         #ifdef __SUNPRO_C
80                 #define LOG(lev, ...) \
81                         do { \
82                                 if (debug>=(lev)){ \
83                                         if (log_stderr) dprint (__VA_ARGS__); \
84                                         else { \
85                                                 switch(lev){ \
86                                                         case L_CRIT: \
87                                                                 syslog(LOG_CRIT | L_FAC, __VA_ARGS__); \
88                                                                 break; \
89                                                         case L_ALERT: \
90                                                                 syslog(LOG_ALERT | L_FAC, __VA_ARGS__); \
91                                                                 break; \
92                                                         case L_ERR: \
93                                                                 syslog(LOG_ERR | L_FAC, __VA_ARGS__); \
94                                                                 break; \
95                                                         case L_WARN: \
96                                                                 syslog(LOG_WARNING | L_FAC, __VA_ARGS__);\
97                                                                 break; \
98                                                         case L_NOTICE: \
99                                                                 syslog(LOG_NOTICE | L_FAC, __VA_ARGS__); \
100                                                                 break; \
101                                                         case L_INFO: \
102                                                                 syslog(LOG_INFO | L_FAC, __VA_ARGS__); \
103                                                                 break; \
104                                                         case L_DBG: \
105                                                                 syslog(LOG_DEBUG | L_FAC, __VA_ARGS__); \
106                                                                 break; \
107                                                 } \
108                                         } \
109                                 } \
110                         }while(0)
111         #else
112                 #define LOG(lev, fmt, args...) \
113                         do { \
114                                 if (debug>=(lev)){ \
115                                         if (log_stderr) dprint (fmt, ## args); \
116                                         else { \
117                                                 switch(lev){ \
118                                                         case L_CRIT: \
119                                                                 syslog(LOG_CRIT | L_FAC, fmt, ##args); \
120                                                                 break; \
121                                                         case L_ALERT: \
122                                                                 syslog(LOG_ALERT | L_FAC, fmt, ##args); \
123                                                                 break; \
124                                                         case L_ERR: \
125                                                                 syslog(LOG_ERR | L_FAC, fmt, ##args); \
126                                                                 break; \
127                                                         case L_WARN: \
128                                                                 syslog(LOG_WARNING | L_FAC, fmt, ##args); \
129                                                                 break; \
130                                                         case L_NOTICE: \
131                                                                 syslog(LOG_NOTICE | L_FAC, fmt, ##args); \
132                                                                 break; \
133                                                         case L_INFO: \
134                                                                 syslog(LOG_INFO | L_FAC, fmt, ##args); \
135                                                                 break; \
136                                                         case L_DBG: \
137                                                                 syslog(LOG_DEBUG | L_FAC, fmt, ##args); \
138                                                                 break; \
139                                                 } \
140                                         } \
141                                 } \
142                         }while(0)
143         #endif /*SUN_PRO_C*/
144 #endif
145
146
147 #ifdef NO_DEBUG
148         #ifdef __SUNPRO_C
149                 #define DBG(...)
150         #else
151                 #define DBG(fmt, args...)
152         #endif
153 #else
154         #ifdef __SUNPRO_C
155                 #define DBG(...) LOG(L_DBG, __VA_ARGS__)
156         #else
157                 #define DBG(fmt, args...) LOG(L_DBG, fmt, ## args)
158         #endif
159 #endif
160
161 #endif /* ifndef dprint_h */