Mayil-SB-Internal-Prod / loguru-II

MIT License
0 stars 0 forks source link

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

Open vikramsubramanian opened 6 months ago

vikramsubramanian commented 6 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 6 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. https://github.com/Mayil-SB-Internal-Prod/loguru-II/blob/dcf42d962567723c0195bb8b2bb6fd764ecf41ae/loguru/_logger.py#L1981-L2033
loguru → _handler.py This snippet is part of the handler's emit method, which is responsible for the final formatting of the log message before it is passed to the handler. It is relevant because it shows how the formatted message is created. https://github.com/Mayil-SB-Internal-Prod/loguru-II/blob/dcf42d962567723c0195bb8b2bb6fd764ecf41ae/loguru/_handler.py#L152-L206 This snippet defines the emit method signature, which is the entry point for a log record into a handler. It is relevant to understand how the record is passed to the emit method. https://github.com/Mayil-SB-Internal-Prod/loguru-II/blob/dcf42d962567723c0195bb8b2bb6fd764ecf41ae/loguru/_handler.py#L127-L127 This snippet is part of the emit method and shows conditions that could affect the log record before it is formatted, which is relevant to the issue. https://github.com/Mayil-SB-Internal-Prod/loguru-II/blob/dcf42d962567723c0195bb8b2bb6fd764ecf41ae/loguru/_handler.py#L129-L150