Skip to content

Commit 7793f9c

Browse files
committed
bpo-40469: Make TimedRotatingFileHandler use CTIME instead of MTIME
The TimedRotatingFileHandler previously used MTIME attribute of the log file to detect whether it has to be rotate yet or not. In cases when the file is changed within the rotatation period the MTIME is also updated to the current time and the rotation never happens. It's more appropriate to check the file creation time (CTIME) instead.
1 parent 213a6bb commit 7793f9c

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

Lib/logging/handlers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"""
2525

2626
import io, logging, socket, os, pickle, struct, time, re
27-
from stat import ST_DEV, ST_INO, ST_MTIME
27+
from stat import ST_DEV, ST_INO, ST_CTIME
2828
import queue
2929
import threading
3030
import copy
@@ -263,7 +263,7 @@ def __init__(self, filename, when='h', interval=1, backupCount=0,
263263
# path object (see Issue #27493), but self.baseFilename will be a string
264264
filename = self.baseFilename
265265
if os.path.exists(filename):
266-
t = os.stat(filename)[ST_MTIME]
266+
t = os.stat(filename)[ST_CTIME]
267267
else:
268268
t = int(time.time())
269269
self.rolloverAt = self.computeRollover(t)

Misc/ACKS

+1
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,7 @@ Owen Martin
11701170
Sidney San Martín
11711171
Westley Martínez
11721172
Sébastien Martini
1173+
Iván Márton
11731174
Roger Masse
11741175
Nick Mathewson
11751176
Simon Mathieu

0 commit comments

Comments
 (0)