【问题标题】:Python 3.4.2 logging not displaying time stampPython 3.4.2 日志不显示时间戳
【发布时间】:2015-02-01 22:31:50
【问题描述】:

我有一个尝试添加日志记录的 Python pgm。它正在记录,但没有为每个条目添加时间戳。我已经研究过它,阅读了文档等,它看起来正确地写给了我,但它没有给我时间戳。这里有什么不正确的地方?

lfname = "TestAPIlog.log"
logging.basicConfig(filename=lfname, format='%(asctime)s %(message)s',
                filemode='w', level=logging.WARNING )
logging.info('Started')

上面产生的日志顶部是这样的:

INFO:root:Started
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.uber.com
DEBUG:requests.packages.urllib3.connectionpool:"GET /v1/estimates/price?end_latitude=39.762239&start_latitude=39.753385&server_token=MY_TOKEN_HERE&start_longitude=-104.998454&end_longitude=-105.013322 HTTP/1.1" 200 None
INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.uber.com
DEBUG:requests.packages.urllib3.connectionpool:"GET /v1/estimates/price?

谢谢,

【问题讨论】:

    标签: python logging


    【解决方案1】:

    在您的代码运行时,看起来好像已经调用了basicConfig()。如文档所述,如果日志记录配置了任何处理程序,basicConfig() 将不执行任何操作。它只是作为一种一次性的、简单的配置方法。检查您未在此处发布的代码的其他部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-22
      • 2018-03-19
      相关资源
      最近更新 更多