YAZ  5.34.0
xmlerror.c
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11 
12 #include <stdio.h>
13 #include <string.h>
14 #include <assert.h>
15 #include <yaz/log.h>
16 #include <yaz/snprintf.h>
17 
18 #if YAZ_HAVE_XML2
19 #include <libxml/parser.h>
20 #include <libxml/tree.h>
21 #endif
22 #if YAZ_HAVE_XSLT
23 #include <libxslt/xsltutils.h>
24 #endif
25 
27 
28 #if YAZ_HAVE_XML2
29 static void xml_error_handler(void *ctx, const char *fmt, ...)
30 {
31  char buf[1024];
32  const char *prefix = (const char *) ctx;
33 
34  va_list ap;
35  va_start(ap, fmt);
36 
37  yaz_vsnprintf(buf, sizeof(buf), fmt, ap);
38  size_t l = strlen(buf);
39  if (l > 0 && buf[l-1] == '\n')
40  buf[l-1] = '\0';
41  yaz_log(xml_error_log_level, "%s: %s", prefix, buf);
42 
43  va_end (ap);
44 }
45 #endif
46 
47 void yaz_log_xml_errors(const char *prefix, int log_level)
48 {
50 
51 #if YAZ_HAVE_XML2
52  xmlSetGenericErrorFunc((void *) (prefix ? prefix : "XML"),
54 #if YAZ_HAVE_XSLT
55  xsltSetGenericErrorFunc((void *) (prefix ? prefix : "XSLT"),
57 #endif
58 #endif
59 }
60 
61 /*
62  * Local variables:
63  * c-basic-offset: 4
64  * c-file-style: "Stroustrup"
65  * indent-tabs-mode: nil
66  * End:
67  * vim: shiftwidth=4 tabstop=8 expandtab
68  */
69 
static int log_level
Definition: eventl.c:39
void yaz_log(int level, const char *fmt,...)
Writes log message.
Definition: log.c:487
Logging utility.
#define YLOG_WARN
log level: warning
Definition: log.h:46
void yaz_vsnprintf(char *buf, size_t size, const char *fmt, va_list ap)
Definition: snprintf.c:17
Header for config file reading utilities.
static void xml_error_handler(void *ctx, const char *fmt,...)
Definition: xmlerror.c:29
void yaz_log_xml_errors(const char *prefix, int log_level)
Makes Libxml2 and Libxslt log errors through yaz_log.
Definition: xmlerror.c:47
static int xml_error_log_level
Definition: xmlerror.c:26