Handler objects are responsible for
dispatching the appropriate log
messages (based on the log messages’
severity) to the handler’s specified
destination. Logger objects can add
zero or more handler objects to
themselves with an addHandler()
method. As an example scenario, an
application may want to send all log
messages to a log file, all log
messages of error or higher to stdout,
and all messages of critical to an
email address. This scenario requires
three individual handlers where each
handler is responsible for sending
messages of a specific severity to a
specific location.
您需要创建一个自定义的
logging.Handler
,并将其添加到您的logging.Logger
。从文档中:
有关
Handler
API,请参见http://docs.python.org/library/logging.html#handler-objects。特别是,可以实现
Handler.emit(record)
方法来指定输出的目标。大概,您可以实现这个来调用TextCtrl.AppendText
。下面是一个简单的工作示例:
截图:
更新:正如iondiode指出的,如果应用程序中有多个线程,所有这些线程都通过这样的处理程序进行日志记录,那么这个简单的脚本可能会有问题;理想情况下,应该只有一个UI线程更新UI。根据他的回答,您可以使用建议的方法,通过使用自定义事件来记录事件。
创建处理程序
在你的控制下
相关问题 更多 >
编程相关推荐