Skip to content

Commit

Permalink
Fix issue 8180. No undefined ns, name, or message. (redwoodjs#8181)
Browse files Browse the repository at this point in the history
  • Loading branch information
dthyresson authored May 4, 2023
1 parent 1177070 commit 8353290
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
16 changes: 16 additions & 0 deletions packages/api-server/src/__tests__/logFormatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ describe('LogFormatter', () => {
})
).toMatch('"environment": "staging"')

logFormatter({
level: 10,
deploy: {
environment: 'staging',
version: '4.2.1',
},
}) // ?

expect(
logFormatter({
level: 10,
Expand All @@ -243,4 +251,12 @@ describe('LogFormatter', () => {
).toMatch('"version": "4.2.1"')
})
})

it('Should not have any undefined ns, name, or message', () => {
expect(
logFormatter({
level: 10,
})
).not.toContain('undefined')
})
})
10 changes: 7 additions & 3 deletions packages/api-server/src/logFormatter/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,26 @@ export const formatMessage = (logData: any) => {
}

export const formatMethod = (method: string) => {
return chalk.white(method)
return method && chalk.white(method)
}

export const formatRequestId = (requestId: string) => {
return requestId && chalk.cyan(requestId)
}

export const formatNs = (ns: string) => {
return chalk.cyan(ns)
return ns && chalk.cyan(ns)
}

export const formatName = (name: string) => {
return chalk.blue(name)
return name && chalk.blue(name)
}

export const formatMessageName = (message: string) => {
if (message === undefined) {
return ''
}

if (message === 'request') {
return '<--'
}
Expand Down

0 comments on commit 8353290

Please sign in to comment.