[英]How do I use logging in python tornado and write to file
Currently I'm using logging.getLogger().setLevel(logging.DEBUG)
what I think is logging everything where logging level is => DEBUG Is that a correct assumption? 当前我正在使用logging.getLogger().setLevel(logging.DEBUG)
我认为正在记录日志级别为=> DEBUG的所有内容这是正确的假设吗? I can see a difference when I set logging.DEBUG to logging.ERROR so I guess I'm correct. 当我将logging.DEBUG设置为logging.ERROR时,我可以看到区别,所以我想我是正确的。
Also how do I write these logging rows to a file? 另外,如何将这些日志记录行写入文件?
This is a exmaple write log to file 这是一个向文件写入日志的示例
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# create a file handler
handler = logging.FileHandler('hello.log')
handler.setLevel(logging.INFO)
# create a logging format
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
# add the handlers to the logger
logger.addHandler(handler)
logger.info('Hello baby')
More detail: http://victorlin.me/posts/2012/08/good-logging-practice-in-python/ 更多详细信息: http : //victorlin.me/posts/2012/08/good-logging-practice-in-python/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.