-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure
loggingLevels
is respected (#10308)
Issue #10272 Adds `logError` utility that can be used across the codebase for logging errors
- Loading branch information
Showing
10 changed files
with
72 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type pino from 'pino' | ||
|
||
import type { Payload } from '../types/index.js' | ||
|
||
export const logError = ({ err, payload }: { err: unknown; payload: Payload }): void => { | ||
let level: false | pino.Level = 'error' | ||
|
||
if ( | ||
err && | ||
typeof err === 'object' && | ||
'name' in err && | ||
typeof err.name === 'string' && | ||
typeof payload.config.loggingLevels[err.name] !== 'undefined' | ||
) { | ||
level = payload.config.loggingLevels[err.name] | ||
} | ||
|
||
if (level) { | ||
const logObject: { err?: unknown; msg?: unknown } = {} | ||
|
||
if (level === 'info') { | ||
logObject.msg = typeof err === 'object' && 'message' in err ? err.message : 'Error' | ||
} else { | ||
logObject.err = err | ||
} | ||
|
||
payload.logger[level](logObject) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters