Delgan / loguru

Python logging made (stupidly) simple
MIT License
19.51k stars 690 forks source link

【question】The name of the generated log file is different from that set in the code。 Why is that? #722

Open Odimmsun opened 1 year ago

Odimmsun commented 1 year ago

hello,my code is:

import os
import time
from loguru import logger

basedir = os.getcwd()
log_path = os.path.join(basedir, 'logs')

if not os.path.exists(log_path):
    os.mkdir(log_path)

log_path_all = os.path.join(log_path, f'{time.strftime("%Y-%m-%d")}_log.log')
logger.add(log_path_all, rotation="12:00", retention="20 days", enqueue=True)

Normally, my logs folder should be a log file named by day, like: "2022-09-30_log.log"etc However, such files appear in the directory: ”2022-09-30_log.2022-10-08_08-25-19_710893.log“ And the content recorded in it is another day's log。Like: image

So,How to solve this situation?Thanks~

Delgan commented 1 year ago

The trailing date indicates Loguru find a file named "2022-09-30_Log.log" which already exists, so it renamed it first to avoid overwriting it. This behavior happens during rotation.