【问题标题】:Unable to add a timestamp to a logger in Python 3.5无法在 Python 3.5 中向记录器添加时间戳
【发布时间】:2017-01-16 09:17:16
【问题描述】:

我的记录器:

 logging.basicConfig(filename="{}/log.log".format(config.log_dir), level=logging.DEBUG, format="%(asctime)s %(message)s", datefmt="%d-%b-%Y %I:%M:%S"    )

而且.. 没有添加时间戳:

logging.info("fdsfdsfds")
# => fdsfdsfds

【问题讨论】:

  • 好吧,同样的两行代码对我有用,所以我猜你的代码中可能还有其他地方可以更改日志配置?您可以通过调用logging.getLogger() 来检查默认处理程序上的配置。检查它是否有适当的处理程序和格式化程序。

标签: python python-3.x logging


【解决方案1】:

这对我有用

那是my output

import logging
FORMAT = '%(asctime)s %(message)s'
DATE = '%d-%b-%Y %I:%M:%S'
logging.basicConfig(filename="log.log",level=logging.DEBUG,format=FORMAT,datefmt=DATE)
logger = logging.getLogger('Stackoverflow log')
logger.info('Info 1')

如果仍然没有时间戳,请添加更多代码

【讨论】:

    猜你喜欢
    • 2015-10-24
    • 2017-06-21
    • 2018-03-13
    • 1970-01-01
    • 2013-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多