[英]Creating .log files with logging's TimedRotatingFileHandler
I would expect the TimedRotatingFileHandler
to create.log files, but instead it creates files without extension.我希望TimedRotatingFileHandler
可以创建.log 文件,但它会创建没有扩展名的文件。 Is there any way I can set up the handler to generate log files?有什么办法可以设置处理程序来生成日志文件?
What I want in a nutshell: file_name.2019-10-09.log
, instead of file_name.log.2019-10-09
.简而言之,我想要的是: file_name.2019-10-09.log
,而不是file_name.log.2019-10-09
。
From the class' documentation (emphasis mine):来自班级的文档(强调我的):
The system will save old log files by appending extensions to the filename .系统将通过将扩展名附加到文件名来保存旧的日志文件。 The extensions are date-and-time based, using the strftime format %Y-%m-%d_%H-%M-%S or a leading portion thereof, depending on the rollover interval.扩展是基于日期和时间的,使用 strftime 格式 %Y-%m-%d_%H-%M-%S 或其前导部分,具体取决于翻转间隔。
This, plus the implementation of the doRollover
function show that the class will simply append the time to whatever filename the old log file has.这一点,加上doRollover
function的实现表明 class 将简单地将 append 时间转换为旧日志文件具有的任何文件名。 There seems to be no way for you to force it to keep the same file extension.您似乎无法强制它保持相同的文件扩展名。
Here my code example, can ignore extra arguments.这里我的代码示例,可以忽略额外的 arguments。 I have in a Singleton class我有一个 Singleton class
from logging.handlers import RotatingFileHandler
rhandler = RotatingFileHandler("your_desired_FILENAME_logger.out" ,
mode="a+",
maxBytes=10*1024*1024,
backupCount=5)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.