Pass log kwargs to custom sink
See original GitHub issueLoguru supports string formatting, but it seems that these kwargs are dropped if there is nothing to format in the string. I would think these would be passed to the custom sink, but it does not seem like this is the case.
See the below example.
>>> from loguru import logger
>>>
>>> def callback(payload):
... print(payload)
...
>>> logger.start(callback, serialize=True)
>>> logger.info("testing", hello="world")
2018-12-08 15:56:07.675 | INFO | __main__:<module>:1 - yoo
{"text": "2018-12-08 15:56:07.675 | INFO | __main__:<module>:1 - testing\n", "record": {"elapsed": {"repr": "0:01:35.065585", "seconds": 95.065585}, "exception": null, "extra": {}, "file": {"name": "<stdin>", "path": "<stdin>"}, "function": "<module>", "level": {"icon": "\u2139\ufe0f", "name": "INFO", "no": 20}, "line": 1, "message": "testing", "module": "<stdin>", "name": "__main__", "process": {"id": 22013, "name": "MainProcess"}, "thread": {"id": 140289032955392, "name": "MainThread"}, "time": {"repr": "2018-12-08 15:56:07.675593-06:00", "timestamp": 1544306167.675593}}}
>>> logger.info("testing {hello}", hello="world")
2018-12-08 15:58:37.702 | INFO | __main__:<module>:1 - testing world
{"text": "2018-12-08 15:58:37.702 | INFO | __main__:<module>:1 - testing world\n", "record": {"elapsed": {"repr": "0:04:05.092374", "seconds": 245.092374}, "exception": null, "extra": {}, "file": {"name": "<stdin>", "path": "<stdin>"}, "function": "<module>", "level": {"icon": "\u2139\ufe0f", "name": "INFO", "no": 20}, "line": 1, "message": "testing world", "module": "<stdin>", "name": "__main__", "process": {"id": 22013, "name": "MainProcess"}, "thread": {"id": 140289032955392, "name": "MainThread"}, "time": {"repr": "2018-12-08 15:58:37.702382-06:00", "timestamp": 1544306317.702382}}}
I would expect that {"hello": "world"}
to be somewhere in the payload passed to the custom sink
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Python: Logging exceptions with custom *kwargs
My Question: Is there an easy way to use custom kwargs with logging.exception? A minimal example follows: import logging import logging.handlers def ...
Read more >Python Logging Guide - Best Practices and Hands-on Examples
This method is useful when using custom logging levels. Logger.exception(msg, *args, **kwargs) issues log requests with the logging level ...
Read more >A better way to logging in Python | F5 - Squashing Bugs
This basic logging decorator looks good and already does what we originally set out to achieve. As long as a method is decorated...
Read more >Logger - loguru documentation - Read the Docs
An object to dispatch logging messages to configured handlers. The Logger is the core object of loguru , every logging configuration and usage...
Read more >loguru Documentation - Read the Docs
context_logger.info("Use kwargs to add context during formatting: ... The logged message passed to all added sinks is nothing more than a ...
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
Well, I’m sorry it took a year and a half, but… This feature is finally available. 🙂
The
**kwargs
arguments are automatically added to theextra
dict. This can be disabled using.opt(capture=False)
.🥳