当前位置:   article > 正文

Klipper 源码解析-queuelogger_klipper代码

klipper代码

QueueLogger 是一个用于后台日志记录的工具。它用于将日志消息存储在一个队列中,以便在后台进行处理和记录。

下面是他的代码

  1. # Code to implement asynchronous logging from a background thread
  2. #
  3. # Copyright (C) 2016-2019 Kevin O'Connor <kevin@koconnor.net>
  4. #
  5. # This file may be distributed under the terms of the GNU GPLv3 license.
  6. import logging, logging.handlers, threading, queue, time
  7. # Class to forward all messages through a queue to a background thread
  8. class QueueHandler(logging.Handler):
  9. def __init__(self, queue):
  10. logging.Handler.__init__(self)
  11. self.queue = queue
  12. def emit(self, record):
  13. try:
  14. self.format(record)
  15. record.msg = record.message
  16. record.args = None
  17. record.exc_info = None
  18. self.queue.put_nowait(record)
  19. except Exception:
  20. self.handleError(record)
  21. # Class to poll a queue in a background thread and log each message
  22. class QueueListener(logging.handler
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/294304
推荐阅读
相关标签
  

闽ICP备14008679号