英文:
python logging - there is any way to pass the log as an argument?
问题
在我的项目中,我正在使用日志模块将日志写入本地的 .log 文件,此外,我想将相同的日志传递给另一个函数,使用循环队列算法在本地记录日志。是否可以配置日志记录器来实现这个目标?谢谢。
当前的日志配置如下:
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter("<SOME FORMAT>")
file_handler = logging.FileHandler('logfile.log')
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
!! 更新:问题已解决 - @imriqwe 在这里的回答 https://stackoverflow.com/a/36408692 帮助我找到了解决方法。
英文:
in my project i am using the logging module and write the logs into a local .log file, in addition i want to pass the same log to another function to document locally the logs with circular queue algorithm.
it is possible to configure the logger to do it?
thanks .
the currnet logging config
logger=logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
formatter=logging.Formatter("<SOME FORMAT>")
file_handler=logging.FileHandler('logfile.log')
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
!! UPDATE : SOLVED - @imriqwe answer here https://stackoverflow.com/a/36408692 helped me to figure it.
答案1
得分: 0
这个线程 https://stackoverflow.com/questions/25187083/python-logging-to-multiple-handlers-at-different-log-levels 回答了你的问题,它展示了如何添加多个处理程序,一个文件处理程序和一个流处理程序。
英文:
I think this thread https://stackoverflow.com/questions/25187083/python-logging-to-multiple-handlers-at-different-log-levels answers your question, it shows how to add multiple handlers, one file handler and one stream handler.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论