Creating multiple log files at log rotation time '00:00'
See original GitHub issueHi guys!
This is my log_sys.py code:
from loguru import logger
logger.remove()
formato = '{time:YYYY-MM-DD HH:mm:ss.SSSSS!UTC} {level:15} {message} [{file} : {line}]'
logger.add('logs_loguru/loguru_UTC_time_WARNING_{time:YYYY-MM-DD!UTC}.log', rotation='00:00', format=formato, level='WARNING', catch=True)
logger.add('logs_loguru/loguru_UTC_time_DEBUG_{time:YYYY-MM-DD!UTC}.log', rotation='00:00', format=formato, level='DEBUG', catch=True)
It is a web app and is running in a Cloudlinux server.
At the time the app was started, two log files were created, as expected:
loguru_UTC_time_WARNING_2022-08-23.log
loguru_UTC_time_DEBUG_2022-08-23.log
Problem started after a few hours (when the server clock was at 00:00 at the server timezone?). Instead to rotate the files, creating loguru_UTC_time_WARNING_2022-08-24.log
and loguru_UTC_time_DEBUG_2022-08-24.log
, it started to create many log files, with different file name and overwriting the content of some of them, as you can see in the following image:
File time shown in the image is my local time rather than server time.
I tried to add enqueue=True
as
logger.add('logs_loguru/loguru_UTC_time_DEBUG_{time:YYYY-MM-DD!UTC}.log', rotation='00:00', format=formato, level='DEBUG', catch=True, enqueue=True)
but that leads my web app to freezing/crashing, that seems to be a separated issue.
I could not find a way to set the rotation to UTC time. Can that be the issue?
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
In recent weeks I am using this code, that is working fine so far.
My server has internal clock set to
UTC +02:00
. So, by rotating at02:00
it will be rotating atUTC +00:00
time.Hey @sukhoi47, thanks for the investigations and the reported edge case.
I think you can try using adatetime.time()
object withtzinfo
set asUTC
forrotation
:May bad it’s not working, I need to address this bug.
Currently, I think you have to implement a custom
rotation
function or convert your UTC time to local time.