hapijs / hapi-pino

🌲 Hapi plugin for the Pino logger
MIT License
148 stars 61 forks source link

Typing of logger field on Request is misleading in case of ignored routes #186

Open nlochschmidt opened 10 months ago

nlochschmidt commented 10 months ago

Runtime

node.js

Runtime version

18

Module version

12.2.0

Last module version without issue

No response

Used with

hapi application

Any other relevant information

No response

What are you trying to achieve or the steps to reproduce?

In certain cases I would like to access pino logger specific attributes and functions (e.g. bindings()) even when the route accessing logger might later be ignored using any of the ignoreX options.

What was the result you got?

TypeErrors such as logger.bindings is not a function requiring me to build checks around the presence of methods such as bindings.

What result did you expect?

I was expecting the logger instance on the request to always be of type pino.Logger, but it might be the much simpler nullLogger instance from abstract-logging that is used in case of ignored routes.

Ideally the nullLogger should be extended to implement all methods of the pino.Logger interface, alternatively the typings in hapi-pino should reflect that the logger might be missing some of the methods in pino.Logger.