From 6fef48087ae8e01bae2638be8babe0b74a812f28 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 25 Mar 2008 13:49:46 +0100 Subject: [PATCH] Added function yaz_log_xml_errors. --- include/yaz/log.h | 7 ++++++ src/Makefile.am | 2 +- src/statserv.c | 2 ++ src/xmlerror.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ win/makefile | 1 + 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/xmlerror.c diff --git a/include/yaz/log.h b/include/yaz/log.h index 5d52338..103cf1f 100644 --- a/include/yaz/log.h +++ b/include/yaz/log.h @@ -196,6 +196,13 @@ YAZ_EXPORT void log_event_start(void (*func)(int level, const char *msg, YAZ_EXPORT void log_event_end(void (*func)(int level, const char *msg, void *info), void *info); + +/** \brief Makes Libxml2/Libxslt log errors via yaz_log + \param prefix prefix to use for log messages (may be 0) + \param log_level log level to use for messages +*/ +YAZ_EXPORT void yaz_log_xml_errors(const char *prefix, int log_level); + /* by default, do not enable the old LOG_-defines */ #ifndef YAZ_USE_NEW_LOG #define YAZ_USE_NEW_LOG 1 diff --git a/src/Makefile.am b/src/Makefile.am index 9135bd3..b1dd090 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -92,7 +92,7 @@ libyaz_la_SOURCES=version.c options.c log.c \ cqlstrer.c querytowrbuf.c \ tcpdchk.c \ test.c timing.c \ - xmlquery.c http.c \ + xmlquery.c xmlerror.c http.c \ mime.c mime.h oid_util.c tokenizer.c \ record_conv.c retrieval.c elementset.c snprintf.c query-charset.c \ copy_types.c match_glob.c poll.c daemon.c diff --git a/src/statserv.c b/src/statserv.c index 4b80162..63a5efb 100644 --- a/src/statserv.c +++ b/src/statserv.c @@ -1358,6 +1358,8 @@ int check_options(int argc, char **argv) char *arg; yaz_log_init_level(yaz_log_mask_str(STAT_DEFAULT_LOG_LEVEL)); + + yaz_log_xml_errors(0, YLOG_WARN); get_logbits(1); while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:A:p:DC:f:m:r:", diff --git a/src/xmlerror.c b/src/xmlerror.c new file mode 100644 index 0000000..70bd639 --- /dev/null +++ b/src/xmlerror.c @@ -0,0 +1,62 @@ +/* + * Copyright (C) 1995-2008, Index Data ApS + * All rights reserved. + */ + +/** \file + \brief Log XML / XSLT Errors via yaz_log +*/ + +#include +#include +#include +#include +#include + +#if YAZ_HAVE_XML2 +#include +#include +#endif +#if YAZ_HAVE_XSLT +#include +#endif + +static int xml_error_log_level = YLOG_WARN; + +#if YAZ_HAVE_XML2 +static void xml_error_handler(void *ctx, const char *fmt, ...) +{ + char buf[1024]; + const char *prefix = (const char *) ctx; + + va_list ap; + va_start(ap, fmt); + + yaz_vsnprintf(buf, sizeof(buf), fmt, ap); + yaz_log(YLOG_WARN, "%s: %s", prefix, buf); + + va_end (ap); +} +#endif + +void yaz_log_xml_errors(const char *prefix, int log_level) +{ + xml_error_log_level = log_level; + +#if YAZ_HAVE_XML2 + xmlSetGenericErrorFunc((void *) (prefix ? prefix : "XML"), + xml_error_handler); +#endif +#if YAZ_HAVE_XSLT + xsltSetGenericErrorFunc((void *) (prefix ? prefix : "XSLT"), + xml_error_handler); +#endif +} + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ diff --git a/win/makefile b/win/makefile index 3149007..5671056 100644 --- a/win/makefile +++ b/win/makefile @@ -467,6 +467,7 @@ MISC_OBJS= \ $(OBJDIR)\zoom-socket.obj \ $(OBJDIR)\initopt.obj \ $(OBJDIR)\xmlquery.obj \ + $(OBJDIR)\xmlerror.obj \ $(OBJDIR)\mime.obj \ $(OBJDIR)\cql.obj \ $(OBJDIR)\cqlstdio.obj \ -- 1.7.10.4