Fix mistake: fuzzy matching is 5=103, not 5=102
[yaz-moved-to-github.git] / doc / tools.xml
index 9385c8a..1d79005 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $Id: tools.xml,v 1.38 2004-10-02 13:41:46 adam Exp $ -->
+<!-- $Id: tools.xml,v 1.49 2006-04-25 11:25:08 marc Exp $ -->
  <chapter id="tools"><title>Supporting Tools</title>
   
   <para>
         <literal>@and</literal>.  Its semantics are described in 
        section 3.7.2 (Proximity) of Z39.50 the standard itself, which
         can be read on-line at
-       <ulink url="http://lcweb.loc.gov/z3950/agency/markup/09.html"/>
+       <ulink url="&url.z39.50.proximity;"/>
       </para>
       <para>
        In PQF, the proximity operation is represented by a sequence
        </itemizedlist>
        (The numeric values of the relation and well-known unit-code
        parameters are taken straight from
-       <ulink url="http://lcweb.loc.gov/z3950/agency/asn1.html#ProximityOperator"
+       <ulink url="&url.z39.50.proximity.asn1;"
        >the ASN.1</ulink> of the proximity structure in the standard.)
       </para>
     </sect3>
       <para>
        <screen>
        dylan
+
        "bob dylan"
        </screen>
       </para>
       <para>
        <screen>
        @or "dylan" "zimmerman"
+
        @and @or dylan zimmerman when
+
        @and when @or dylan zimmerman
        </screen>
       </para>
       <para>
        <screen>
        @set Result-1
-       @and @set seta setb
+
+       @and @set seta @set setb
        </screen>
       </para>
      </example>
       <para>
        <screen>
        @attr 1=4 computer
+
        @attr 1=4 @attr 4=1 "self portrait"
+
        @attrset exp1 @attr 1=1 CategoryList
+
        @attr gils 1=2008 Copenhagen
+
        @attr 1=/book/title computer
        </screen>
       </para>
        </table>
       </para>
       <para>
-       The complete list of Bib-1 attributes can be found 
-       <ulink url="http://lcweb.loc.gov/z3950/agency/defns/bib1.html">
-       here
-       </ulink>.
+       Refer to the complete
+       <ulink url="&url.z39.50.attset.bib1;">list of Bib-1 attributes</ulink>
       </para>
       <para>
        It is also possible to specify non-numeric attribute values, 
@@ -932,10 +938,9 @@ struct ccl_rpn_node *ccl_find_str (CCL_bibset bibset, const char *str,
    </sect2>
    <sect2 id="tools.cql"><title>CQL</title>
     <para>
-     <ulink url="http://www.loc.gov/z3950/agency/zing/cql/">CQL</ulink>
+     <ulink url="&url.cql;">CQL</ulink>
       - Common Query Language - was defined for the
-     <ulink url="http://www.loc.gov/z3950/agency/zing/srw/">SRW</ulink>
-     protocol.
+     <ulink url="&url.srw;">SRW</ulink> protocol.
      In many ways CQL has a similar syntax to CCL.
      The objective of CQL is different. Where CCL aims to be
      an end-user language, CQL is <emphasis>the</emphasis> protocol
@@ -944,8 +949,7 @@ struct ccl_rpn_node *ccl_find_str (CCL_bibset bibset, const char *str,
     <tip>
      <para>
       If you are new to CQL, read the 
-      <ulink url="http://zing.z3950.org/cql/intro.html">Gentle
-       Introduction</ulink>.
+      <ulink url="&url.cql.intro;">Gentle Introduction</ulink>.
      </para>
     </tip>
     <para>
@@ -972,8 +976,7 @@ struct ccl_rpn_node *ccl_find_str (CCL_bibset bibset, const char *str,
       <listitem>
        <para>
         The parser converts CQL to
-        <ulink url="http://www.loc.gov/z3950/agency/zing/cql/xcql.html">
-         XCQL</ulink>.
+        <ulink url="&url.xcql;">XCQL</ulink>.
         XCQL is an XML representation of CQL.
         XCQL is part of the SRW specification. However, since SRU
         supports CQL only, we don't expect XCQL to be widely used.
@@ -1081,6 +1084,8 @@ struct cql_node {
          If an index is unspecified for a search term,
          <literal>index</literal> will be NULL.
         </para>
+       </listitem>
+       <listitem>
         <para>
          <literal>index_uri</literal>: index URi for search term
         or NULL if none could be resolved for the index.
@@ -1174,7 +1179,7 @@ int cql_transform_buf(cql_transform_t ct,
       returns a non-zero SRW error code; otherwise zero is returned
       (conversion successful).  The meanings of the numeric error
       codes are listed in the SRW specifications at
-      <ulink url="http://www.loc.gov/srw/diagnostic-list.html"/>
+      <ulink url="&url.sru.diagnostics.list;"/>
      </para>
      <para>
       If conversion fails, more information can be obtained by calling
@@ -1214,7 +1219,7 @@ int cql_transform_FILE(cql_transform_t ct,
      </para>
     </sect3>
     <sect3 id="tools.cql.map">
-     <title>Specification of CQL to RPN mapping</title>
+     <title>Specification of CQL to RPN mappings</title>
      <para>
       The file supplied to functions 
       <function>cql_transform_open_FILE</function>,
@@ -1598,7 +1603,7 @@ typedef struct oident
    <para>
     again, corresponding to the specific OIDs defined by the standard.
     Refer to the
-    <ulink url="http://lcweb.loc.gov/z3950/agency/defns/oids.html">
+    <ulink url="&url.z39.50.oids;">
      Registry of Z39.50 Object Identifiers</ulink> for the
      whole list.
    </para>
@@ -1796,6 +1801,155 @@ typedef struct oident
 
   </sect1>
 
+  <sect1 id="tools.log"><title>Log</title>
+  <para>
+   &yaz; has evolved a fairly complex log system which should be useful both 
+   for debugging &yaz; itself, debugging applications that use &yaz;, and for
+   production use of those applications.  
+  </para>
+  <para>
+   The log functions are declared in header <filename>yaz/log.h</filename>
+    and implemented in <filename>src/log.c</filename>.
+    Due to name clash with syslog and some math utilities the logging
+    interface has been modified as of YAZ 2.0.29. The obsolete interface
+    is still available if in header file <filename>yaz/log.h</filename>.
+    The key points of the interface are:
+  </para>
+  <screen>
+   void yaz_log(int level, const char *fmt, ...)
+
+   void yaz_log_init(int level, const char *prefix, const char *name);
+   void yaz_log_init_file(const char *fname);
+   void yaz_log_init_level(int level);
+   void yaz_log_init_prefix(const char *prefix);
+   void yaz_log_time_format(const char *fmt);
+   void yaz_log_init_max_size(int mx);
+
+   int yaz_log_mask_str(const char *str);
+   int yaz_log_module_level(const char *name);
+  </screen>
+
+  <para>
+   The reason for the whole log module is the <function>yaz_log</function>
+   function. It takes a bitmask indicating the log levels, a
+   <literal>printf</literal>-like format string, and a variable number of
+   arguments to log.
+  </para>
+
+  <para>
+   The <literal>log level</literal> is a bit mask, that says on which level(s)
+   the log entry should be made, and optionally set some behaviour of the
+   logging. In the most simple cases, it can be one of <literal>YLOG_FATAL,
+   YLOG_DEBUG, YLOG_WARN, YLOG_LOG</literal>. Those can be combined with bits
+   that modify the way the log entry is written:<literal>YLOG_ERRNO,
+   YLOG_NOTIME, YLOG_FLUSH</literal>.
+   Most of the rest of the bits are deprecated, and should not be used. Use
+   the dynamic log levels instead.
+  </para>
+
+  <para>
+   Applications that use &yaz;, should not use the LOG_LOG for ordinary
+   messages, but should make use of the dynamic loglevel system. This consists
+   of two parts, defining the loglevel and checking it.
+  </para>
+
+  <para>
+   To define the log levels, the (main) program should pass a string to
+   <function>yaz_log_mask_str</function> to define which log levels are to be
+   logged. This string should be a comma-separated list of log level names,
+   and can contain both hard-coded names and dynamic ones. The log level
+   calculation starts with <literal>YLOG_DEFAULT_LEVEL</literal> and adds a bit
+   for each word it meets, unless the word starts with a '-', in which case it 
+   clears the bit. If the string <literal>'none'</literal> is found,
+   all bits are cleared. Typically this string comes from the command-line,
+   often identified by <literal>-v</literal>. The
+   <function>yaz_log_mask_str</function> returns a log level that should be
+   passed to <function>yaz_log_init_level</function> for it to take effect.
+  </para>
+
+  <para>
+   Each module should check what log bits it should be used, by calling 
+   <function>yaz_log_module_level</function> with a suitable name for the
+   module. The name is cleared from a preceding path and an extension, if any,
+   so it is quite possible to use <literal>__FILE__</literal> for it. If the
+   name has been passed to <function>yaz_log_mask_str</function>, the routine
+   returns a non-zero bitmask, which should then be used in consequent calls
+   to yaz_log. (It can also be tested, so as to avoid unnecessary calls to
+   yaz_log, in time-critical places, or when the log entry would take time 
+   to construct.) 
+  </para>
+
+  <para>
+   Yaz uses the following dynamic log levels:
+   <literal>server, session, request, requestdetail</literal> for the server
+   functionality.
+   <literal>zoom</literal> for the zoom client api.
+   <literal>ztest</literal> for the simple test server.
+   <literal>malloc, nmem, odr, eventl</literal> for internal debugging of yaz itself.
+   Of course, any program using yaz is welcome to define as many new ones, as
+   it needs.
+  </para>
+
+  <para>
+   By default the log is written to stderr, but this can be changed by a call
+   to <function>yaz_log_init_file</function> or
+   <function>yaz_log_init</function>. If the log is directed to a file, the
+   file size is checked at every write, and if it exceeds the limit given in
+   <function>yaz_log_init_max_size</function>, the log is rotated. The
+   rotation keeps one old version (with a <literal>.1</literal> appended to
+   the name). The size defaults to 1GB. Setting it to zero will disable the
+   rotation feature.
+  </para>
+
+  <screen>
+  A typical yaz-log looks like this
+  13:23:14-23/11 yaz-ztest(1) [session] Starting session from tcp:127.0.0.1 (pid=30968)
+  13:23:14-23/11 yaz-ztest(1) [request] Init from 'YAZ' (81) (ver 2.0.28) OK
+  13:23:17-23/11 yaz-ztest(1) [request] Search Z: @attrset Bib-1 foo  OK:7 hits
+  13:23:22-23/11 yaz-ztest(1) [request] Present: [1] 2+2  OK 2 records returned
+  13:24:13-23/11 yaz-ztest(1) [request] Close OK
+  </screen>
+
+  <para>
+   The log entries start with a time stamp. This can be omitted by setting the
+   <literal>YLOG_NOTIME</literal> bit in the loglevel. This way automatic tests
+   can be hoped to produce identical log files, that are easy to diff. The
+   format of the time stamp can be set with
+   <function>yaz_log_time_format</function>, which takes a format string just
+   like <function>strftime</function>.
+  </para>
+
+  <para>
+   Next in a log line comes the prefix, often the name of the program. For
+   yaz-based servers, it can also contain the session number. Then
+   comes one or more logbits in square brackets, depending on the logging
+   level set by <function>yaz_log_init_level</function> and the loglevel
+   passed to <function>yaz_log_init_level</function>. Finally comes the format
+   string and additional values passed to <function>yaz_log</function>
+  </para>
+
+  <para>
+   The log level <literal>YLOG_LOGLVL</literal>, enabled by the string
+   <literal>loglevel</literal>, will log all the log-level affecting
+   operations. This can come in handy if you need to know what other log
+   levels would be useful. Grep the logfile for <literal>[loglevel]</literal>.
+  </para>
+
+  <para>
+   The log system is almost independent of the rest of &yaz;, the only
+   important dependence is of <filename>nmem</filename>, and that only for
+   using the semaphore definition there. 
+  </para>
+
+  <para>
+   The dynamic log levels and log rotation were introduced in &yaz; 2.0.28. At
+   the same time, the log bit names were changed from
+   <literal>LOG_something</literal> to <literal>YLOG_something</literal>, 
+   to avoid collision with <filename>syslog.h</filename>.
+  </para>
+
+  </sect1>
+  
   <sect1 id="tools.marc"><title>MARC</title>
    
    <para>
@@ -1818,6 +1972,7 @@ typedef struct oident
     #define YAZ_MARC_OAIMARC   2
     #define YAZ_MARC_MARCXML   3
     #define YAZ_MARC_ISO2709   4
+    #define YAZ_MARC_XCHANGE   5
 
     /* supply iconv handle for character set conversion .. */
     void yaz_marc_iconv(yaz_marc_t mt, yaz_iconv_t cd);