Mayil-AI / loguru

MIT License
0 stars 0 forks source link

Colors not rendering in Apache WSGI logs (hashtag1026) #15

Open vikramsubramanian opened 3 months ago

vikramsubramanian commented 3 months ago

I integrated loguru with a django application with this handler.

    dict(
        sink=sys.stderr,
        format="<g>{time:YYYY ddd MMM DD HH:mm:ss.SSSSSSZZ}</g>",
        colorize=True,
        backtrace=False, 
        diagnose=True,  
        catch=True, 
    ),

When I try to use django's inbuilt webserver to serve the application, the colors are shown just fine but for production environment, I use Apache WSGI to serve django application, the logs print fine in apache logs, but the colors are shown as codes instead of the actual color.

\x1b[32m2023 Sun Nov 26 23:44:55.622738+0000\x1b[0m - Apache Logs

![image]( - Django Development Server logs

I tested Apache Logs both on gitbash and command prompt

)

mayil-ai[bot] commented 3 months ago

Possible Solution

Code snippets to check

loguru → _colorama.py This snippet contains the logic to determine if the output should be colorized, which is directly related to the issue of colors not rendering properly in Apache WSGI logs. https://github.com/Mayil-AI/loguru/blob/871de74acb2382fb3982d3fb8e224e4a82de9073/loguru/_colorama.py#L1-L67
loguru → _colorizer.py This snippet contains the logic for substituting color tags with ANSI codes, which is relevant to the issue since the colors are shown as codes instead of the actual color in Apache logs. https://github.com/Mayil-AI/loguru/blob/871de74acb2382fb3982d3fb8e224e4a82de9073/loguru/_colorizer.py#L274-L309 This snippet deals with the colorization of messages and may be relevant to understand how the colorization process is applied to log messages. https://github.com/Mayil-AI/loguru/blob/871de74acb2382fb3982d3fb8e224e4a82de9073/loguru/_colorizer.py#L312-L350 This snippet defines background color codes and may be relevant to the issue if the problem is related to the background color rendering. https://github.com/Mayil-AI/loguru/blob/871de74acb2382fb3982d3fb8e224e4a82de9073/loguru/_colorizer.py#L132-L214
loguru → _better_exceptions.py This snippet includes default color themes and initialization of colorization settings, which could be relevant to the issue if default settings are affecting the color output in Apache WSGI logs. https://github.com/Mayil-AI/loguru/blob/871de74acb2382fb3982d3fb8e224e4a82de9073/loguru/_better_exceptions.py#L122-L190