hapijs / good

hapi process monitoring
Other
525 stars 161 forks source link

Fingers Crossed reporter #540

Closed cristinecula closed 7 years ago

cristinecula commented 7 years ago

Hi!

Is it possible to create a reporter that logs all events logged for the duration of a request but only in case of an error? More specifically, I am thinking about something similar to Monolog/FingersCrossedHandler.

Buffers all records until a certain level is reached

The advantage of this approach is that you don't get any clutter in your log files. Only requests which actually trigger an error (or whatever your actionLevel is) will be in the logs, but they will contain all records, not only those above the level threshold.

This way I could include verbose log messages and have access to them in the event of a critical error, aiding in debugging.

On the other hand I make heavy use of pre handlers and those don't have access to request.log so it might not be that useful (unless there is some way of accessing the request that I am not aware of).

AdriVanHoudt commented 7 years ago

See https://hapijs.com/api#route-prerequisites the method of the pre handler is the same as the one from the handler so request.log should be there?

Marsup commented 7 years ago

I guess you could, good plugin are just streams, so you just have to hold onto the events you get, store them per request id, and then start emitting them all if you see something interesting, otherwise throw them away at the end of the request. I think the latter is the most important part, making sure that you clean after yourself, if you miss the end of the request you'll be piling up logs forever.

This seems like a good idea but logs will be globally unordered as you are going to defer logs, this might be unsettling.

cristinecula commented 7 years ago

@AdriVanHoudt Oh, thanks. You are right of course.

I am using the short-hand notation for registered server methods. I actually tried sending request.log to the handler but this is not the request object and this.id throws.

pre: [ { method: "getAppData(params.app, log)", assign: "app" } ]

@Marsup Thank you for the insights!

I guess I could store the original timestamp and reorder them in an external log analyser.

Thanks for the help!

Marsup commented 7 years ago

This is not what I meant. You'll be emitting logs in bulk, so if all of the logs are grouped per request, you're not reading the logs purely chronologically but per request as well.

cristinecula commented 7 years ago

I see what you mean. The emitted log would actually be a single log item with all of the other logs inside?

In this case it would make sense to have two reporters. One standard "info" level logger and another that emits grouped up logs in case of errors to aid in debugging.

I am a novice in hapi-land and I don't have a lot of battleground experience yet. In your opinion, do you see any value in this type of logging? Or are there better approaches to gaining insight into why requests failed?

Marsup commented 7 years ago

Not a single log item but a rapid fire of several past logs.

I'm sure a plugin like that could be useful as they provide a complete failed exchange, less grepping, don't hesitate to publish it. I'm not an expert in logging but I don't think high level tools do much better than that, just a fancier UI.

cristinecula commented 7 years ago

Will do! Thanks a lot!

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.