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

json formatter #176

Closed
baddoxx opened this issue Jul 27, 2022 · 2 comments
Closed

json formatter #176

baddoxx opened this issue Jul 27, 2022 · 2 comments

Comments

@baddoxx
Copy link

baddoxx commented Jul 27, 2022

Hi - firstly thanks for creating this log handler, it's simplified things for me greatly.

however I'm unable to get things to work as described in the doco.; the example json formatter just won't work, and cannot produce the results described in the documentation. I've tried to modify it myself but I cannot find a way to make the log formatter correctly handle dictionaries passed to it, and the resulting message sent to CW is not valid json (contains ' instead of ") and is parsed as a string only.

e.g. my formatter attempt
format: '{ "timestamp" : "%(asctime)s", "process" : "%(process)d", "levelname" : "%(levelname)s", "name" : "%(name)s", "function" : "%(funcName)s", "line" : "%(lineno)s", "message" : "%(message)s" }'

and the resulting message sent to CW

{
    "timestamp": "2022-07-27 06:01:20,679",
    "process": "18421",
    "levelname": "CRITICAL",
    "name": "__main__",
    "function": "main",
    "line": "9",
    "message": "{'request': 'hello', 'metadata': {'size': 666}}"
}

can you please advise what the json formatter should be in the logging config?

best
Richard
cwtest.py.txt

@medley56
Copy link

medley56 commented Dec 7, 2022

This is a problem for me as well. I think the specific problem is lack of support for nested JSON objects. If this is supported, what is the magic incantation? If it's not, can it be added?

@kislyuk
Copy link
Owner

kislyuk commented Feb 22, 2023

Thank you for your interest in Watchtower. If you want to log JSON, do not use a formatter that formats your message as a non-JSON string.

I agree the documentation of the logging system YAML config was misleading. It was originally contributed by a third party and I failed to thoroughly vet it. I deleted all mention of formatters from that part of the documentation.

To be clear, JSON and nested JSON objects are supported and have been supported by Watchtower since day one, as illustrated in line 6 of the first code block in the readme.

@kislyuk kislyuk closed this as completed Feb 22, 2023
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

3 participants