Skip to content

Commit

Permalink
Merge pull request #216 from DEFRA/pino-updates
Browse files Browse the repository at this point in the history
Update Pino logger packages + type fixes
  • Loading branch information
colinrotherham authored May 30, 2024
2 parents 2753663 + 621fc53 commit 4a2d57e
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 25 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ updates:
- 'lint-staged'
- 'prettier'

logging:
patterns:
- '*-pino'
- '*-pino-format'
- 'pino'
- 'pino-*'

tools:
patterns:
- '@testing-library/*'
Expand Down
4 changes: 2 additions & 2 deletions designer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"luxon": "^3.4.4",
"nanoid": "^3.3.4",
"nunjucks": "^3.2.4",
"pino": "^8.20.0",
"pino": "^9.1.0",
"prismjs": "^1.29.0",
"react": "^16.14.0",
"react-dom": "^16.14.0",
Expand All @@ -86,7 +86,7 @@
"jsdom": "^24.1.0",
"mini-css-extract-plugin": "^2.9.0",
"outdent": "^0.8.0",
"pino-pretty": "^11.0.0",
"pino-pretty": "^11.1.0",
"postcss": "^8.4.38",
"postcss-loader": "^8.1.1",
"sass-embedded": "^1.75.0",
Expand Down
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
*/
77 changes: 64 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4a2d57e

Please sign in to comment.