Skip to content

Commit

Permalink
fix: Do not allow logger and loggerInstance to simultaneously exist i…
Browse files Browse the repository at this point in the history
…n fastifyOptions
  • Loading branch information
NullVoxPopuli committed Jan 2, 2025
1 parent b891c7f commit 6c69249
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit 6c69249

Please sign in to comment.