-
-
Notifications
You must be signed in to change notification settings - Fork 301
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
Add on additional fields to all log entries #303
base: master
Are you sure you want to change the base?
Add on additional fields to all log entries #303
Conversation
c2bd7a4
to
4c65224
Compare
Allows for the added payload fields in lograge to surface in logs outside of just controller logs.
4c65224
to
c95bc76
Compare
@bcharna I think I'm looking for something similar to you, at least conceptually, but I'm having a trouble applying your approach to my desired goal, which is simpler than yours. My goal is to trigger another line of log, similar to one that Lograge would trigger. Not looking for any third party loggers like LogStashLogger. I just want to trigger what Lograge would normally trigger - including my custom paylods and options.
Any ideas how I would do it? I don't have any |
@bcharna Pardon my ignorance - I didn't spot it was a PR. Thought it was just an issue. ;) I set what you did there and will repurpose it for my use. Thank you for this contribution. |
@bcharna Here's my feedback on your PR:
|
hey @Nowaker, thank you for these notes. I'm a bit far removed from this PR and likely will not be able to dig deeper into it anytime soon. But I'd be happy if someone can pick it up and improve it or gain some traction on supporting something along these lines. |
Problem
#255 and #272 highlight the problem. To summarize, it's great that lograge by default tacks on fields like 'action', 'controller', 'format', etc onto the controller log entries. But it's unfortunate that other log entries triggered throughout the request do not have these fields tacked on.
Goal
The goal of this PR is to make it so that you can opt into having all log entries (even those triggered from third-party gems) within a request have the default fields that lograge typically adds on, plus any fields added on by the user's supplied
config.lograge.custom_payload
by using a special formatter.Example Config
Below is an example of how the newly added formatter,
Lograge::LogStashLoggerFormatters::MergedWithLogragePayload
, can be used to add all the fields on all the log entries.Open Questions
I have left a couple of
TODO
s in the code that I think warrant more discussion; please feel free to comment and we can come to a consensus on the right approach.Limitations
Logs triggered from middleware that is run before the Rails application is run will not get the additional fields tacked on because this change relies on the start_processing.action_controller event. As far as I can tell, there is no trivial fix for this, though this can be revisited later.
Callouts