hapi-pino icon indicating copy to clipboard operation
hapi-pino copied to clipboard

multiple registrations not allowed

Open fcesgpfedef opened this issue 4 years ago • 4 comments

Hi,

We have written two custom plugins using hapi-pino for our project written on hapi20 and registered both the plugins with different options. When I am starting the server I am seeing the error hapi-pino is already registered. Any reason why hapi-pino is not supporting multiple registrations?

How can I resolve this issue in my project ? Any help is appreciated, Thanks.

fcesgpfedef avatar Mar 25 '21 06:03 fcesgpfedef

I don't know, I'm not using Hapi anymore :(. I'm not sure this is possible with Hapi.

mcollina avatar Mar 25 '21 14:03 mcollina

Hapi docs: https://hapi.dev/api/?v=20.1.0#plugins

felixheck avatar Mar 26 '21 11:03 felixheck

You can force the multiple registrations by using once: true when calling server.register()

osukaa avatar Jun 07 '21 15:06 osukaa

Using once here won't do the job because if you are setting different options in the two hapi-pino registrations, hapi will only recognize one of those options and apply it to both.

As for why hapi-pino cannot support multiple registrations, the server.decorate('server', 'logger', logger) is to blame for this. The server decoration cannot be defined twice.

thsmale avatar Dec 13 '22 02:12 thsmale