Debian Codegraph @

src/modules/xlog/README

raw
1 xlog Module
2
3 Elena-Ramona Modroiu
4
5 rosdev.ro
6 <[email protected]>
7
8 Edited by
9
10 Elena-Ramona Modroiu
11
12 <[email protected]>
13
14 Copyright © 2003 FhG FOKUS
15
16 Copyright © 2008-2010 Elena-Ramona Modroiu
17 __________________________________________________________________
18
19 Table of Contents
20
21 1. Admin Guide
22
23 1. Overview
24 2. Implemented Specifiers
25 3. Dependencies
26
27 3.1. Kamailio Modules
28 3.2. External Libraries or Applications
29
30 4. Parameters
31
32 4.1. buf_size (integer)
33 4.2. force_color (integer)
34 4.3. long_format (integer)
35 4.4. prefix (str)
36 4.5. prefix_mode (str)
37 4.6. log_facility (string)
38 4.7. log_colors (string)
39 4.8. methods_filter (int)
40
41 5. Functions
42
43 5.1. xlog([ [facility,] level,] format)
44 5.2. xdbg(format)
45 5.3. xinfo(format)
46 5.4. xnotice(format)
47 5.5. xwarn(format)
48 5.6. xerr(format)
49 5.7. xbug(format)
50 5.8. xcrit(format)
51 5.9. xalert(format)
52 5.10. xlogl([ [facility,] level,] format)
53 5.11. xdbgl(format)
54 5.12. xlogm(level, format)
55
56 List of Examples
57
58 1.1. Set buf_size parameter
59 1.2. Set force_color parameter
60 1.3. Set long_format parameter
61 1.4. Set prefix parameter
62 1.5. Set prefix_mode parameter
63 1.6. log_facility example
64 1.7. log_colors example
65 1.8. Set methods_filter parameter
66 1.9. xlog usage
67 1.10. xdbg usage
68 1.11. xinfo usage
69 1.12. xnotice usage
70 1.13. xwarn usage
71 1.14. xerr usage
72 1.15. xbug usage
73 1.16. xcrit usage
74 1.17. xalert usage
75
76 Chapter 1. Admin Guide
77
78 Table of Contents
79
80 1. Overview
81 2. Implemented Specifiers
82 3. Dependencies
83
84 3.1. Kamailio Modules
85 3.2. External Libraries or Applications
86
87 4. Parameters
88
89 4.1. buf_size (integer)
90 4.2. force_color (integer)
91 4.3. long_format (integer)
92 4.4. prefix (str)
93 4.5. prefix_mode (str)
94 4.6. log_facility (string)
95 4.7. log_colors (string)
96 4.8. methods_filter (int)
97
98 5. Functions
99
100 5.1. xlog([ [facility,] level,] format)
101 5.2. xdbg(format)
102 5.3. xinfo(format)
103 5.4. xnotice(format)
104 5.5. xwarn(format)
105 5.6. xerr(format)
106 5.7. xbug(format)
107 5.8. xcrit(format)
108 5.9. xalert(format)
109 5.10. xlogl([ [facility,] level,] format)
110 5.11. xdbgl(format)
111 5.12. xlogm(level, format)
112
113 1. Overview
114
115 This module provides the possibility to print user formatted log or
116 debug messages from Kamailio scripts, similar to the printf function. A
117 C-style printf specifier is replaced with a part of the SIP request or
118 other variables from system.
119
120 2. Implemented Specifiers
121
122 In the xlog function, you use pseudo-variables, that are a part of
123 Kamailio core and are used by other modules as well (e.g., avpops in
124 the function avp_printf())
125
126 The most important changes from earlier versions of Kamailio are:
127 * - '%' has been replaced by '$'
128 * - to print a header, use $hdr(header_name[index]) instead of
129 %{header_name[index]}
130 * - to print an AVP, use now $avp([si]:avp_id[index]) instead of
131 %{[si]:avp_id[index]} or $avp([$avp_alias[index]) instead of
132 %{[$avp_alias[index]}
133
134 The full list of available pseudo-variables in Kamailio is available
135 at: https://www.kamailio.org/wikidocs/
136
137 3. Dependencies
138
139 3.1. Kamailio Modules
140 3.2. External Libraries or Applications
141
142 3.1. Kamailio Modules
143
144 The following modules must be loaded before this module:
145 * No dependencies on other Kamailio modules. Note that many modules
146 publish pseudovariables that you can use in this module. The core
147 module for this is the pv module.
148
149 3.2. External Libraries or Applications
150
151 The following libraries or applications must be installed before
152 running Kamailio with this module loaded:
153 * None.
154
155 4. Parameters
156
157 4.1. buf_size (integer)
158 4.2. force_color (integer)
159 4.3. long_format (integer)
160 4.4. prefix (str)
161 4.5. prefix_mode (str)
162 4.6. log_facility (string)
163 4.7. log_colors (string)
164 4.8. methods_filter (int)
165
166 4.1. buf_size (integer)
167
168 Maximum size of the log message.
169
170 Default value is 4096.
171
172 Example 1.1. Set buf_size parameter
173 ...
174 modparam("xlog", "buf_size", 8192)
175 ...
176
177 4.2. force_color (integer)
178
179 When set to 1, forces color codes in log messages even if log_stderror
180 is set to 0.
181
182 Default value is 0.
183
184 Example 1.2. Set force_color parameter
185 ...
186 modparam("xlog", "force_color", 0)
187 ...
188
189 4.3. long_format (integer)
190
191 When set to 1, outputs the configuration file name in xlogl() and
192 xdbgl() before the line number.
193
194 Default value is 0.
195
196 Example 1.3. Set long_format parameter
197 ...
198 modparam("xlog", "long_format", 1)
199 ...
200
201 4.4. prefix (str)
202
203 Prefix to be output before the log message.
204
205 Default value is "<script>: ".
206
207 Example 1.4. Set prefix parameter
208 ...
209 modparam("xlog", "prefix", "-xlog: ")
210 ...
211
212 4.5. prefix_mode (str)
213
214 control behaviour of prefix value. if mode = 0 then prefix is treated
215 as string (current behaviour). if mode = 1 then prefix is treated as
216 pv_format specifier and value will be evaluated before output.
217
218 Default value is 0.
219
220 Example 1.5. Set prefix_mode parameter
221 ...
222 modparam("xlog", "prefix", "$cfg(name):$cfg(line)")
223 modparam("xlog", "prefix_mode", 1)
224 ...
225
226 4.6. log_facility (string)
227
228 Syslog facility to be used for the xlog output. By setting this, and
229 configuring syslog, you can get the xlog messages in a separate syslog
230 file than the debug messages issued from the source code.
231
232 Default value is NULL (unset - use same facility as source code debug
233 messages).
234
235 Example 1.6. log_facility example
236 modparam("xlog", "log_facility", "LOG_DAEMON")
237
238 4.7. log_colors (string)
239
240 Update terminal colors used by the Kamailio core for log levels (when
241 log_stderr=1 and log_color=1). The value has to be 'logname=colors',
242 where colors is two characters specifying foreground and background in
243 the same format as $C(xy) variable.
244
245 The parameter can be set many times. The value can also be a
246 ';'-separated list of color specifications.
247
248 Default value is NULL.
249
250 Example 1.7. log_colors example
251 modparam("xlog", "log_colors", "L_ERR=cr")
252 modparam("xlog", "log_colors", "L_ERR=cr;L_WARN=px")
253
254 4.8. methods_filter (int)
255
256 The bitmask with internal SIP method ids to be ignored by xlogm()
257 function. The value can be changed at runtime via cfg reload framework:
258 ...
259 kamctl rpc cfg.set_now_int xlog methods_filter 15
260 ...
261
262 To see the associated internal ids for SIP requests, look in source
263 tree inside parser/msg_parser.h for enum request_method.
264
265 Default value is -1 (all SIP methods are ignored).
266
267 Example 1.8. Set methods_filter parameter
268 ...
269 modparam("xlog", "methods_filter", 15)
270 ...
271
272 5. Functions
273
274 5.1. xlog([ [facility,] level,] format)
275 5.2. xdbg(format)
276 5.3. xinfo(format)
277 5.4. xnotice(format)
278 5.5. xwarn(format)
279 5.6. xerr(format)
280 5.7. xbug(format)
281 5.8. xcrit(format)
282 5.9. xalert(format)
283 5.10. xlogl([ [facility,] level,] format)
284 5.11. xdbgl(format)
285 5.12. xlogm(level, format)
286
287 5.1. xlog([ [facility,] level,] format)
288
289 Output a formatted log message.
290
291 Meaning of the parameters are as follows:
292 * facility - The syslog facility that will be used for this single
293 log message.
294 If this parameter is missing, the implicit facility is either the
295 facility set with the 'log_facility' module parameter or the core's
296 log facility.
297 * level - The level that will be used in LOG function. It can be:
298 + L_ALERT - log level -5
299 + L_BUG - log level -4
300 + L_CRIT - log level -3
301 + L_ERR - log level -1
302 + L_WARN - log level 0
303 + L_NOTICE - log level 1
304 + L_INFO - log level 2
305 + L_DBG - log level 3
306 + $pv - any valid pseudo-variable, that has an integer value.
307 See above options for valid log levels.
308 If it is not a pseudo-variable, then what really matters is the
309 third letter of the value. If the log level is higher than the
310 “debug” global parameter, the message is not printed to syslog.
311 If this parameter is missing, the implicit log level is 'L_ERR'.
312 * format - The formatted string to be printed.
313
314 This function can be used from ANY_ROUTE.
315
316 Example 1.9. xlog usage
317 ...
318 xlog("L_ERR", "time [$Tf] method ($rm) r-uri ($ru) 2nd via ($hdr(via[1]))\n");
319 ...
320 xlog("time [$Tf] method ($rm) r-uri ($ru) 2nd via ($hdr(via[1]))\n");
321 ...
322 $var(loglevel) = 2;
323 xlog("$var(loglevel)", "time [$Tf] method ($rm) r-uri ($ru)\n");
324 ...
325 xlog("LOG_LOCAL3", "L_ERR", "this message will be sent to syslog facility LOG_LO
326 CAL3\n");
327 ...
328
329 5.2. xdbg(format)
330
331 Print a formatted message using DBG function.
332
333 Meaning of the parameters is as follows:
334 * format - The formatted string to be printed.
335
336 This function can be used from ANY_ROUTE.
337
338 Example 1.10. xdbg usage
339 ...
340 xdbg("time $Cbx[$Tf]$Cxx method ($rm) r-uri ($ru)\n");
341 ...
342
343 5.3. xinfo(format)
344
345 Print a formatted log message at L_INFO level.
346
347 Meaning of the parameters is as follows:
348 * format - The formatted string to be printed.
349
350 This function can be used from ANY_ROUTE.
351
352 Example 1.11. xinfo usage
353 ...
354 xinfo("time $Cbx[$Tf]$Cxx method ($rm) r-uri ($ru)\n");
355 ...
356
357 5.4. xnotice(format)
358
359 Print a formatted log message at L_NOTICE level.
360
361 Meaning of the parameters is as follows:
362 * format - The formatted string to be printed.
363
364 This function can be used from ANY_ROUTE.
365
366 Example 1.12. xnotice usage
367 ...
368 xnotice("time $Cbx[$Tf]$Cxx method ($rm) r-uri ($ru)\n");
369 ...
370
371 5.5. xwarn(format)
372
373 Print a formatted log message at L_WARN level.
374
375 Meaning of the parameters is as follows:
376 * format - The formatted string to be printed.
377
378 This function can be used from ANY_ROUTE.
379
380 Example 1.13. xwarn usage
381 ...
382 xwarn("time $Cbx[$Tf]$Cxx method ($rm) r-uri ($ru)\n");
383 ...
384
385 5.6. xerr(format)
386
387 Print a formatted log message at L_ERR level.
388
389 Meaning of the parameters is as follows:
390 * format - The formatted string to be printed.
391
392 This function can be used from ANY_ROUTE.
393
394 Example 1.14. xerr usage
395 ...
396 xerr("time $Cbx[$Tf]$Cxx method ($rm) r-uri ($ru)\n");
397 ...
398
399 5.7. xbug(format)
400
401 Print a formatted log message at L_BUG level.
402
403 Meaning of the parameters is as follows:
404 * format - The formatted string to be printed.
405
406 This function can be used from ANY_ROUTE.
407
408 Example 1.15. xbug usage
409 ...
410 xbug("time $Cbx[$Tf]$Cxx method ($rm) r-uri ($ru)\n");
411 ...
412
413 5.8. xcrit(format)
414
415 Print a formatted log message at L_CRIT level.
416
417 Meaning of the parameters is as follows:
418 * format - The formatted string to be printed.
419
420 This function can be used from ANY_ROUTE.
421
422 Example 1.16. xcrit usage
423 ...
424 xcrit("time $Cbx[$Tf]$Cxx method ($rm) r-uri ($ru)\n");
425 ...
426
427 5.9. xalert(format)
428
429 Print a formatted log message at L_ALERT level.
430
431 Meaning of the parameters is as follows:
432 * format - The formatted string to be printed.
433
434 This function can be used from ANY_ROUTE.
435
436 Example 1.17. xalert usage
437 ...
438 xalert("time $Cbx[$Tf]$Cxx method ($rm) r-uri ($ru)\n");
439 ...
440
441 5.10. xlogl([ [facility,] level,] format)
442
443 Similar to xlog(), in addition prints configuration file line number at
444 the beginning of message.
445
446 5.11. xdbgl(format)
447
448 Similar to xdbg(), in addition prints configuration file line number at
449 the beginning of message.
450
451 5.12. xlogm(level, format)
452
453 Similar to xlog(level, format), but skips writing the log messages for
454 SIP requests and responses that match the SIP method id with
455 methods_filter parameter value.