GPLization banner introduced to *.[hc] files
[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
49
50 #define DPRINT_LEV      1
51 /* log facility (see syslog(3)) */
52 #define L_FAC  LOG_DAEMON
53 /* priority at which we log */
54 #define DPRINT_PRIO LOG_DEBUG
55
56
57 void dprint (char* format, ...);
58
59 #ifdef NO_DEBUG
60         #ifdef __SUNPRO_C
61                 #define DPrint(...)
62         #else
63                 #define DPrint(fmt, args...)
64         #endif
65 #else
66         #ifdef __SUNPRO_C
67                 #define DPrint( ...) \
68                         do{ \
69                                 if (debug>=DPRINT_LEV){ \
70                                         if (log_stderr){ \
71                                                 dprint (__VA_ARGS__); \
72                                         }else{ \
73                                                 syslog(DPRINT_LEV|L_FAC,  __VA_ARGS__); \
74                                         }\
75                                 } \
76                         }while(0)
77         #else
78                         #define DPrint(fmt,args...) \
79                         do{ \
80                                 if (debug>=DPRINT_LEV){ \
81                                         if (log_stderr){ \
82                                                 dprint (fmt, ## args); \
83                                         }else{ \
84                                                 syslog(DPRINT_LEV|L_FAC, fmt, ## args); \
85                                         }\
86                                 } \
87                         }while(0)
88         #endif
89
90 #endif
91
92 #ifndef NO_DEBUG
93         #undef NO_LOG
94 #endif
95
96 #ifdef NO_LOG
97         #ifdef __SUNPRO_C
98                 #define LOG(lev, ...)
99         #else
100                 #define LOG(lev, fmt, args...)
101         #endif
102 #else
103         #ifdef __SUNPRO_C
104                 #define LOG(lev, ...) \
105                         do { \
106                                 if (debug>=(lev)){ \
107                                         if (log_stderr) dprint (__VA_ARGS__); \
108                                         else { \
109                                                 switch(lev){ \
110                                                         case L_CRIT: \
111                                                                 syslog(LOG_CRIT | L_FAC, __VA_ARGS__); \
112                                                                 break; \
113                                                         case L_ALERT: \
114                                                                 syslog(LOG_ALERT | L_FAC, __VA_ARGS__); \
115                                                                 break; \
116                                                         case L_ERR: \
117                                                                 syslog(LOG_ERR | L_FAC, __VA_ARGS__); \
118                                                                 break; \
119                                                         case L_WARN: \
120                                                                 syslog(LOG_WARNING | L_FAC, __VA_ARGS__);\
121                                                                 break; \
122                                                         case L_NOTICE: \
123                                                                 syslog(LOG_NOTICE | L_FAC, __VA_ARGS__); \
124                                                                 break; \
125                                                         case L_INFO: \
126                                                                 syslog(LOG_INFO | L_FAC, __VA_ARGS__); \
127                                                                 break; \
128                                                         case L_DBG: \
129                                                                 syslog(LOG_DEBUG | L_FAC, __VA_ARGS__); \
130                                                                 break; \
131                                                 } \
132                                         } \
133                                 } \
134                         }while(0)
135         #else
136                 #define LOG(lev, fmt, args...) \
137                         do { \
138                                 if (debug>=(lev)){ \
139                                         if (log_stderr) dprint (fmt, ## args); \
140                                         else { \
141                                                 switch(lev){ \
142                                                         case L_CRIT: \
143                                                                 syslog(LOG_CRIT | L_FAC, fmt, ##args); \
144                                                                 break; \
145                                                         case L_ALERT: \
146                                                                 syslog(LOG_ALERT | L_FAC, fmt, ##args); \
147                                                                 break; \
148                                                         case L_ERR: \
149                                                                 syslog(LOG_ERR | L_FAC, fmt, ##args); \
150                                                                 break; \
151                                                         case L_WARN: \
152                                                                 syslog(LOG_WARNING | L_FAC, fmt, ##args); \
153                                                                 break; \
154                                                         case L_NOTICE: \
155                                                                 syslog(LOG_NOTICE | L_FAC, fmt, ##args); \
156                                                                 break; \
157                                                         case L_INFO: \
158                                                                 syslog(LOG_INFO | L_FAC, fmt, ##args); \
159                                                                 break; \
160                                                         case L_DBG: \
161                                                                 syslog(LOG_DEBUG | L_FAC, fmt, ##args); \
162                                                                 break; \
163                                                 } \
164                                         } \
165                                 } \
166                         }while(0)
167         #endif /*SUN_PRO_C*/
168 #endif
169
170
171 #ifdef NO_DEBUG
172         #ifdef __SUNPRO_C
173                 #define DBG(...)
174         #else
175                 #define DBG(fmt, args...)
176         #endif
177 #else
178         #ifdef __SUNPRO_C
179                 #define DBG(...) LOG(L_DBG, __VA_ARGS__)
180         #else
181                 #define DBG(fmt, args...) LOG(L_DBG, fmt, ## args)
182         #endif
183 #endif
184
185 #endif /* ifndef dprint_h */