Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 96 additions & 38 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"uuid": "^11.1.0",
"uuid-by-string": "^4.0.0",
"validator": "^13.15.23",
"winston": "^3.13.0",
"winston": "^3.19.0",
"winston-cloudwatch": "^6.3.0",
"zod": "^3.24.3"
},
Expand Down Expand Up @@ -246,4 +246,4 @@
"arch": "x64"
}
}
}
}
18 changes: 10 additions & 8 deletions src/app/config/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import omit from 'lodash/omit'
import logform from 'logform'
import path from 'path'
import tripleBeam from 'triple-beam'
import { SPLAT } from 'triple-beam'
import { inspect } from 'util'
import { v4 as uuidv4 } from 'uuid'
import { format, Logger, LoggerOptions, loggers, transports } from 'winston'
Expand Down Expand Up @@ -37,8 +37,10 @@ export type CustomLoggerParams = {
const errorHunter = logform.format((info) => {
if (info.error) return info

const splat = info[tripleBeam.SPLAT as any] || []
info.error = splat.find((obj: any) => obj instanceof Error)
const splat = info[SPLAT]
if (Array.isArray(splat)) {
info.error = splat.find((obj: any) => obj instanceof Error)
}

return info
})
Expand All @@ -47,9 +49,8 @@ const errorHunter = logform.format((info) => {
* Formats the error in the transformable info to a console.error-like format.
*/
const errorPrinter = logform.format((info) => {
if (!info.error) return info
if (!info.error || !(info.error instanceof Error)) return info

// Handle case where Error has no stack.
const errorMsg = info.error.stack || info.error.toString()
info.message += `\n${errorMsg}`

Expand Down Expand Up @@ -106,9 +107,10 @@ export const customFormat = format.printf((info) => {
// e.g. logger.info('param1', 'param2')
// The second parameter onwards will be passed into the `splat` key and
// require formatting (because that is just how the library is written).
const splatSymbol = Symbol.for('splat') as unknown as string
const splatArgs = info[splatSymbol] || []
const rest = splatArgs.map((data: any) => formatWithInspect(data)).join(' ')
const splatArgs = info[SPLAT]
const rest = Array.isArray(splatArgs)
? splatArgs.map((data: any) => formatWithInspect(data)).join(' ')
: ''
const msg = formatWithInspect(info.message)

return `${info.timestamp} ${info.level} [${info.label}]: ${msg}\t${duration}\t${rest}`
Expand Down
Loading