-
Notifications
You must be signed in to change notification settings - Fork 117
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
Fix request on error logger #45
Conversation
'err' is never passed into the event callback, use the response object as the err transport
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.
Good catch! Can you add a unit test for this?
Thinking about it some more, I think we have to support both things, as other frameworks might emit errors as |
I was pretty sure this is an express only package, since I came here from express-pino-logger |
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.
LGTM
logger.js
Outdated
|
||
var log = this.log | ||
var responseTime = Date.now() - this[startTime] | ||
|
||
if (err) { | ||
if (err || this.err || this.statusCode >= 400) { |
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.
I think this should be >= 500
, not 400
.
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.
I think that you'd want to have logs of issues like: bad request, unauthorized, forbidden access
And besides, we want to log the request / response, and a 4xx is a request (client) error.
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.
Non of them are errors.
This is a flow for error conditions.
@jsumners what do you think?
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.
One more point on my side, if I'd look at a logs dashboard, I'd be looking to see 4xx responses as errors. These can indicate a broken client side library, broken flow somewhere, etc.
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.
Looks like it got resolved before I came around. I'm fine with the current solution.
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.
I’m very opposed to land this in the current form.
I’m also ok in removing the check on the status code (as it was before).
Basically, we can leave it up to the user to set the |
I think so, yes. |
Modified. Not sure it notified you, as the commit and your message happened pretty much the same time... so I'm sending a message. |
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.
LGTM
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.
LGTM
The
err
param inonResFinished(err)
was alwaysundefined
no matter what the result of the request was.From nodejs / express documentation, there is no event named
error
:The
res
object can be used as a theerr
holder, and set on theres
object in the express error handler middlewareIf no
err
object on the response but a badstatusCode
, we generate the error from the logger. I know this would show a somewhat confusing stack, but it's something.Besides the
stdSerializers.err
handles string error as an array of chars.