-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Additional configuration options for RequestLogger and Logger middleware #2341
Conversation
… to handle error within middleware with global error handler thus setting response status code decided by error handler and not derived from error itself.
…add custom text to logged row.
Codecov ReportBase: 92.38% // Head: 92.69% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #2341 +/- ##
==========================================
+ Coverage 92.38% 92.69% +0.30%
==========================================
Files 37 37
Lines 4454 4460 +6
==========================================
+ Hits 4115 4134 +19
+ Misses 247 238 -9
+ Partials 92 88 -4
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
@lammel please re-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about the implications of the custom tag I find arbitrary binary data being modified for a custom tag having the potential to shout yourself in the foot and write invalid JSON because of typos or dangling commas.
As it's only for logging it will only affect the logserver in the background. The HandleError directive might cause unexpected side-effects which might be hard to debug.
I tend to approve, as defaults are sane and people should know what the are doing.
We might emphasize that more in the code comments with a "WARNING" for both new options.
There is comment for that field
|
Is using a dedicated interface instead of binary data for the customTag field an option? // CustomTagFields may hold additional custom fields or text that is replaced for the `${custom}` tag to write custom user data into the output buffer
// Optional.
CustomTagFields *CustomTagFields The CustomTagFields would hold a map[string]any and needs an
Agreed. Now it's even documented here :) |
I think interface would be over complicating this thing. Moreover - that log row does not need to be even formatted as JSON. You could create template that has Apache or Nginx request log format. and having multiple tags as map/slice means that these custom tags could overlap with potential tags that we could add in future. by adding single one - we reserve single tag and give us room to add tag with any name in future. If user want to write multiple tags - he/she can do this within this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then let's keep it simple for now. Approved!
middleware.RequestLoggerConfig.HandleError
configuration option to handle error within middleware with global error handler thus setting response status code decided by error handler and not derived from error itself.middleware.LoggerConfig.CustomTagFunc
so Logger middleware can add custom text/fields etc to logged (JSON or whatever format) row.