Can I customize log format on top of loguru format
See original GitHub issueI am trying to figure out if I could customize log message in addition to the log format provided by loguru.
For example:
Log message from Loguru :
2019-07-01 16:21:16.733 | INFO | __main__:run_server:50 - Tornado server starting on port 5000
Can I change this format to include correlation ID as well like 👇
[2019-06-28 09:51:59] [application_name] [correlationID] [INFO] - __main__:run_server:50 Tornado server starting on port 5000
Thanks
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Logger - loguru documentation - Read the Docs
The default values of sink parameters can be entirely customized. This is particularly useful if you don't like the log format of the...
Read more >loguru Documentation - Read the Docs
How to set up logs formatting? How to filter messages? ... Using the logger in your scripts is easy, and you can configure()...
Read more >A quick guide to using Loguru - Medium
The format parameter specifies the custom format of our log. We can ... Other than the keys which the logger provides, we can...
Read more >Two Logging Options Better than Print Statements
There's lots more to customize with loguru . For example, you can change the default format using an environment variable so you don't...
Read more >documentation
Loguru provides a set of functions and macros to aid logging to one or several ... By default, Loguru will only let you...
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
I forgot to precise: you need first to
remove()
the default handler, otherwise, logs will be printed twice as you saw!The thing is that, for convenience, Loguru adds a pre-configured handler which sends messages to
stderr
. This is why you can dofrom loguru import logger
thenlogger.info("A message")
and it works out of the box.If you want to customize the log format, you have to remove the default handler first.
Note that the default format used by Loguru is as follow:
Another way to do the same, which I use myself, is to directly configure the logger with the handler(s) you desire which also takes care of removing the default handler.
Which would give you the desired output: