785a39f64da8920b1eac5c05a90d1a7cb311f20f
[sip-router] / dprint.h
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2001-2003 Fhg Fokus
5  *
6  * This file is part of ser, a free SIP server.
7  *
8  * ser is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version
12  *
13  * For a license to use the ser software under conditions
14  * other than those described here, or to purchase support for this
15  * software, please contact iptel.org by e-mail at the following addresses:
16  *    info@iptel.org
17  *
18  * ser is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License 
24  * along with this program; if not, write to the Free Software 
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  */
27
28
29
30 #ifndef dprint_h
31 #define dprint_h
32
33 #include <syslog.h>
34
35
36 #define L_ALERT -3
37 #define L_CRIT  -2
38 #define L_ERR   -1
39 #define L_WARN   1
40 #define L_NOTICE 2
41 #define L_INFO   3
42 #define L_DBG    4
43
44 /* vars:*/
45
46 extern int debug;
47 extern int log_stderr;
48 extern int log_facility;
49
50
51 #define DPRINT_LEV      1
52 /* priority at which we log */
53 #define DPRINT_PRIO LOG_DEBUG
54
55
56 void dprint (char* format, ...);
57
58 int str2facility(char *s);
59
60
61 #ifdef NO_DEBUG
62         #ifdef __SUNPRO_C
63                 #define DPrint(...)
64         #else
65                 #define DPrint(fmt, args...)
66         #endif
67 #else
68         #ifdef __SUNPRO_C
69                 #define DPrint( ...) \
70                         do{ \
71                                 if (debug>=DPRINT_LEV){ \
72                                         if (log_stderr){ \
73                                                 dprint (__VA_ARGS__); \
74                                         }else{ \
75                                                 syslog(DPRINT_LEV|log_facility,  __VA_ARGS__); \
76                                         }\
77                                 } \
78                         }while(0)
79         #else
80                         #define DPrint(fmt,args...) \
81                         do{ \
82                                 if (debug>=DPRINT_LEV){ \
83                                         if (log_stderr){ \
84                                                 dprint (fmt, ## args); \
85                                         }else{ \
86                                                 syslog(DPRINT_LEV|log_facility, fmt, ## args); \
87                                         }\
88                                 } \
89                         }while(0)
90         #endif
91
92 #endif
93
94 #ifndef NO_DEBUG
95         #undef NO_LOG
96 #endif
97
98 #ifdef NO_LOG
99         #ifdef __SUNPRO_C
100                 #define LOG(lev, ...)
101         #else
102                 #define LOG(lev, fmt, args...)
103         #endif
104 #else
105         #ifdef __SUNPRO_C
106                 #define LOG(lev, ...) \
107                         do { \
108                                 if (debug>=(lev)){ \
109                                         if (log_stderr) dprint (__VA_ARGS__); \
110                                         else { \
111                                                 switch(lev){ \
112                                                         case L_CRIT: \
113                                                                 syslog(LOG_CRIT|log_facility, __VA_ARGS__); \
114                                                                 break; \
115                                                         case L_ALERT: \
116                                                                 syslog(LOG_ALERT|log_facility, __VA_ARGS__); \
117                                                                 break; \
118                                                         case L_ERR: \
119                                                                 syslog(LOG_ERR|log_facility, __VA_ARGS__); \
120                                                                 break; \
121                                                         case L_WARN: \
122                                                                 syslog(LOG_WARNING|log_facility, __VA_ARGS__);\
123                                                                 break; \
124                                                         case L_NOTICE: \
125                                                                 syslog(LOG_NOTICE|log_facility, __VA_ARGS__); \
126                                                                 break; \
127                                                         case L_INFO: \
128                                                                 syslog(LOG_INFO|log_facility, __VA_ARGS__); \
129                                                                 break; \
130                                                         case L_DBG: \
131                                                                 syslog(LOG_DEBUG|log_facility, __VA_ARGS__); \
132                                                                 break; \
133                                                 } \
134                                         } \
135                                 } \
136                         }while(0)
137         #else
138                 #define LOG(lev, fmt, args...) \
139                         do { \
140                                 if (debug>=(lev)){ \
141                                         if (log_stderr) dprint (fmt, ## args); \
142                                         else { \
143                                                 switch(lev){ \
144                                                         case L_CRIT: \
145                                                                 syslog(LOG_CRIT|log_facility, fmt, ##args); \
146                                                                 break; \
147                                                         case L_ALERT: \
148                                                                 syslog(LOG_ALERT|log_facility, fmt, ##args); \
149                                                                 break; \
150                                                         case L_ERR: \
151                                                                 syslog(LOG_ERR|log_facility, fmt, ##args); \
152                                                                 break; \
153                                                         case L_WARN: \
154                                                                 syslog(LOG_WARNING|log_facility, fmt, ##args);\
155                                                                 break; \
156                                                         case L_NOTICE: \
157                                                                 syslog(LOG_NOTICE|log_facility, fmt, ##args); \
158                                                                 break; \
159                                                         case L_INFO: \
160                                                                 syslog(LOG_INFO|log_facility, fmt, ##args); \
161                                                                 break; \
162                                                         case L_DBG: \
163                                                                 syslog(LOG_DEBUG|log_facility, fmt, ##args); \
164                                                                 break; \
165                                                 } \
166                                         } \
167                                 } \
168                         }while(0)
169         #endif /*SUN_PRO_C*/
170 #endif
171
172
173 #ifdef NO_DEBUG
174         #ifdef __SUNPRO_C
175                 #define DBG(...)
176         #else
177                 #define DBG(fmt, args...)
178         #endif
179 #else
180         #ifdef __SUNPRO_C
181                 #define DBG(...) LOG(L_DBG, __VA_ARGS__)
182         #else
183                 #define DBG(fmt, args...) LOG(L_DBG, fmt, ## args)
184         #endif
185 #endif
186
187 #endif /* ifndef dprint_h */