Skip to content

Commit

Permalink
Narrow logger types to avoid TransportMultiOptions mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed May 30, 2024
1 parent 0e182ca commit 621fc53
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
18 changes: 10 additions & 8 deletions designer/server/src/common/helpers/logging/logger-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ import { ecsFormat } from '@elastic/ecs-pino-format'
import config from '~/src/config.js'

/**
* @type {import('pino').LoggerOptions}
* @satisfies {LoggerOptions}
*/
export const loggerOptions = {
redact: {
paths: ['req.headers.authorization', 'req.headers.cookie', 'res.headers'],
remove: true
},
level: config.logLevel,
...(config.isProduction
? ecsFormat()
: {
transport: {
target: 'pino-pretty'
}
})
...(config.isDevelopment
? /** @type {LoggerTransport} */ ({ transport: { target: 'pino-pretty' } })
: /** @type {LoggerFormat} */ (ecsFormat()))
}

/**
* @typedef {import('pino').LoggerOptions} LoggerOptions
* @typedef {{ transport: import('pino').TransportSingleOptions }} LoggerTransport
* @typedef {Pick<LoggerOptions, 'messageKey' | 'timestamp' | 'formatters'>} LoggerFormat
*/
14 changes: 12 additions & 2 deletions designer/server/src/common/helpers/logging/request-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ import hapiPino from 'hapi-pino'

import { loggerOptions } from '~/src/common/helpers/logging/logger-options.js'

const requestLogger = {
/**
* @satisfies {ServerRegisterPluginObject<Options>}
*/
export const requestLogger = {
plugin: hapiPino,
options: loggerOptions
}

export { requestLogger }
/**
* @template {object | void} [PluginOptions=void]
* @typedef {import('@hapi/hapi').ServerRegisterPluginObject<PluginOptions>} ServerRegisterPluginObject
*/

/**
* @typedef {import('hapi-pino').Options} Options
*/

0 comments on commit 621fc53

Please sign in to comment.