Open mvastola opened 2 years ago
Yes, the same way Rails Semantic Logger swapped out the Rails built-in log subscriber, you can swap out the Rails Semantic Logger built-in log subscriber with your own.
Rather than changing the message itself, other developers add log tags to every request, using config.log_tags
, or use the builtin Rails method append_info_to_payload
to add controller specific log tags to your output?
I know the LogSubscriber
can be replaced, but that would require duplicating all the other features of this gem, which are great.
And yes, log tags are very helpful, and I do plan to use them, but we aggregate logs from many different sources and we usually just show the message and then you can click the entry to view details. I was hoping there could be some way to make the message more informative.
I have a similar issue. My use case is Rails running in Docker with a read-only filesystem. This runs in Google Cloud Platform so logs sent to stdout are collected in Cloud Logging automatically, and Cloud Logging likes fluentd formatting so I send logs formatted as :fluentd
.
When I view the logs in Cloud Logging all I see is "Completed #show" until I click on it to show the jsonPayload. It would be great if I could say "set the message field to the output of :default
and set the jsonPayload field to the output of :fluentd
" so that I get the best of both worlds: a one-line text string that I can read at a glance and the structured JSON data that makes the logs easier to query.
I hope this helps illustrate the utility of customizing message
. I know I could define my own formatter but it would be nice to have as a configurable option.
Sounds like a common need, anyone want to submit a pull request with a solution?
Is there any way you could add the ability to override the message that is logged with given events? (For example, in lieu of
Completed ##{payload[:action]}
)A simple implementation could be to replace the message with one from the payload if set at a certain key.
Unfortunately, it's not easy to do otherwise via monkeypatching or similar because blocks (instead of functions) are used to generate log data (example).
Environment