Loguru: File sink (incl. rotation, retention, delay; time-stamped file name) does not remove old log files

Created on 11 Jul 2019  路  2Comments  路  Source: Delgan/loguru

I was experimenting with rotating logs, and the delay parameter. Considering this example:

import string
import time

from loguru import logger

LOGGER_CONFIG = dict(
    sink="test_{time}.log",
    rotation=130,  # to fit two log messages per file
    retention=2,
    delay=True,
)

logger.configure(handlers=[LOGGER_CONFIG])

for char in string.ascii_lowercase:
    logger.info(char)
    time.sleep(0.001)

Expected behavior:
three log files are present (two retained ones, plus the active one).

Actual behavior:
26 log files are present.

I noticed the following as well:
Not using a timestamped filename

LOGGER_CONFIG = dict(
    sink="test.log",
    rotation=130,  # to fit two log messages per file
    retention=2,
    delay=True,
)

or switching off the delay,

LOGGER_CONFIG = dict(
    sink="test_{time}.log",
    rotation=130,  # to fit two log messages per file
    retention=2,
    delay=False,
)

produce three log files.

bug

All 2 comments

Urgh, what an ugly regression!

This happens because the FileSink.write() method is dynamically re-assigned during the execution of the program based on rotation and delay arguments. However, the Handler is initialized with the former write() method and hence not updated appropriately.

Thanks for the bug report. I will fix this and publish a new release tomorrow.

Please, update loguru to the v0.3.1 just released. The bug should now be fixed! :smiley:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

heckad picture heckad  路  4Comments

shmilylty picture shmilylty  路  5Comments

HarveySummers picture HarveySummers  路  4Comments

sergree picture sergree  路  3Comments

talz picture talz  路  6Comments