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.
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: