1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
|
<?xml version="1.0" encoding='ISO-8859-1'?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
<!-- Include general documentation entities -->
<!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
%docentities;
]>
<!-- Module User's Guide -->
<chapter>
<title>&adminguide;</title>
<section>
<title>Overview</title>
<para>
This module provides the possibility to print user formatted log or
debug messages from &kamailio; scripts, similar to the printf function.
A C-style printf specifier is replaced with a part of the &sip; request or other
variables from system.
<xref linkend="sec-implemented-specifiers"/> shows what can be printed
out.
</para>
</section>
<section id="sec-implemented-specifiers">
<title>Implemented Specifiers</title>
<para>
In the xlog function, you use pseudo-variables, that are a part
of &kamailio; core and are used by other modules as well (e.g., <emphasis>avpops</emphasis>
in the function <function>avp_printf()</function>)
</para>
<para>
The most important changes from earlier versions of &kamailio; are:
</para>
<itemizedlist>
<listitem>
<para>
- '%' has been replaced by '$'
</para>
</listitem>
<listitem>
<para>
- to print a header, use now $hdr(header_name[index]) instead of
%{header_name[index]}
</para>
</listitem>
<listitem>
<para>
- to print an AVP, use now $avp([si]:avp_id[index]) instead of
%{[si]:avp_id[index]} or $avp([$avp_alias[index]) instead of
%{[$avp_alias[index]}
</para>
</listitem>
</itemizedlist>
<para>
The full list of available pseudo-variables in &kamailio; is
available at:
<ulink url="http://kamailio.org/wiki/">
http://kamailio.org/wiki/</ulink>
</para>
</section>
<section>
<title>Dependencies</title>
<section>
<title>&kamailio; Modules</title>
<para>
The following modules must be loaded before this module:
<itemizedlist>
<listitem>
<para>
<emphasis>No dependencies on other &kamailio; modules</emphasis>.
</para>
</listitem>
</itemizedlist>
</para>
</section>
<section>
<title>External Libraries or Applications</title>
<para>
The following libraries or applications must be installed before running
&kamailio; with this module loaded:
<itemizedlist>
<listitem>
<para>
<emphasis>None</emphasis>.
</para>
</listitem>
</itemizedlist>
</para>
</section>
</section>
<section>
<title>Parameters</title>
<section id="xlog.p.buf_size">
<title><varname>buf_size</varname> (integer)</title>
<para>
Maximum size of the log message.
</para>
<para>
<emphasis>
Default value is 4096.
</emphasis>
</para>
<example>
<title>Set <varname>buf_size</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("xlog", "buf_size", 8192)
...
</programlisting>
</example>
</section>
<section id="xlog.p.force_color">
<title><varname>force_color</varname> (integer)</title>
<para>
When set to 1, forces color printing even if log_stderror=0.
</para>
<para>
<emphasis>
Default value is 0.
</emphasis>
</para>
<example>
<title>Set <varname>force_color</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("xlog", "force_color", 0)
...
</programlisting>
</example>
</section>
<section id="xlog.p.long_format">
<title><varname>long_format</varname> (integer)</title>
<para>
When set to 1, prints config file name in xlogl() and xdbgl()
before line number.
</para>
<para>
<emphasis>
Default value is 0.
</emphasis>
</para>
<example>
<title>Set <varname>long_format</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("xlog", "long_format", 1)
...
</programlisting>
</example>
</section>
<section id="xlog.p.varname">
<title><varname>prefix</varname> (str)</title>
<para>
Prefix to be printed before the log message.
</para>
<para>
<emphasis>
Default value is "<script>: ".
</emphasis>
</para>
<example>
<title>Set <varname>prefix</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("xlog", "prefix", "-xlog: ")
...
</programlisting>
</example>
</section>
<section id="xlog.p.log_facility">
<title><varname>log_facility</varname> (string)</title>
<para>
Syslog facility to be used when printing xlog messages.
In this way you can get the xlog messages in a separate syslog file
than the debug messages issued from source code.
</para>
<para>
Default value is NULL (unset - use same facility as source code debug
messages).
</para>
<example>
<title>log_facility example</title>
<programlisting format="linespecific">
modparam("xlog", "log_facility", "LOG_DAEMON")
</programlisting>
</example>
</section>
<section id="xlog.p.log_colors">
<title><varname>log_colors</varname> (string)</title>
<para>
Update terminal colors used by core for log levels (when log_stderr=1
and log_color=1). The value has to be 'logname=colors', where colors
is two characters specifying foreground and background in the same
format as $C(xy) variable.
</para>
<para>
The parameter can be set many times, its value can also be a
';'-separated list of color specs.
</para>
<para>
Default value is NULL.
</para>
<example>
<title>log_colors example</title>
<programlisting format="linespecific">
modparam("xlog", "log_colors", "L_ERR=cr")
modparam("xlog", "log_colors", "L_ERR=cr;L_WARN=px")
</programlisting>
</example>
</section>
</section>
<section>
<title>Functions</title>
<section id="xlog.f.xlog">
<title>
<function moreinfo="none">xlog([ [facility,] level,] format)</function>
</title>
<para>
Print a formated message using LOG function.
</para>
<para>Meaning of the parameters are as follows:</para>
<itemizedlist>
<listitem>
<para><emphasis>facility</emphasis> - The log facility that will be used for this single log message.
</para>
<para>
If this parameter is missing, the implicit facility is either the facility set with
the 'log_facility' module parameter or the core's log facility.
</para>
</listitem>
<listitem>
<para><emphasis>level</emphasis> - The level that will be used in LOG function. It can be:
</para>
<itemizedlist>
<listitem>
<para>
L_ALERT - log level -5
</para>
</listitem>
<listitem>
<para>
L_BUG - log level -4
</para>
</listitem>
<listitem>
<para>
L_CRIT - log level -3
</para>
</listitem>
<listitem>
<para>
L_ERR - log level -1
</para>
</listitem>
<listitem>
<para>
L_WARN - log level 0
</para>
</listitem>
<listitem>
<para>
L_NOTICE - log level 1
</para>
</listitem>
<listitem>
<para>
L_INFO - log level 2
</para>
</listitem>
<listitem>
<para>
L_DBG - log level 3
</para>
</listitem>
<listitem>
<para>
$pv - any valid pseudo-variable, that has an integer value.
See above options for valid log levels.
</para>
</listitem>
</itemizedlist>
<para>
If it is not a pseudo-variable, then what really matters is the
third letter of the value. If the log level is higher than the
<quote>debug</quote> global parameter, the message is not printed
to syslog.
</para>
<para>
If this parameter is missing, the implicit log level is 'L_ERR'.
</para>
</listitem>
<listitem>
<para><emphasis>format</emphasis> - The formatted string to be printed.
</para>
</listitem>
</itemizedlist>
<para>
This function can be used from ANY_ROUTE.
</para>
<example>
<title><function>xlog</function> usage</title>
<programlisting format="linespecific">
...
xlog("L_ERR", "time [$Tf] method ($rm) r-uri ($ru) 2nd via ($hdr(via[1]))\n");
...
xlog("time [$Tf] method ($rm) r-uri ($ru) 2nd via ($hdr(via[1]))\n");
...
$var(loglevel) = 2;
xlog("$var(loglevel)", "time [$Tf] method ($rm) r-uri ($ru)\n");
...
xlog("LOG_LOCAL3", "L_ERR", "this message will be sent to syslog facility LOG_LOCAL3\n");
...
</programlisting>
</example>
</section>
<section id="xlog.f.xdbg">
<title>
<function moreinfo="none">xdbg(format)</function>
</title>
<para>
Print a formatted message using DBG function.
</para>
<para>Meaning of the parameters is as follows:</para>
<itemizedlist>
<listitem>
<para><emphasis>format</emphasis> - The formatted string to be printed.
</para>
</listitem>
</itemizedlist>
<para>
This function can be used from ANY_ROUTE.
</para>
<example>
<title><function>xdbg</function> usage</title>
<programlisting format="linespecific">
...
xdbg("time $Cbx[$Tf]$Cxx method ($rm) r-uri ($ru)\n");
...
</programlisting>
</example>
</section>
<section id="xlog.f.xlogl">
<title>
<function moreinfo="none">xlogl([ [facility,] level,] format)</function>
</title>
<para>
Similar to xlog(), in addition prints configuration file line number
at the beginning of message.
</para>
</section>
<section id="xlog.f.xdbgl">
<title>
<function moreinfo="none">xdbgl(format)</function>
</title>
<para>
Similar to xdbg(), in addition prints configuration file line number
at the beginning of message.
</para>
</section>
</section>
</chapter>
|