Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用logging.config.fileConfig()自定义时间格式_Python - Fatal编程技术网

Python 如何使用logging.config.fileConfig()自定义时间格式

Python 如何使用logging.config.fileConfig()自定义时间格式,python,Python,我正在使用python日志模块写入日志文件: logging.config.fileConfig(log_conf_file) 我的日志配置文件“logging.conf”中的格式化程序部分如下所示: [formatter_mylog] format: %(asctime)s %(message)s 2013-05-02 13:39:55,325 mesagebody blablablabla 这使我的日志看起来像: [formatter_mylog] format: %(asctime)

我正在使用python日志模块写入日志文件:

logging.config.fileConfig(log_conf_file)
我的日志配置文件“logging.conf”中的格式化程序部分如下所示:

[formatter_mylog]
format: %(asctime)s %(message)s
2013-05-02 13:39:55,325 mesagebody blablablabla
这使我的日志看起来像:

[formatter_mylog]
format: %(asctime)s %(message)s
2013-05-02 13:39:55,325 mesagebody blablablabla
如何自定义asctime格式以输出以下内容:

May 02 13:39:55 mesage_body blablablabla
# create formatter
formatter = logging.Formatter("%(asctime)s;%(message)s",
                          "%Y-%m-%d %H:%M:%S")
我知道如果是python代码,您可以执行以下操作:

May 02 13:39:55 mesage_body blablablabla
# create formatter
formatter = logging.Formatter("%(asctime)s;%(message)s",
                          "%Y-%m-%d %H:%M:%S")
但是如何通过日志记录配置文件执行此操作?

尝试以下操作:

[formatter_mylog]
format: %(asctime)s %(message)s
datefmt=%m-%d %H:%M:%S
不确定这是否会将本月改为口头风格

更新:

要实现当月的口头风格,请尝试使用
%b
()

尝试以下方法:

[formatter_mylog]
format: %(asctime)s %(message)s
datefmt=%m-%d %H:%M:%S
不确定这是否会将本月改为口头风格

更新:


要实现本月的口头风格,请尝试使用下面的
%b
()

给出您的预期输出

[formatter_mylog]
format: %(asctime)s %(message)s
datefmt=%b %d %H:%M:%S

下面应该给出您的预期输出

[formatter_mylog]
format: %(asctime)s %(message)s
datefmt=%b %d %H:%M:%S