Python的默认日志记录格式化程序是什么? [英] What is Python's default logging formatter?

查看:94
本文介绍了Python的默认日志记录格式化程序是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解密日志中包含的信息(日志记录设置使用默认的格式化程序). 文档指出:

I'm trying to decipher the information contained in my logs (the logging setup is using the default formatter). The documentation states:

对记录进行格式化-如果设置了格式化程序,请使用它.否则,请使用该模块的默认格式化程序.

Do formatting for a record - if a formatter is set, use it. Otherwise, use the default formatter for the module.

但是,我找不到任何引用来说明这种默认格式.

However, I can't find any reference actually stating what this default format is.

推荐答案

默认格式位于

格式代码将告诉您如何自定义它.这是一个有关如何自定义它的示例.

The Format code will tell you how you can customize it. Here is one example on how you can customize it.

import sys
import logging

logging.basicConfig(
    level=logging.DEBUG,
    format="[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s",
    datefmt="%H:%M:%S",
    stream=sys.stdout)

logging.info("HEY")

这将导致:

[26/May/2013 06:41:40] INFO [root.<module>:1] HEY

这篇关于Python的默认日志记录格式化程序是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆