- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,471 +0,0 @@ |
1 |
-/* |
|
2 |
- * debug print |
|
3 |
- * |
|
4 |
- * Copyright (C) 2001-2003 FhG Fokus |
|
5 |
- * |
|
6 |
- * This file is part of Kamailio, a free SIP server. |
|
7 |
- * |
|
8 |
- * Kamailio 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 |
- * Kamailio is distributed in the hope that it will be useful, |
|
14 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
- * GNU General Public License for more details. |
|
17 |
- * |
|
18 |
- * You should have received a copy of the GNU General Public License |
|
19 |
- * along with this program; if not, write to the Free Software |
|
20 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
21 |
- */ |
|
22 |
-/*! |
|
23 |
- * \file |
|
24 |
- * \brief Kamailio core :: Debug print |
|
25 |
- * \ingroup core |
|
26 |
- * Module: \ref core |
|
27 |
- */ |
|
28 |
- |
|
29 |
- |
|
30 |
- |
|
31 |
-#include "globals.h" |
|
32 |
-#include "dprint.h" |
|
33 |
-#include "pvar.h" |
|
34 |
- |
|
35 |
-#include <stdarg.h> |
|
36 |
-#include <stdio.h> |
|
37 |
-#include <strings.h> |
|
38 |
- |
|
39 |
-char *_km_log_engine_type = NULL; |
|
40 |
-char *_km_log_engine_data = NULL; |
|
41 |
- |
|
42 |
-km_log_f _km_log_func = &syslog; |
|
43 |
- |
|
44 |
-/** |
|
45 |
- * |
|
46 |
- */ |
|
47 |
-void km_log_func_set(km_log_f f) |
|
48 |
-{ |
|
49 |
- _km_log_func = f; |
|
50 |
-} |
|
51 |
- |
|
52 |
-#ifndef NO_SIG_DEBUG |
|
53 |
-/* signal protection: !=0 when LOG/DBG/... are printing */ |
|
54 |
-volatile int dprint_crit = 0; |
|
55 |
-#endif |
|
56 |
- |
|
57 |
-static char* str_fac[]={"LOG_AUTH","LOG_CRON","LOG_DAEMON", |
|
58 |
- "LOG_KERN","LOG_LOCAL0","LOG_LOCAL1", |
|
59 |
- "LOG_LOCAL2","LOG_LOCAL3","LOG_LOCAL4","LOG_LOCAL5", |
|
60 |
- "LOG_LOCAL6","LOG_LOCAL7","LOG_LPR","LOG_MAIL", |
|
61 |
- "LOG_NEWS","LOG_USER","LOG_UUCP", |
|
62 |
-#ifndef __OS_solaris |
|
63 |
- "LOG_AUTHPRIV","LOG_FTP","LOG_SYSLOG", |
|
64 |
-#endif |
|
65 |
- 0}; |
|
66 |
- |
|
67 |
-static int int_fac[]={LOG_AUTH , LOG_CRON , LOG_DAEMON , |
|
68 |
- LOG_KERN , LOG_LOCAL0 , LOG_LOCAL1 , |
|
69 |
- LOG_LOCAL2 , LOG_LOCAL3 , LOG_LOCAL4 , LOG_LOCAL5 , |
|
70 |
- LOG_LOCAL6 , LOG_LOCAL7 , LOG_LPR , LOG_MAIL , |
|
71 |
- LOG_NEWS , LOG_USER , LOG_UUCP, |
|
72 |
-#ifndef __OS_solaris |
|
73 |
- LOG_AUTHPRIV,LOG_FTP,LOG_SYSLOG, |
|
74 |
-#endif |
|
75 |
- 0}; |
|
76 |
- |
|
77 |
-struct log_level_info log_level_info[] = { |
|
78 |
- {"ALERT", LOG_ALERT}, /* L_ALERT */ |
|
79 |
- {"BUG", LOG_CRIT}, /* L_BUG */ |
|
80 |
- {"CRITICAL", LOG_CRIT}, /* L_CRIT2 */ |
|
81 |
- {"", LOG_CRIT}, /* L_CRIT */ |
|
82 |
- {"ERROR", LOG_ERR}, /* L_ERR */ |
|
83 |
- {"WARNING", LOG_WARNING}, /* L_WARN */ |
|
84 |
- {"NOTICE", LOG_NOTICE}, /* L_NOTICE */ |
|
85 |
- {"INFO", LOG_INFO}, /* L_INFO */ |
|
86 |
- {"DEBUG", LOG_DEBUG} /* L_DBG */ |
|
87 |
-}; |
|
88 |
- |
|
89 |
-int str2facility(char *s) |
|
90 |
-{ |
|
91 |
- int i; |
|
92 |
- |
|
93 |
- for (i=0; str_fac[i]; i++) { |
|
94 |
- if (!strcasecmp(s,str_fac[i])) |
|
95 |
- return int_fac[i]; |
|
96 |
- } |
|
97 |
- return -1; |
|
98 |
-} |
|
99 |
- |
|
100 |
-char* facility2str(int fl, int *len) |
|
101 |
-{ |
|
102 |
- int i; |
|
103 |
- |
|
104 |
- for (i=0; str_fac[i]; i++) { |
|
105 |
- if (fl == int_fac[i]) { |
|
106 |
- *len = strlen(str_fac[i]); |
|
107 |
- return str_fac[i]; |
|
108 |
- } |
|
109 |
- } |
|
110 |
- |
|
111 |
- return NULL; |
|
112 |
-} |
|
113 |
- |
|
114 |
-/* fixup function for log_facility cfg parameter */ |
|
115 |
-int log_facility_fixup(void *handle, str *gname, str *name, void **val) |
|
116 |
-{ |
|
117 |
- int i; |
|
118 |
- |
|
119 |
- if ((i = str2facility((char *)*val)) == -1) { |
|
120 |
- LM_ERR("invalid log facility: %s\n", (char *)*val); |
|
121 |
- return -1; |
|
122 |
- } |
|
123 |
- *val = (void *)(long)i; |
|
124 |
- return 0; |
|
125 |
-} |
|
126 |
- |
|
127 |
- |
|
128 |
-/** |
|
129 |
- * per process debug log level (local) |
|
130 |
- */ |
|
131 |
- |
|
132 |
-/* value for unset local log level */ |
|
133 |
-#define UNSET_LOCAL_DEBUG_LEVEL -255 |
|
134 |
-#define UNSET_LOCAL_DEBUG_FACILITY -255 |
|
135 |
- |
|
136 |
-/* the local debug log level */ |
|
137 |
-static int _local_debug_level = UNSET_LOCAL_DEBUG_LEVEL; |
|
138 |
-static int _local_debug_facility = UNSET_LOCAL_DEBUG_FACILITY; |
|
139 |
-/* callback to get per module debug level */ |
|
140 |
-static get_module_debug_level_f _module_debug_level = NULL; |
|
141 |
-static get_module_debug_facility_f _module_debug_facility = NULL; |
|
142 |
- |
|
143 |
-/** |
|
144 |
- * @brief set callback function for per module debug level |
|
145 |
- */ |
|
146 |
-void set_module_debug_level_cb(get_module_debug_level_f f) |
|
147 |
-{ |
|
148 |
- _module_debug_level = f; |
|
149 |
-} |
|
150 |
- |
|
151 |
-void set_module_debug_facility_cb(get_module_debug_facility_f f) |
|
152 |
-{ |
|
153 |
- _module_debug_facility = f; |
|
154 |
-} |
|
155 |
- |
|
156 |
-/** |
|
157 |
- * @brief return the log level - the local one if it set, |
|
158 |
- * otherwise the global value |
|
159 |
- */ |
|
160 |
-int get_debug_level(char *mname, int mnlen) { |
|
161 |
- int mlevel; |
|
162 |
- /*important -- no LOGs inside, because it will loop */ |
|
163 |
- if(unlikely(_module_debug_level!=NULL && mnlen>0)) { |
|
164 |
- if(_module_debug_level(mname, mnlen, &mlevel)==0) { |
|
165 |
- return mlevel; |
|
166 |
- } |
|
167 |
- } |
|
168 |
- return (_local_debug_level != UNSET_LOCAL_DEBUG_LEVEL) ? |
|
169 |
- _local_debug_level : cfg_get(core, core_cfg, debug); |
|
170 |
-} |
|
171 |
- |
|
172 |
-/** |
|
173 |
- * @brief return the log facility - the local one if it set, |
|
174 |
- * otherwise the global value |
|
175 |
- */ |
|
176 |
-int get_debug_facility(char *mname, int mnlen) { |
|
177 |
- int mfacility; |
|
178 |
- /*important -- no LOGs inside, because it will loop */ |
|
179 |
- if(unlikely(_module_debug_facility!=NULL && mnlen>0)) { |
|
180 |
- if(_module_debug_facility(mname, mnlen, &mfacility)==0) { |
|
181 |
- return mfacility; |
|
182 |
- } |
|
183 |
- } |
|
184 |
- return (_local_debug_facility != UNSET_LOCAL_DEBUG_FACILITY) ? |
|
185 |
- _local_debug_facility : cfg_get(core, core_cfg, log_facility); |
|
186 |
-} |
|
187 |
- |
|
188 |
- |
|
189 |
-/** |
|
190 |
- * @brief set the local debug log level |
|
191 |
- */ |
|
192 |
-void set_local_debug_level(int level) |
|
193 |
-{ |
|
194 |
- _local_debug_level = level; |
|
195 |
-} |
|
196 |
- |
|
197 |
-/** |
|
198 |
- * @brief reset the local debug log level |
|
199 |
- */ |
|
200 |
-void reset_local_debug_level(void) |
|
201 |
-{ |
|
202 |
- _local_debug_level = UNSET_LOCAL_DEBUG_LEVEL; |
|
203 |
-} |
|
204 |
- |
|
205 |
-/** |
|
206 |
- * @brief set the local debug log facility |
|
207 |
- */ |
|
208 |
-void set_local_debug_facility(int facility) |
|
209 |
-{ |
|
210 |
- _local_debug_facility = facility; |
|
211 |
-} |
|
212 |
- |
|
213 |
-/** |
|
214 |
- * @brief reset the local debug log facility |
|
215 |
- */ |
|
216 |
-void reset_local_debug_facility(void) |
|
217 |
-{ |
|
218 |
- _local_debug_facility = UNSET_LOCAL_DEBUG_FACILITY; |
|
219 |
-} |
|
220 |
- |
|
221 |
-typedef struct log_level_color { |
|
222 |
- char f; |
|
223 |
- char b; |
|
224 |
-} log_level_color_t; |
|
225 |
- |
|
226 |
-log_level_color_t _log_level_colors[L_MAX - L_MIN + 1]; |
|
227 |
- |
|
228 |
-void dprint_init_colors(void) |
|
229 |
-{ |
|
230 |
- int i; |
|
231 |
- |
|
232 |
- i = 0; |
|
233 |
- |
|
234 |
- memset(_log_level_colors, 0, |
|
235 |
- (L_MAX - L_MIN + 1)*sizeof(log_level_color_t)); |
|
236 |
- |
|
237 |
- /* L_ALERT */ |
|
238 |
- _log_level_colors[i].f = 'R'; /* default */ |
|
239 |
- _log_level_colors[i].b = 'x'; /* default */ |
|
240 |
- i++; |
|
241 |
- |
|
242 |
- /* L_BUG */ |
|
243 |
- _log_level_colors[i].f = 'P'; /* default */ |
|
244 |
- _log_level_colors[i].b = 'x'; /* default */ |
|
245 |
- i++; |
|
246 |
- |
|
247 |
- /* L_CRIT2 */ |
|
248 |
- _log_level_colors[i].f = 'y'; /* default */ |
|
249 |
- _log_level_colors[i].b = 'x'; /* default */ |
|
250 |
- i++; |
|
251 |
- |
|
252 |
- /* L_CRIT */ |
|
253 |
- _log_level_colors[i].f = 'b'; /* default */ |
|
254 |
- _log_level_colors[i].b = 'x'; /* default */ |
|
255 |
- i++; |
|
256 |
- |
|
257 |
- /* L_ERR */ |
|
258 |
- _log_level_colors[i].f = 'r'; /* default */ |
|
259 |
- _log_level_colors[i].b = 'x'; /* default */ |
|
260 |
- i++; |
|
261 |
- |
|
262 |
- /* L_WARN */ |
|
263 |
- _log_level_colors[i].f = 'p'; /* default */ |
|
264 |
- _log_level_colors[i].b = 'x'; /* default */ |
|
265 |
- i++; |
|
266 |
- |
|
267 |
- /* L_NOTICE */ |
|
268 |
- _log_level_colors[i].f = 'g'; /* default */ |
|
269 |
- _log_level_colors[i].b = 'x'; /* default */ |
|
270 |
- i++; |
|
271 |
- |
|
272 |
- /* L_INFO */ |
|
273 |
- _log_level_colors[i].f = 'c'; /* default */ |
|
274 |
- _log_level_colors[i].b = 'x'; /* default */ |
|
275 |
- i++; |
|
276 |
- |
|
277 |
- /* L_DBG */ |
|
278 |
- _log_level_colors[i].f = 'x'; /* default */ |
|
279 |
- _log_level_colors[i].b = 'x'; /* default */ |
|
280 |
- i++; |
|
281 |
-} |
|
282 |
- |
|
283 |
-#define TERM_COLOR_SIZE 16 |
|
284 |
- |
|
285 |
-#define dprint_termc_add(p, end, s) \ |
|
286 |
- do{ \ |
|
287 |
- if ((p)+(sizeof(s)-1)<=(end)){ \ |
|
288 |
- memcpy((p), s, sizeof(s)-1); \ |
|
289 |
- (p)+=sizeof(s)-1; \ |
|
290 |
- }else{ \ |
|
291 |
- /* overflow */ \ |
|
292 |
- LM_ERR("dprint_termc_add overflow\n"); \ |
|
293 |
- goto error; \ |
|
294 |
- } \ |
|
295 |
- } while(0) |
|
296 |
- |
|
297 |
- |
|
298 |
-void dprint_term_color(char f, char b, str *obuf) |
|
299 |
-{ |
|
300 |
- static char term_color[TERM_COLOR_SIZE]; |
|
301 |
- char* p; |
|
302 |
- char* end; |
|
303 |
- |
|
304 |
- p = term_color; |
|
305 |
- end = p + TERM_COLOR_SIZE; |
|
306 |
- |
|
307 |
- /* excape sequence */ |
|
308 |
- dprint_termc_add(p, end, "\033["); |
|
309 |
- |
|
310 |
- if(f!='_') |
|
311 |
- { |
|
312 |
- if (islower((int)f)) |
|
313 |
- { |
|
314 |
- /* normal font */ |
|
315 |
- dprint_termc_add(p, end, "0;"); |
|
316 |
- } else { |
|
317 |
- /* bold font */ |
|
318 |
- dprint_termc_add(p, end, "1;"); |
|
319 |
- f += 32; |
|
320 |
- } |
|
321 |
- } |
|
322 |
- |
|
323 |
- /* foreground */ |
|
324 |
- switch(f) |
|
325 |
- { |
|
326 |
- case 'x': |
|
327 |
- dprint_termc_add(p, end, "39;"); |
|
328 |
- break; |
|
329 |
- case 's': |
|
330 |
- dprint_termc_add(p, end, "30;"); |
|
331 |
- break; |
|
332 |
- case 'r': |
|
333 |
- dprint_termc_add(p, end, "31;"); |
|
334 |
- break; |
|
335 |
- case 'g': |
|
336 |
- dprint_termc_add(p, end, "32;"); |
|
337 |
- break; |
|
338 |
- case 'y': |
|
339 |
- dprint_termc_add(p, end, "33;"); |
|
340 |
- break; |
|
341 |
- case 'b': |
|
342 |
- dprint_termc_add(p, end, "34;"); |
|
343 |
- break; |
|
344 |
- case 'p': |
|
345 |
- dprint_termc_add(p, end, "35;"); |
|
346 |
- break; |
|
347 |
- case 'c': |
|
348 |
- dprint_termc_add(p, end, "36;"); |
|
349 |
- break; |
|
350 |
- case 'w': |
|
351 |
- dprint_termc_add(p, end, "37;"); |
|
352 |
- break; |
|
353 |
- default: |
|
354 |
- dprint_termc_add(p, end, "39;"); |
|
355 |
- } |
|
356 |
- |
|
357 |
- /* background */ |
|
358 |
- switch(b) |
|
359 |
- { |
|
360 |
- case 'x': |
|
361 |
- dprint_termc_add(p, end, "49"); |
|
362 |
- break; |
|
363 |
- case 's': |
|
364 |
- dprint_termc_add(p, end, "40"); |
|
365 |
- break; |
|
366 |
- case 'r': |
|
367 |
- dprint_termc_add(p, end, "41"); |
|
368 |
- break; |
|
369 |
- case 'g': |
|
370 |
- dprint_termc_add(p, end, "42"); |
|
371 |
- break; |
|
372 |
- case 'y': |
|
373 |
- dprint_termc_add(p, end, "43"); |
|
374 |
- break; |
|
375 |
- case 'b': |
|
376 |
- dprint_termc_add(p, end, "44"); |
|
377 |
- break; |
|
378 |
- case 'p': |
|
379 |
- dprint_termc_add(p, end, "45"); |
|
380 |
- break; |
|
381 |
- case 'c': |
|
382 |
- dprint_termc_add(p, end, "46"); |
|
383 |
- break; |
|
384 |
- case 'w': |
|
385 |
- dprint_termc_add(p, end, "47"); |
|
386 |
- break; |
|
387 |
- default: |
|
388 |
- dprint_termc_add(p, end, "49"); |
|
389 |
- } |
|
390 |
- |
|
391 |
- /* end */ |
|
392 |
- dprint_termc_add(p, end, "m"); |
|
393 |
- |
|
394 |
- obuf->s = term_color; |
|
395 |
- obuf->len = p - term_color; |
|
396 |
- return; |
|
397 |
- |
|
398 |
-error: |
|
399 |
- obuf->s = term_color; |
|
400 |
- term_color[0] = '\0'; |
|
401 |
- obuf->len = 0; |
|
402 |
-} |
|
403 |
- |
|
404 |
-void dprint_color(int level) |
|
405 |
-{ |
|
406 |
- str obuf; |
|
407 |
- |
|
408 |
- if(level<L_MIN || level>L_MAX) |
|
409 |
- return; |
|
410 |
- dprint_term_color(_log_level_colors[level - L_MIN].f, |
|
411 |
- _log_level_colors[level - L_MIN].b, |
|
412 |
- &obuf); |
|
413 |
- fprintf(stderr, "%.*s", obuf.len, obuf.s); |
|
414 |
-} |
|
415 |
- |
|
416 |
-void dprint_color_reset(void) |
|
417 |
-{ |
|
418 |
- str obuf; |
|
419 |
- |
|
420 |
- dprint_term_color('x', 'x', &obuf); |
|
421 |
- fprintf(stderr, "%.*s", obuf.len, obuf.s); |
|
422 |
-} |
|
423 |
- |
|
424 |
-void dprint_color_update(int level, char f, char b) |
|
425 |
-{ |
|
426 |
- if(level<L_MIN || level>L_MAX) |
|
427 |
- return; |
|
428 |
- if(f && f!='0') _log_level_colors[level - L_MIN].f = f; |
|
429 |
- if(b && b!='0') _log_level_colors[level - L_MIN].b = b; |
|
430 |
-} |
|
431 |
- |
|
432 |
- |
|
433 |
-/* log_prefix functionality */ |
|
434 |
-str *log_prefix_val = NULL; |
|
435 |
-int log_prefix_mode = 0; |
|
436 |
-static pv_elem_t *log_prefix_pvs = NULL; |
|
437 |
- |
|
438 |
-#define LOG_PREFIX_SIZE 1024 |
|
439 |
-static char log_prefix_buf[LOG_PREFIX_SIZE]; |
|
440 |
-static str log_prefix_str; |
|
441 |
- |
|
442 |
-void log_prefix_init(void) |
|
443 |
-{ |
|
444 |
- str s; |
|
445 |
- if(log_prefix_fmt==NULL) |
|
446 |
- return; |
|
447 |
- s.s = log_prefix_fmt; s.len = strlen(s.s); |
|
448 |
- |
|
449 |
- if(pv_parse_format(&s, &log_prefix_pvs)<0) |
|
450 |
- { |
|
451 |
- LM_ERR("wrong format[%s]\n", s.s); |
|
452 |
- return; |
|
453 |
- } |
|
454 |
-} |
|
455 |
- |
|
456 |
-void log_prefix_set(sip_msg_t *msg) |
|
457 |
-{ |
|
458 |
- if(log_prefix_pvs == NULL) |
|
459 |
- return; |
|
460 |
- if(msg==NULL || !(IS_SIP(msg) || IS_SIP_REPLY(msg))) { |
|
461 |
- log_prefix_val = NULL; |
|
462 |
- return; |
|
463 |
- } |
|
464 |
- log_prefix_str.s = log_prefix_buf; |
|
465 |
- log_prefix_str.len = LOG_PREFIX_SIZE; |
|
466 |
- if(pv_printf(msg, log_prefix_pvs, log_prefix_str.s, &log_prefix_str.len)<0) |
|
467 |
- return; |
|
468 |
- if(log_prefix_str.len<=0) |
|
469 |
- return; |
|
470 |
- log_prefix_val = &log_prefix_str; |
|
471 |
-} |
- if set to 0 (default), then log_prefix is evaluated when the sip
message is received and then reused (recommended if the log_prefix has
only variables that have same value for same message). This is the
current behaviour of log_prefix evaluation.
- if set to 1, then the log prefix is evaluated before/after each config
action (needs to be set when the log_prefix has variables that are
different based on the context of config execution, e.g., $cfg(line))
Add support to get the facility number given the facility string.
... | ... |
@@ -90,13 +90,27 @@ int str2facility(char *s) |
90 | 90 |
{ |
91 | 91 |
int i; |
92 | 92 |
|
93 |
- for( i=0; str_fac[i] ; i++) { |
|
93 |
+ for (i=0; str_fac[i]; i++) { |
|
94 | 94 |
if (!strcasecmp(s,str_fac[i])) |
95 | 95 |
return int_fac[i]; |
96 | 96 |
} |
97 | 97 |
return -1; |
98 | 98 |
} |
99 | 99 |
|
100 |
+char* facility2str(int fl, int *len) |
|
101 |
+{ |
|
102 |
+ int i; |
|
103 |
+ |
|
104 |
+ for (i=0; str_fac[i]; i++) { |
|
105 |
+ if (fl == int_fac[i]) { |
|
106 |
+ *len = strlen(str_fac[i]); |
|
107 |
+ return str_fac[i]; |
|
108 |
+ } |
|
109 |
+ } |
|
110 |
+ |
|
111 |
+ return NULL; |
|
112 |
+} |
|
113 |
+ |
|
100 | 114 |
/* fixup function for log_facility cfg parameter */ |
101 | 115 |
int log_facility_fixup(void *handle, str *gname, str *name, void **val) |
102 | 116 |
{ |
... | ... |
@@ -420,7 +420,7 @@ void dprint_color_update(int level, char f, char b) |
420 | 420 |
str *log_prefix_val = NULL; |
421 | 421 |
static pv_elem_t *log_prefix_pvs = NULL; |
422 | 422 |
|
423 |
-#define LOG_PREFIX_SIZE 128 |
|
423 |
+#define LOG_PREFIX_SIZE 1024 |
|
424 | 424 |
static char log_prefix_buf[LOG_PREFIX_SIZE]; |
425 | 425 |
static str log_prefix_str; |
426 | 426 |
|
- this enables a module to replace all logging to syslog with another
logging mechanism
- it is not enabled when log_stderror=yes or the system is detected as
__SUNPRO_C
... | ... |
@@ -36,6 +36,19 @@ |
36 | 36 |
#include <stdio.h> |
37 | 37 |
#include <strings.h> |
38 | 38 |
|
39 |
+char *_km_log_engine_type = NULL; |
|
40 |
+char *_km_log_engine_data = NULL; |
|
41 |
+ |
|
42 |
+km_log_f _km_log_func = &syslog; |
|
43 |
+ |
|
44 |
+/** |
|
45 |
+ * |
|
46 |
+ */ |
|
47 |
+void km_log_func_set(km_log_f f) |
|
48 |
+{ |
|
49 |
+ _km_log_func = f; |
|
50 |
+} |
|
51 |
+ |
|
39 | 52 |
#ifndef NO_SIG_DEBUG |
40 | 53 |
/* signal protection: !=0 when LOG/DBG/... are printing */ |
41 | 54 |
volatile int dprint_crit = 0; |
Added two new debugger params which will support setting per module logging facility.
This is useful when one might want to change logging for a certain module to a different file.
mod_facility_mode (0/1) is used for enabling this. mod_facility (str) is used for
setting the facility.
... | ... |
@@ -103,12 +103,15 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val) |
103 | 103 |
*/ |
104 | 104 |
|
105 | 105 |
/* value for unset local log level */ |
106 |
-#define UNSET_LOCAL_DEBUG_LEVEL -255 |
|
106 |
+#define UNSET_LOCAL_DEBUG_LEVEL -255 |
|
107 |
+#define UNSET_LOCAL_DEBUG_FACILITY -255 |
|
107 | 108 |
|
108 | 109 |
/* the local debug log level */ |
109 | 110 |
static int _local_debug_level = UNSET_LOCAL_DEBUG_LEVEL; |
111 |
+static int _local_debug_facility = UNSET_LOCAL_DEBUG_FACILITY; |
|
110 | 112 |
/* callback to get per module debug level */ |
111 | 113 |
static get_module_debug_level_f _module_debug_level = NULL; |
114 |
+static get_module_debug_facility_f _module_debug_facility = NULL; |
|
112 | 115 |
|
113 | 116 |
/** |
114 | 117 |
* @brief set callback function for per module debug level |
... | ... |
@@ -118,12 +121,17 @@ void set_module_debug_level_cb(get_module_debug_level_f f) |
118 | 121 |
_module_debug_level = f; |
119 | 122 |
} |
120 | 123 |
|
124 |
+void set_module_debug_facility_cb(get_module_debug_facility_f f) |
|
125 |
+{ |
|
126 |
+ _module_debug_facility = f; |
|
127 |
+} |
|
128 |
+ |
|
121 | 129 |
/** |
122 | 130 |
* @brief return the log level - the local one if it set, |
123 | 131 |
* otherwise the global value |
124 | 132 |
*/ |
125 | 133 |
int get_debug_level(char *mname, int mnlen) { |
126 |
- int mlevel = L_DBG; |
|
134 |
+ int mlevel; |
|
127 | 135 |
/*important -- no LOGs inside, because it will loop */ |
128 | 136 |
if(unlikely(_module_debug_level!=NULL && mnlen>0)) { |
129 | 137 |
if(_module_debug_level(mname, mnlen, &mlevel)==0) { |
... | ... |
@@ -134,6 +142,23 @@ int get_debug_level(char *mname, int mnlen) { |
134 | 142 |
_local_debug_level : cfg_get(core, core_cfg, debug); |
135 | 143 |
} |
136 | 144 |
|
145 |
+/** |
|
146 |
+ * @brief return the log facility - the local one if it set, |
|
147 |
+ * otherwise the global value |
|
148 |
+ */ |
|
149 |
+int get_debug_facility(char *mname, int mnlen) { |
|
150 |
+ int mfacility; |
|
151 |
+ /*important -- no LOGs inside, because it will loop */ |
|
152 |
+ if(unlikely(_module_debug_facility!=NULL && mnlen>0)) { |
|
153 |
+ if(_module_debug_facility(mname, mnlen, &mfacility)==0) { |
|
154 |
+ return mfacility; |
|
155 |
+ } |
|
156 |
+ } |
|
157 |
+ return (_local_debug_facility != UNSET_LOCAL_DEBUG_FACILITY) ? |
|
158 |
+ _local_debug_facility : cfg_get(core, core_cfg, log_facility); |
|
159 |
+} |
|
160 |
+ |
|
161 |
+ |
|
137 | 162 |
/** |
138 | 163 |
* @brief set the local debug log level |
139 | 164 |
*/ |
... | ... |
@@ -150,6 +175,22 @@ void reset_local_debug_level(void) |
150 | 175 |
_local_debug_level = UNSET_LOCAL_DEBUG_LEVEL; |
151 | 176 |
} |
152 | 177 |
|
178 |
+/** |
|
179 |
+ * @brief set the local debug log facility |
|
180 |
+ */ |
|
181 |
+void set_local_debug_facility(int facility) |
|
182 |
+{ |
|
183 |
+ _local_debug_facility = facility; |
|
184 |
+} |
|
185 |
+ |
|
186 |
+/** |
|
187 |
+ * @brief reset the local debug log facility |
|
188 |
+ */ |
|
189 |
+void reset_local_debug_facility(void) |
|
190 |
+{ |
|
191 |
+ _local_debug_facility = UNSET_LOCAL_DEBUG_FACILITY; |
|
192 |
+} |
|
193 |
+ |
|
153 | 194 |
typedef struct log_level_color { |
154 | 195 |
char f; |
155 | 196 |
char b; |
- reported by Klaus Darilion
... | ... |
@@ -10,11 +10,6 @@ |
10 | 10 |
* the Free Software Foundation; either version 2 of the License, or |
11 | 11 |
* (at your option) any later version |
12 | 12 |
* |
13 |
- * For a license to use the Kamailio 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 | 13 |
* Kamailio is distributed in the hope that it will be useful, |
19 | 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
... | ... |
@@ -26,7 +21,7 @@ |
26 | 21 |
*/ |
27 | 22 |
/*! |
28 | 23 |
* \file |
29 |
- * \brief SIP-router core :: Debug print |
|
24 |
+ * \brief Kamailio core :: Debug print |
|
30 | 25 |
* \ingroup core |
31 | 26 |
* Module: \ref core |
32 | 27 |
*/ |
... | ... |
@@ -1,24 +1,21 @@ |
1 | 1 |
/* |
2 |
- * $Id$ |
|
3 |
- * |
|
4 | 2 |
* debug print |
5 | 3 |
* |
6 |
- * |
|
7 | 4 |
* Copyright (C) 2001-2003 FhG Fokus |
8 | 5 |
* |
9 |
- * This file is part of ser, a free SIP server. |
|
6 |
+ * This file is part of Kamailio, a free SIP server. |
|
10 | 7 |
* |
11 |
- * ser is free software; you can redistribute it and/or modify |
|
8 |
+ * Kamailio is free software; you can redistribute it and/or modify |
|
12 | 9 |
* it under the terms of the GNU General Public License as published by |
13 | 10 |
* the Free Software Foundation; either version 2 of the License, or |
14 | 11 |
* (at your option) any later version |
15 | 12 |
* |
16 |
- * For a license to use the ser software under conditions |
|
13 |
+ * For a license to use the Kamailio software under conditions |
|
17 | 14 |
* other than those described here, or to purchase support for this |
18 | 15 |
* software, please contact iptel.org by e-mail at the following addresses: |
19 | 16 |
* info@iptel.org |
20 | 17 |
* |
21 |
- * ser is distributed in the hope that it will be useful, |
|
18 |
+ * Kamailio is distributed in the hope that it will be useful, |
|
22 | 19 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 | 20 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24 | 21 |
* GNU General Public License for more details. |
... | ... |
@@ -29,7 +26,7 @@ |
29 | 26 |
*/ |
30 | 27 |
/*! |
31 | 28 |
* \file |
32 |
- * \brief SIP-router core :: |
|
29 |
+ * \brief SIP-router core :: Debug print |
|
33 | 30 |
* \ingroup core |
34 | 31 |
* Module: \ref core |
35 | 32 |
*/ |
... | ... |
@@ -98,8 +98,7 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val) |
98 | 98 |
int i; |
99 | 99 |
|
100 | 100 |
if ((i = str2facility((char *)*val)) == -1) { |
101 |
- LOG(L_ERR, "log_facility_fixup: invalid log facility: %s\n", |
|
102 |
- (char *)*val); |
|
101 |
+ LM_ERR("invalid log facility: %s\n", (char *)*val); |
|
103 | 102 |
return -1; |
104 | 103 |
} |
105 | 104 |
*val = (void *)(long)i; |
- can be used to set what prefix to be printed for each log message
while processing a SIP message
- can contain variables
- example:
log_prefix="[$mt $hdr(CSeq) $ci]"
... | ... |
@@ -38,6 +38,7 @@ |
38 | 38 |
|
39 | 39 |
#include "globals.h" |
40 | 40 |
#include "dprint.h" |
41 |
+#include "pvar.h" |
|
41 | 42 |
|
42 | 43 |
#include <stdarg.h> |
43 | 44 |
#include <stdio.h> |
... | ... |
@@ -368,3 +369,43 @@ void dprint_color_update(int level, char f, char b) |
368 | 369 |
if(f && f!='0') _log_level_colors[level - L_MIN].f = f; |
369 | 370 |
if(b && b!='0') _log_level_colors[level - L_MIN].b = b; |
370 | 371 |
} |
372 |
+ |
|
373 |
+ |
|
374 |
+/* log_prefix functionality */ |
|
375 |
+str *log_prefix_val = NULL; |
|
376 |
+static pv_elem_t *log_prefix_pvs = NULL; |
|
377 |
+ |
|
378 |
+#define LOG_PREFIX_SIZE 128 |
|
379 |
+static char log_prefix_buf[LOG_PREFIX_SIZE]; |
|
380 |
+static str log_prefix_str; |
|
381 |
+ |
|
382 |
+void log_prefix_init(void) |
|
383 |
+{ |
|
384 |
+ str s; |
|
385 |
+ if(log_prefix_fmt==NULL) |
|
386 |
+ return; |
|
387 |
+ s.s = log_prefix_fmt; s.len = strlen(s.s); |
|
388 |
+ |
|
389 |
+ if(pv_parse_format(&s, &log_prefix_pvs)<0) |
|
390 |
+ { |
|
391 |
+ LM_ERR("wrong format[%s]\n", s.s); |
|
392 |
+ return; |
|
393 |
+ } |
|
394 |
+} |
|
395 |
+ |
|
396 |
+void log_prefix_set(sip_msg_t *msg) |
|
397 |
+{ |
|
398 |
+ if(log_prefix_pvs == NULL) |
|
399 |
+ return; |
|
400 |
+ if(msg==NULL) { |
|
401 |
+ log_prefix_val = NULL; |
|
402 |
+ return; |
|
403 |
+ } |
|
404 |
+ log_prefix_str.s = log_prefix_buf; |
|
405 |
+ log_prefix_str.len = LOG_PREFIX_SIZE; |
|
406 |
+ if(pv_printf(msg, log_prefix_pvs, log_prefix_str.s, &log_prefix_str.len)<0) |
|
407 |
+ return; |
|
408 |
+ if(log_prefix_str.len<=0) |
|
409 |
+ return; |
|
410 |
+ log_prefix_val = &log_prefix_str; |
|
411 |
+} |
... | ... |
@@ -25,7 +25,7 @@ |
25 | 25 |
* |
26 | 26 |
* You should have received a copy of the GNU General Public License |
27 | 27 |
* along with this program; if not, write to the Free Software |
28 |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
28 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
29 | 29 |
*/ |
30 | 30 |
/*! |
31 | 31 |
* \file |
- a callback can be registered to return the log level based on module
name
... | ... |
@@ -115,12 +115,29 @@ int log_facility_fixup(void *handle, str *gname, str *name, void **val) |
115 | 115 |
|
116 | 116 |
/* the local debug log level */ |
117 | 117 |
static int _local_debug_level = UNSET_LOCAL_DEBUG_LEVEL; |
118 |
+/* callback to get per module debug level */ |
|
119 |
+static get_module_debug_level_f _module_debug_level = NULL; |
|
120 |
+ |
|
121 |
+/** |
|
122 |
+ * @brief set callback function for per module debug level |
|
123 |
+ */ |
|
124 |
+void set_module_debug_level_cb(get_module_debug_level_f f) |
|
125 |
+{ |
|
126 |
+ _module_debug_level = f; |
|
127 |
+} |
|
118 | 128 |
|
119 | 129 |
/** |
120 | 130 |
* @brief return the log level - the local one if it set, |
121 | 131 |
* otherwise the global value |
122 | 132 |
*/ |
123 |
-int get_debug_level(void) { |
|
133 |
+int get_debug_level(char *mname, int mnlen) { |
|
134 |
+ int mlevel = L_DBG; |
|
135 |
+ /*important -- no LOGs inside, because it will loop */ |
|
136 |
+ if(unlikely(_module_debug_level!=NULL && mnlen>0)) { |
|
137 |
+ if(_module_debug_level(mname, mnlen, &mlevel)==0) { |
|
138 |
+ return mlevel; |
|
139 |
+ } |
|
140 |
+ } |
|
124 | 141 |
return (_local_debug_level != UNSET_LOCAL_DEBUG_LEVEL) ? |
125 | 142 |
_local_debug_level : cfg_get(core, core_cfg, debug); |
126 | 143 |
} |
... | ... |
@@ -343,3 +343,11 @@ void dprint_color_reset(void) |
343 | 343 |
dprint_term_color('x', 'x', &obuf); |
344 | 344 |
fprintf(stderr, "%.*s", obuf.len, obuf.s); |
345 | 345 |
} |
346 |
+ |
|
347 |
+void dprint_color_update(int level, char f, char b) |
|
348 |
+{ |
|
349 |
+ if(level<L_MIN || level>L_MAX) |
|
350 |
+ return; |
|
351 |
+ if(f && f!='0') _log_level_colors[level - L_MIN].f = f; |
|
352 |
+ if(b && b!='0') _log_level_colors[level - L_MIN].b = b; |
|
353 |
+} |
- used only when log messages are printed to stderr
- each log level is printed in different color, using term colors (like
$C(xy) variable)
... | ... |
@@ -140,3 +140,206 @@ void reset_local_debug_level(void) |
140 | 140 |
{ |
141 | 141 |
_local_debug_level = UNSET_LOCAL_DEBUG_LEVEL; |
142 | 142 |
} |
143 |
+ |
|
144 |
+typedef struct log_level_color { |
|
145 |
+ char f; |
|
146 |
+ char b; |
|
147 |
+} log_level_color_t; |
|
148 |
+ |
|
149 |
+log_level_color_t _log_level_colors[L_MAX - L_MIN + 1]; |
|
150 |
+ |
|
151 |
+void dprint_init_colors(void) |
|
152 |
+{ |
|
153 |
+ int i; |
|
154 |
+ |
|
155 |
+ i = 0; |
|
156 |
+ |
|
157 |
+ memset(_log_level_colors, 0, |
|
158 |
+ (L_MAX - L_MIN + 1)*sizeof(log_level_color_t)); |
|
159 |
+ |
|
160 |
+ /* L_ALERT */ |
|
161 |
+ _log_level_colors[i].f = 'R'; /* default */ |
|
162 |
+ _log_level_colors[i].b = 'x'; /* default */ |
|
163 |
+ i++; |
|
164 |
+ |
|
165 |
+ /* L_BUG */ |
|
166 |
+ _log_level_colors[i].f = 'P'; /* default */ |
|
167 |
+ _log_level_colors[i].b = 'x'; /* default */ |
|
168 |
+ i++; |
|
169 |
+ |
|
170 |
+ /* L_CRIT2 */ |
|
171 |
+ _log_level_colors[i].f = 'y'; /* default */ |
|
172 |
+ _log_level_colors[i].b = 'x'; /* default */ |
|
173 |
+ i++; |
|
174 |
+ |
|
175 |
+ /* L_CRIT */ |
|
176 |
+ _log_level_colors[i].f = 'b'; /* default */ |
|
177 |
+ _log_level_colors[i].b = 'x'; /* default */ |
|
178 |
+ i++; |
|
179 |
+ |
|
180 |
+ /* L_ERR */ |
|
181 |
+ _log_level_colors[i].f = 'r'; /* default */ |
|
182 |
+ _log_level_colors[i].b = 'x'; /* default */ |
|
183 |
+ i++; |
|
184 |
+ |
|
185 |
+ /* L_WARN */ |
|
186 |
+ _log_level_colors[i].f = 'p'; /* default */ |
|
187 |
+ _log_level_colors[i].b = 'x'; /* default */ |
|
188 |
+ i++; |
|
189 |
+ |
|
190 |
+ /* L_NOTICE */ |
|
191 |
+ _log_level_colors[i].f = 'g'; /* default */ |
|
192 |
+ _log_level_colors[i].b = 'x'; /* default */ |
|
193 |
+ i++; |
|
194 |
+ |
|
195 |
+ /* L_INFO */ |
|
196 |
+ _log_level_colors[i].f = 'c'; /* default */ |
|
197 |
+ _log_level_colors[i].b = 'x'; /* default */ |
|
198 |
+ i++; |
|
199 |
+ |
|
200 |
+ /* L_DBG */ |
|
201 |
+ _log_level_colors[i].f = 'x'; /* default */ |
|
202 |
+ _log_level_colors[i].b = 'x'; /* default */ |
|
203 |
+ i++; |
|
204 |
+} |
|
205 |
+ |
|
206 |
+#define TERM_COLOR_SIZE 16 |
|
207 |
+ |
|
208 |
+#define dprint_termc_add(p, end, s) \ |
|
209 |
+ do{ \ |
|
210 |
+ if ((p)+(sizeof(s)-1)<=(end)){ \ |
|
211 |
+ memcpy((p), s, sizeof(s)-1); \ |
|
212 |
+ (p)+=sizeof(s)-1; \ |
|
213 |
+ }else{ \ |
|
214 |
+ /* overflow */ \ |
|
215 |
+ LM_ERR("dprint_termc_add overflow\n"); \ |
|
216 |
+ goto error; \ |
|
217 |
+ } \ |
|
218 |
+ } while(0) |
|
219 |
+ |
|
220 |
+ |
|
221 |
+void dprint_term_color(char f, char b, str *obuf) |