Disable debug output in libxml2 and xmlsec

拈花ヽ惹草 提交于 2019-12-23 02:35:09

问题


In my software, I use libxml2 and xmlsec to manipulate (obviously) XML data structures. I mainly use XSD schema validation and so far, it works well.

When the data structure input by the client doesn't match the XSD schema, libxml2 (or xmlsec) output some debug strings to the console.

Here is an example:

Entity: line 1: parser error : Start tag expected, '<' not found
DUMMY<?xml
^

While those strings are useful for debugging purposes, I don't want them to appear and polute the console output in the released software. So far, I couldn't find an official way of doing this.

Do you know how to suppress the debug output or (even better) to redirect it to a custom function ?

Many thanks.


回答1:


I would investigate the xmlSetGenericErrorFunc() and xmlThrDefSetGenericErrorFunc() functions, they seem right. The documentation is .. sparse, though.

Here is some Python code that seems to use these functions to disable error messages, the relevant lines look like this:

# dummy function: no debug output at all
cdef void _nullGenericErrorFunc(void* ctxt, char* msg, ...) nogil:
    pass

# setup for global log:

cdef void _initThreadLogging():
    # disable generic error lines from libxml2
    xmlerror.xmlThrDefSetGenericErrorFunc(NULL, _nullGenericErrorFunc)
    xmlerror.xmlSetGenericErrorFunc(NULL, _nullGenericErrorFunc)


来源:https://stackoverflow.com/questions/2801315/disable-debug-output-in-libxml2-and-xmlsec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!