相关疑难解决方法(0)

如何更改 RotatingFileHandler 在 Python 中命名文件的方式?

我想改变旋转文件处理程序命名文件的方式。

例如,如果我使用 RotatingFileHandler,它会在达到特定文件大小时将日志文件分开,命名为“日志文件名 + 扩展名编号”,如下所示。

filename.log      #first log file
filename.log.1    #rotating log file1
filename.log.2    #rotating log file2
Run Code Online (Sandbox Code Playgroud)

但是,我希望日志处理程序在每次创建时都为它们命名。例如。

09-01-12-20.log    #first log file
09-01-12-43.log    #rotating log file1
09-01-15-00.log    #rotating log file2
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

编辑:

我不是在问如何创建和命名文件。

我想促进 pythonlogging包做一些类似继承和覆盖的事情logging

python logging

7
推荐指数
1
解决办法
3056
查看次数

标签 统计

logging ×1

python ×1