source: yaz/trunk/fuentes/doc/tools.log.html @ 265

Last change on this file since 265 was 265, checked in by mabarracus, 4 years ago

Add new source code 5.15.2

File size: 8.4 KB
Line 
1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>4. Log</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="YAZ User's Guide and Reference"><link rel="up" href="tools.html" title="Chapter 7. Supporting Tools"><link rel="prev" href="tools.nmem.html" title="3. Nibble Memory"><link rel="next" href="marc.html" title="5. MARC"></head><body><link rel="stylesheet" type="text/css" href="common/style1.css"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">4. Log</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="tools.nmem.html">Prev</a> </td><th width="60%" align="center">Chapter 7. Supporting Tools</th><td width="20%" align="right"> <a accesskey="n" href="marc.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="tools.log"></a>4. Log</h2></div></div></div><p>
2    YAZ has evolved a fairly complex log system which should be useful both
3    for debugging YAZ itself, debugging applications that use YAZ, and for
4    production use of those applications.
5   </p><p>
6    The log functions are declared in header <code class="filename">yaz/log.h</code>
7    and implemented in <code class="filename">src/log.c</code>.
8    Due to name clash with syslog and some math utilities the logging
9    interface has been modified as of YAZ 2.0.29. The obsolete interface
10    is still available in header file <code class="filename">yaz/log.h</code>.
11    The key points of the interface are:
12   </p><pre class="screen">
13    void yaz_log(int level, const char *fmt, ...)
14    void yaz_log_init(int level, const char *prefix, const char *name);
15    void yaz_log_init_file(const char *fname);
16    void yaz_log_init_level(int level);
17    void yaz_log_init_prefix(const char *prefix);
18    void yaz_log_time_format(const char *fmt);
19    void yaz_log_init_max_size(int mx);
20
21    int yaz_log_mask_str(const char *str);
22    int yaz_log_module_level(const char *name);
23   </pre><p>
24    The reason for the whole log module is the <code class="function">yaz_log</code>
25    function. It takes a bitmask indicating the log levels, a
26    <code class="literal">printf</code>-like format string, and a variable number of
27    arguments to log.
28   </p><p>
29    The <code class="literal">log level</code> is a bit mask, that says on which level(s)
30    the log entry should be made, and optionally set some behaviour of the
31    logging. In the most simple cases, it can be one of <code class="literal">YLOG_FATAL,
32    YLOG_DEBUG, YLOG_WARN, YLOG_LOG</code>. Those can be combined with bits
33    that modify the way the log entry is written:<code class="literal">YLOG_ERRNO,
34    YLOG_NOTIME, YLOG_FLUSH</code>.
35    Most of the rest of the bits are deprecated, and should not be used. Use
36    the dynamic log levels instead.
37   </p><p>
38    Applications that use YAZ, should not use the LOG_LOG for ordinary
39    messages, but should make use of the dynamic loglevel system. This consists
40    of two parts, defining the loglevel and checking it.
41   </p><p>
42    To define the log levels, the (main) program should pass a string to
43    <code class="function">yaz_log_mask_str</code> to define which log levels are to be
44    logged. This string should be a comma-separated list of log level names,
45    and can contain both hard-coded names and dynamic ones. The log level
46    calculation starts with <code class="literal">YLOG_DEFAULT_LEVEL</code> and adds a bit
47    for each word it meets, unless the word starts with a '-', in which case it
48    clears the bit. If the string <code class="literal">'none'</code> is found,
49    all bits are cleared. Typically this string comes from the command-line,
50    often identified by <code class="literal">-v</code>. The
51    <code class="function">yaz_log_mask_str</code> returns a log level that should be
52    passed to <code class="function">yaz_log_init_level</code> for it to take effect.
53   </p><p>
54    Each module should check what log bits should be used, by calling
55    <code class="function">yaz_log_module_level</code> with a suitable name for the
56    module. The name is cleared of a preceding path and an extension, if any,
57    so it is quite possible to use <code class="literal">__FILE__</code> for it. If the
58    name has been passed to <code class="function">yaz_log_mask_str</code>, the routine
59    returns a non-zero bitmask, which should then be used in consequent calls
60    to yaz_log. (It can also be tested, so as to avoid unnecessary calls to
61    yaz_log, in time-critical places, or when the log entry would take time
62    to construct.)
63   </p><p>
64    Yaz uses the following dynamic log levels:
65    <code class="literal">server, session, request, requestdetail</code> for the server
66    functionality.
67    <code class="literal">zoom</code> for the zoom client api.
68    <code class="literal">ztest</code> for the simple test server.
69    <code class="literal">malloc, nmem, odr, eventl</code> for internal
70    debugging of yaz itself.
71    Of course, any program using yaz is welcome to define as many new
72    ones as it needs.
73   </p><p>
74    By default the log is written to stderr, but this can be changed by a call
75    to <code class="function">yaz_log_init_file</code> or
76    <code class="function">yaz_log_init</code>. If the log is directed to a file, the
77    file size is checked at every write, and if it exceeds the limit given in
78    <code class="function">yaz_log_init_max_size</code>, the log is rotated. The
79    rotation keeps one old version (with a <code class="literal">.1</code> appended to
80    the name). The size defaults to 1GB. Setting it to zero will disable the
81    rotation feature.
82   </p><pre class="screen">
83    A typical yaz-log looks like this
84  13:23:14-23/11 yaz-ztest(1) [session] Starting session from tcp:127.0.0.1 (pid=30968)
85  13:23:14-23/11 yaz-ztest(1) [request] Init from 'YAZ' (81) (ver 2.0.28) OK
86  13:23:17-23/11 yaz-ztest(1) [request] Search Z: @attrset Bib-1 foo  OK:7 hits
87  13:23:22-23/11 yaz-ztest(1) [request] Present: [1] 2+2  OK 2 records returned
88  13:24:13-23/11 yaz-ztest(1) [request] Close OK
89   </pre><p>
90    The log entries start with a time stamp. This can be omitted by setting the
91    <code class="literal">YLOG_NOTIME</code> bit in the loglevel. This way automatic tests
92    can be hoped to produce identical log files, that are easy to diff. The
93    format of the time stamp can be set with
94    <code class="function">yaz_log_time_format</code>, which takes a format string just
95    like <code class="function">strftime</code>.
96   </p><p>
97    Next in a log line comes the prefix, often the name of the program. For
98    yaz-based servers, it can also contain the session number. Then
99    comes one or more logbits in square brackets, depending on the logging
100    level set by <code class="function">yaz_log_init_level</code> and the loglevel
101    passed to <code class="function">yaz_log_init_level</code>. Finally comes the format
102    string and additional values passed to <code class="function">yaz_log</code>
103   </p><p>
104    The log level <code class="literal">YLOG_LOGLVL</code>, enabled by the string
105    <code class="literal">loglevel</code>, will log all the log-level affecting
106    operations. This can come in handy if you need to know what other log
107    levels would be useful. Grep the logfile for <code class="literal">[loglevel]</code>.
108   </p><p>
109    The log system is almost independent of the rest of YAZ, the only
110    important dependence is of <code class="filename">nmem</code>, and that only for
111    using the semaphore definition there.
112   </p><p>
113    The dynamic log levels and log rotation were introduced in YAZ 2.0.28. At
114    the same time, the log bit names were changed from
115    <code class="literal">LOG_something</code> to <code class="literal">YLOG_something</code>,
116    to avoid collision with <code class="filename">syslog.h</code>.
117   </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="tools.nmem.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="tools.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="marc.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3. Nibble Memory </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5. MARC</td></tr></table></div></body></html>
Note: See TracBrowser for help on using the repository browser.