Skip to content

Commit

Permalink
fix: fix printing of log context
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslav-fedyshyn-nordwhale committed Jul 16, 2020
1 parent 3c38332 commit 3309b3b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/imports/logger.js
Expand Up @@ -40,9 +40,13 @@ const formatLogValue = value => {
return value
}

const { name, message, stack } = value
const error = {}

return `${name}: ${message}\n${stack}`
Object.getOwnPropertyNames(value).forEach(key => {
error[key] = value[key]
})

return error
}

const logger = winston.createLogger({
Expand All @@ -52,8 +56,8 @@ const logger = winston.createLogger({
timestamp(),
format.errors({ stack: true }),
printf(({ level, timestamp, from, userId, ...rest }) => {
const logPayload = mapKeys(rest, (_, key) => (key === SPLAT ? 'context' : key))
const stringifiedPayload = JSON.stringify(logPayload, (_, logValue) => formatLogValue(logValue))
const context = rest[SPLAT]
const stringifiedPayload = JSON.stringify({ ...rest, context }, (_, logValue) => formatLogValue(logValue))

return colorizer.colorize(
level,
Expand Down

0 comments on commit 3309b3b

Please sign in to comment.