0

My problem: I try to send logs from python3 project via logging module to fluentd.

log = '{"@timestamp":"2020-06-18T11:52:37.391","severity":"INFO", "message":"Processing request started"}'
logging.error(json.dumps(log))

At fluentd I get such error:

pattern not matched data="<14>{"@timestamp":"2020-06-18T11:52:37.391","severity":"INFO", "message":"Processing request started"}\x00"

I see strange symbols, <14> and \x00. When I try to send same string via bash console --everything works well

echo -n '{"@timestamp":"2020-06-18T11:52:37.391","severity":"INFO", "message":"Processing request started"}' > /dev/udp/HOST/PORT

Looks like there are some problems with encoding, but I can't recognise how to fix this error in python.

Slavka
  • 1,070
  • 4
  • 13
  • 28
  • Have you tried removing non-printable characters from the string? – JoshG Jun 19 '20 at 06:20
  • yes, tried via .replace method after `json.dumps()`, nothing changed – Slavka Jun 19 '20 at 06:26
  • What about trying this approach for removing them? https://stackoverflow.com/a/8689826 – JoshG Jun 19 '20 at 06:31
  • [json.dumps](https://docs.python.org/3/library/json.html) encodes *a python data structure* into a json string. If you encode a string it still works, it escapes all the quotes – Pynchia Jun 19 '20 at 06:54

0 Answers0