I building an app with node.js and express. I have started using bunyan
but I am having a hard time understanding hot to log requests.
Say that my router calls a function like this:
function(request, someOtherStuff, done){\\do something}
where request
is generated from a POST request, and has some stuff in request.body
.
I would like to do the following: when an error occurs inside the function I would like to log the error, as well as the request (including the req.body
) from the user. Something like:
if(err) {
bunyan.error(err,request);
done(err);
}
I know I can use serializers: {req: reqSerializer}
in the bunyan configuration, but I could not find any examples where a request is actually logged.
Any suggestion is highly appreciated.