Skip to content

Commit 55adeb7

Browse files
Document this as a new feature.
1 parent e1c910e commit 55adeb7

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

Doc/library/logging.handlers.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ timed intervals.
402402
rollover interval.
403403

404404
When computing the next rollover time for the first time (when the handler
405-
is created), the last modification time of an existing log file, or else
405+
is created), the creation time (if supported by the OS and file system)
406+
or the last modification of an existing log file, or else
406407
the current time, is used to compute when the next rotation will occur.
407408

408409
If the *utc* argument is true, times in UTC will be used; otherwise
@@ -449,6 +450,10 @@ timed intervals.
449450
.. versionchanged:: 3.9
450451
The *errors* parameter was added.
451452

453+
.. versionchanged:: next
454+
Use the creation time instead of the last modification time, if supported by the OS and file system.
455+
456+
452457
.. method:: doRollover()
453458

454459
Does a rollover, as described above.

Doc/whatsnew/3.16.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ lzma
102102
requires ``lzma`` 5.4.0 or newer while RISC-V requires 5.6.0 or newer.
103103
(Contributed by Chien Wong in :gh:`115988`.)
104104

105+
logging
106+
-------
107+
108+
* :class:`~logging.handlers.TimedRotatingFileHandler` now uses the creation
109+
time instead of the last modification time of an existing log file as
110+
the basis for the first rotation after handler creation, if supported by
111+
the OS and file system.
112+
This allows it to be used in short-running programs that start and end
113+
before the rotation interval expires.
114+
(Contributed by Iván Márton and Serhiy Storchaka in :gh:`84649`.)
115+
105116
os
106117
--
107118

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
A bug has been fixed that made the ``TimedRotatingFileHandler`` use the
2-
MTIME attribute of the configured log file to to detect whether it has to be
3-
rotated yet or not. In cases when the file was changed within the rotation
4-
period the value of the MTIME was also updated to the current time and as a
5-
result the rotation never happened. The file creation time (CTIME) is used
6-
instead that makes the rotation file modification independent.
1+
:class:`~logging.handlers.TimedRotatingFileHandler` now uses the creation time
2+
instead of the last modification time of an existing log file as the basis
3+
for the first rotation after handler creation, if supported by the OS and file system.
4+
This allows it to be used in short-running programs that start and end before
5+
the rotation interval expires.

0 commit comments

Comments
 (0)