hapijs/hapi-pino

proposal for a new option: ignoreFunc

Closed this issue · 1 comments

Currently hapi-pino provides ignorePaths and ignoreTags. They are useful to a certain degree, but for some cases it's still impossible to silent hapi-pino for some routes.

The use case I have in mind are routes for static files (which are usually defined with path: /foo/bar/{file*}). I want those to be silent. I can add a tag to these routes and use that tag in ignoreTags. That will work for the "request completed" log, however the "request start" log will still happen (because that log is defined in the onRequest extension point, and at that point the route is not yet located).

I'd like to propose a 3rd ignore option:

options.ignoreFunc: (options, Request) => boolean

It would be a simple addition to the internal isLoggingIgnored function: if option.ignoreFunc is present, it will execute and return the value; else, it will proceed with the current logic (which will check ignorePaths and ignoreTags, and also returns a boolean).

These 3 ignore options wouldn't be compatible obviously (either use ignorePaths/ignoreTags or ignoreFunc).

This way hapi-pino would provide the maximum flexibility to the user. If there's interest in this feature I would make a pr.

Thanks for considering.

Sure thing, send a PR. Remember to add unit tests