watchtower icon indicating copy to clipboard operation
watchtower copied to clipboard

json formatter

Open baddoxx opened this issue 2 years ago • 0 comments

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

baddoxx avatar Jul 27 '22 06:07 baddoxx