From 6c6924997f7b81ef7e4745fdd54572c1331971bc Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Thu, 2 Jan 2025 16:06:30 -0500 Subject: [PATCH] fix: Do not allow logger and loggerInstance to simultaneously exist in fastifyOptions --- src/app.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/app.ts b/src/app.ts index f8fdf950..462f5123 100644 --- a/src/app.ts +++ b/src/app.ts @@ -8,10 +8,23 @@ import remoteCache from './plugins/remote-cache/index.js' const uuid = hyperid({ urlSafe: true }) export function createApp(options: FastifyServerOptions = {}): FastifyInstance { + const fastifyOptions: FastifyServerOptions = { + ...options, + } + + const hasConfiguredLogger = + 'logger' in fastifyOptions || 'loggerInstance' in fastifyOptions + + /** + * Fastify does not allow both loggerInstance and logger to be set + */ + if (!hasConfiguredLogger) { + fastifyOptions.loggerInstance = logger + } + const app = Fastify({ - loggerInstance: logger, genReqId: () => uuid(), - ...options, + ...fastifyOptions, }) app.register(config).after(() => {