Mayil-AI / loguru

MIT License
0 stars 0 forks source link

Custom log handlers do not receive the original log message (hashtag1080) #5

Open vikramsubramanian opened 3 months ago

vikramsubramanian commented 3 months ago

Reading Record.msg in a custom logging.Handler implementation returns a formatted message instead of the original text. Since I need to use a different format for different handlers this is quite problematic. This is also different from the Python logging.

Expected value: "That's it, beautiful and simple logging!"

Actual value: "2024-02-13 13:30:54.357 | DEBUG | __main__:run_it:31 - That's it, beautiful and simple logging!" )

mayil-ai[bot] commented 3 months ago

Possible Solution

Code snippets to check

loguru → _logger.py This snippet contains the logic for formatting the log message, which is relevant to the issue of the custom handler receiving a formatted message instead of the original text. https://github.com/Mayil-AI/loguru/blob/871de74acb2382fb3982d3fb8e224e4a82de9073/loguru/_logger.py#L1981-L2033
loguru → _handler.py This snippet is part of the handler's emit method, which is responsible for formatting the log message before passing it to the sink. It is relevant to the issue as it shows how the formatted message is created. https://github.com/Mayil-AI/loguru/blob/871de74acb2382fb3982d3fb8e224e4a82de9073/loguru/_handler.py#L152-L206 This snippet defines the emit method signature in the handler, which is the entry point for processing log records, including formatting. https://github.com/Mayil-AI/loguru/blob/871de74acb2382fb3982d3fb8e224e4a82de9073/loguru/_handler.py#L127-L127 This snippet is part of the emit method and shows conditions that could affect the formatting of the log message, which is relevant to the issue. https://github.com/Mayil-AI/loguru/blob/871de74acb2382fb3982d3fb8e224e4a82de9073/loguru/_handler.py#L129-L150