禁用libxml2和xmlsec中的调试输出 [英] Disable debug output in libxml2 and xmlsec
问题描述
在我的软件中,我使用 libxml2 和 xmlsec 来操纵(显然)XML数据结构。我主要使用XSD模式验证,到目前为止,它工作得很好。
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.
当客户端输入的数据结构与XSD模式不匹配时,libxml2(或xmlsec)将一些调试字符串输出到控制台。
When the data structure input by the client doesn't match the XSD schema, libxml2 (or xmlsec) output some debug strings to the console.
以下是一个示例:
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 ?
非常感谢。
推荐答案
code> xmlSetGenericErrorFunc() 和 xmlThrDefSetGenericErrorFunc()
功能,他们似乎是正确的。文件是..稀疏,但是。
I would investigate the xmlSetGenericErrorFunc()
and xmlThrDefSetGenericErrorFunc()
functions, they seem right. The documentation is .. sparse, though.
这里是一些似乎使用这些功能来禁用错误消息的Python代码,相关行如下所示:
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)
这篇关于禁用libxml2和xmlsec中的调试输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!