[英]Logging module not working in python 2.6.6
Below code is working fine on Python 2.7 but unfortunately i have to deploy my script on Linux 5.9 which has python 2.6.6 installed in it and there is no option for me to upgrade.下面的代码在 Python 2.7 上运行良好,但不幸的是,我必须在安装了 python 2.6.6 的 Linux 5.9 上部署我的脚本,而且我没有升级的选项。 I am not able to make logging work on python 2.6.6我无法在 python 2.6.6 上进行日志记录
import logging
class Test():
def __init__(self, args):
self.args = args
def call_this(self):
logger.info("Info Log %s" % self.args)
if __name__ == "__main__":
t = Test("Hello")
logger = logging.getLogger()
file_formatter = logging.Formatter(fmt="%(levelname)-1s [%(filename)s:%(lineno)d] %(message)s")
file_handler = logging.FileHandler('LogFile.log')
file_handler.setFormatter(file_formatter)
logger.addHandler(file_handler)
console_handler = logging.StreamHandler()
logger.addHandler(console_handler)
logger.setLevel("INFO")
t.call_this()
更改了以下代码行,现在可以使用了。
logger.setLevel(logging.INFO)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.