Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue [null] null: null maybe caused by structlog or colorama #106

Open
fraser-langton opened this issue Jan 24, 2025 · 3 comments
Open

Comments

@fraser-langton
Copy link

When the plugin is disabled the [null] null: null text does not show, thought maybe it was from colorama using the ansi chars. I did a few things to try and fix like ensuring a reset ansi character was before the json but that didn't help. I tried adding a new line, but that stopped the json folding working at all.

here is some raw ansi that caused the issue

\x1b[2m2025-01-24 02:46:20\x1b[0m [\x1b[33m\x1b[1mwarning  \x1b[0m] \x1b[1mNot Found: /au/api/v1/customers/club/\x1b[0m [\x1b[0m\x1b[1m\x1b[34mdjango.request\x1b[0m]\x1b[0m\x1b[0m {"filepath": "/opt/venv/lib/python3.12/site-packages/django/utils/log.py:241"}

I checked and the ansi looks valid and should have this effect (I used xml like tags to illustrate)

<dim>2025-01-24 02:46:20</dim> 
[<yellow><bold>warning</bold></yellow>] 
<bold>Not Found: /au/api/v1/customers/club/</bold> 
[<bold><blue>django.request</blue></bold>] 
{"filepath": "/opt/venv/lib/python3.12/site-packages/django/utils/log.py:241"}

Image

@fraser-langton
Copy link
Author

Ok I think I see why, it wasn't quite clear form the docs that there were reserved keywords in the log event (level, timestamp, message) and so that's why they are all null for me

Perhaps allow a option to disable formatting in the plugin? ie then I can leave the formatting up to myself?

Also perhaps make timestamp and level optional

@orangain
Copy link
Owner

@fraser-langton Thank you for reporting the issue! As you say, the display of [null] null: null is due to this plugin.

Normally, this plugin only tries to format and display when the entire line is JSON. However, perhaps due to the ANSI color code, it may not be able to correctly recognize the line break.

It is difficult to fundamentally fix this behavior, but it is possible to temporarily disable the formatting from the console context menu. Is this a solution for you?

@fraser-langton
Copy link
Author

I found even turning off colours didn't fix it, it then just displayed the json raw

app-1  |  {"correlation_id": "49192939521365a20be056a9d71fbaf4", ...}

Image

however adding a ansi reset all char before each log fixed it, i made a structlog processor

def pretty_json_log(logger: WrappedLogger, name: str, event: str) -> str:
    return f"{_ColorfulStyles.reset}{event}"

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants