Files
speckle-server/packages/shared/pinoPrettyTransport.js
T
Kristaps Fabians Geikins 4144ce0d8e feat(fe2): improved and more thorough logging to help with observability (#1948)
* better req log text

* minor improvements to server logging

* WIP FE2 req logging

* FE2 apollo operation logging

* undid apolloPlugin changes due to Gergos PR

* seq message templates introduced
2024-01-11 12:15:45 +02:00

26 lines
796 B
JavaScript

const { get, isString, isNumber, isBoolean } = require('lodash')
// https://github.com/pinojs/pino-pretty?tab=readme-ov-file#handling-non-serializable-options
module.exports = (opts) =>
require('pino-pretty')({
...opts,
/**
* Custom formatter to enable value interpolation locally
* @param {Record<string, unknown>} log
* @param {string} messageKey
*/
messageFormat: (log, messageKey) => {
const msg = log[messageKey]
if (!msg) return undefined
return msg.replace(/{([^{}]+)}/g, (match, p1) => {
const val = get(log, p1)
if (val === undefined) return match
const formattedValue =
isString(val) || isNumber(val) || isBoolean(val) ? val : JSON.stringify(val)
return formattedValue
})
}
})