ougai
ougai copied to clipboard
json log formatter ignores with_newline flag when jsonize is false
I wanted to change log format from json to hash, and tried below
logger.formatter.jsonize = false
logger.formatter.with_newline = true
Unfortunately this will produce log without newline because as shown in code below, with_newline flag is ignored if jsonize is false
https://github.com/tilfin/ougai/blob/5584cd00b73d9ca09255d7703c33610a4ca41435/lib/ougai/formatters/for_json.rb#L39
I'm happy to send PR to change behaviour but technically this will be breaking behaviour change so wanted to first open the issue.
When jsonize
option is false, Ougai does not write a string to log files or STDOUT. it pass hash object to the logdevice.
ref) https://github.com/tilfin/ougai/wiki/Forward-logs-to-Fluentd
What log format do you want at last?
Thanks for quick response. My end goal was to send log to GCP.
It seems that if you log string with json (like buyan formatter), GCP's log agent (which I think also is fluentd) just ignored my log entry. Problem is I cannot find log format the agent like, so I end up disabling jsonize.
With jsonize=false with default formatter, we at least was able to get log recognized, but multiple log entries were concatenated.
I endup writing custom formatter to make GCP (and datadog which we finally use for consuming log) happy, but if you have any suggestion that is appreciated.
I wrote this a long time ago, but it may be helpful. https://github.com/tilfin/fluent-plugin-bunyan-to-google-cloud-logging