-
Notifications
You must be signed in to change notification settings - Fork 704
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 can I modify file name without changing log structure and use UTC standard? #128
Comments
I fixed the typo in the Readme, thanks. 😄 Creating a logfile without timing would look like When you call Alternatively, you can use |
I presume this only works for the first file, am I correct? When rotating, it would execute Sorry, but Im getting really confused with the API.
logger.configure(patch=lambda record: record["extra"].update(utc=datetime.utcnow()))
logger.add(sys.stderr, level='DEBUG', format='{extra[utc]} | {level} | {message}')
logger.add('log/mylog_{time:YYYY-MM-DD}.log', level='DEBUG', rotation='00:00', retention='10 days') |
Correct, it will not work well with
Each sink are independent of each others. Indeed, if you want to use a customized my_format = "<g>{time}</> | <r>{level}</> | <lvl>{message}</>"
logger.add(sys.stderr, level="DEBUG", format=my_format)
logger.add("my_log.log", level"="DEBUG", format=my_format, rotation="00:00")
I am not usually a big fan of adding more arguments to However, I agree that dealing with UTC datetime format in Loguru is not straightforward. The same way that an alternative datetime formrajouteratter is provided, I could maybe add a special directive to format the datetime using UTC, like That would still require you to manually re-define the format, but considering the mentioned constraints, it's an acceptable compromise in my opinion. Out of curiosity, why do you need to use UTC time rather than local time with a timezone ( |
Got it.
It would be nice of you. :)
I'm developing a server to communicate with devices configured to send messages in UTC standard. It could confuse someone reading an error log from Thanks a lot for helping me out in this one. It would be nice if you add UTC support. Nice work :) |
For now, I have monkey patched from loguru import _datetime
def my_now():
now = datetime.utcnow()
return _datetime.datetime(now.year, now.month, now.day, now.hour, now.minute, now.second, now.microsecond)
_datetime.datetime.now = my_now It worked nicely so far. What do you think? Can this solution break something else? |
It should be fine, except maybe for some edge cases like when using |
Ok, I finally found some time to implement this. Adding logger.add(sys.stderr, format="[{time:YYYY-MM-DD HH:mm:ss.SSSSSS!UTC}] {message}")
logger.info("Local time is: {}", datetime.now())
# [2019-10-26 08:49:53.933647] Local time is: 2019-10-26 10:49:53.933599 It should work for both logs and filenames. 😉 |
I've been reading the docs and trying some things out for a few hours and could not do the following.
Create files using UTC and without timing:
errors_2019-08-15_.log
Logs in UTC structured like this:
2019-08-15 17:02:16.267 | {LEVEL} | {MESSAGE}
.I've tried this code taken directly from docs and does not seems to work. (And is missing a
)
after.utcnow()
)Error:
How can I do it?
Thanks!
The text was updated successfully, but these errors were encountered: