-
Notifications
You must be signed in to change notification settings - Fork 715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to adjust the time string which is inserted when rotating? #899
Comments
Hi. You can define a custom def rename(filepath):
today = datetime.datetime.now().strftime("%Y-%m-%d")
os.rename(filepath, f"record.{today}.log")
logger.add("record.log", rotation="00:00", compression=rename) |
@Delgan Thanks for your replay 👍 In order to avoid misunderstanding, I would like to ask detailed questions about your answer: Is the codes in your answer just a example about how to use From my understanding in the codes you provied to me,
Should I change the example you gave me to
or
for my own needs? |
Sorry, that was an oversight. I think you indeed need to remove |
You are right, the answer above you provide to me is correct. and the code above(in my question) is incorrect:
|
Be careful there might be a bug with |
It's not a bug report of I got another error and couldn't find out for days: The answer code provided by @Delgan works perfectly
But I have not noticed that the input argument
instead of (what I thought before)
Therefore I got a serious bug when I tried to rename from |
@Delgan I found that the build-in solution in #894 : from loguru import logger
logger.remove()
logger.add(
'logs/log.{time:YYYY-MM-DD}.log',
level='INFO',
rotation="00:00",
retention='1 months',
enqueue=True
)
logger.info('hello world')
logger.info('hello world') Which would you suggest, the answer above #899 (comment) or this build-in solution? |
@changchiyou It depends on your preferences. Using the built-in solution the current logged file will contain the date, e.g. |
The code below generate
record.2023-06-25_21-37-48_944911.log
after rotating The time string2023-06-25_21-37-48_944911
is the time when the script has been launched.Is it possible to adjust the format of time string?
To be more specific, I want
record.2023-06-25.log
(record.{yesterday date time: YYYY-MM-DD}.log
) would be generate on2023-06-26 00:00
, instead ofrecord.2023-06-25_21-37-48_944911.log
(record.{script launching time}.log
).I have read Logger.add but still have no idea about my question.
The text was updated successfully, but these errors were encountered: