How can I modify file name without changing log structure and use UTC standard?
See original GitHub issueI’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()
)
logger.add(sys.stderr, format="{extra[utc]} {message}")
logger = logger.patch(lambda record: record["extra"].update(utc=datetime.utcnow())
Error:
--- Logging error in Loguru Handler #2 ---
Record was: {'elapsed': datetime.timedelta(microseconds=531720), 'exception': None, 'extra': {}, 'file': '__init__.py', 'function': 'escuta', 'level': 'INFO', 'line': 35, 'message': 'Servidor escutando...', 'module': '__init__', 'name': 'servidor.endpoint', 'process': '26045', 'thread': '140735874732992', 'time': datetime(2019, 8, 15, 17, 9, 41, 368329, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=75600), '-03'))}
Traceback (most recent call last):
File "/Users/vitor.morais/Documents/Projetos/futuro-configurador/configurador/venv/lib/python3.7/site-packages/loguru/_handler.py", line 119, in emit
formatted = precomputed_format.format_map(formatter_record)
KeyError: 'utc'
--- End of logging error ---
How can I do it?
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Default Log File Settings for Web Sites <logFile> - IIS
By default, IIS 7 and later uses the World Wide Web Consortium (W3C) log file format. You can change this setting by modifying...
Read more >Preferred format of file names which include a timestamp
ISO 8601 includes a format using UTC ('Z' time), which should be used. ISO 8601 includes a format that does not use the...
Read more >"Standard" format for using a timestamp as part of a filename
My question is two parts: Is using a time stamp to enforce unique file names a poor practice? No, it's fine. I could...
Read more >Name a file in Java to include date and time stamp
Use that formatter instance to generate a String. No more needing to replace characters in the String. String output = odt.format( formatter );....
Read more >Append current UTC time to the filename
We need to append UTC time to the filename while transfer and the Secure Transport ... instances with the ability to automatically adjust...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, I finally found some time to implement this.
Adding
"!UTC"
at the very end of the time format will convert thedatetime
before formatting. Example:It should work for both logs and filenames. 😉
It should be fine, except maybe for some edge cases like when using
retention
with atimedelta
(now()
(UTC) would be compared against file time (local)). 😉