-
Notifications
You must be signed in to change notification settings - Fork 565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: log unexpected GraphQL errors #2084
Conversation
|
maskError: (error, message) => { | ||
const newError = maskErrorFn( | ||
{ | ||
error, | ||
message, | ||
isDev: this.maskedErrorsOpts?.isDev ?? false, | ||
}, | ||
message, | ||
) | ||
|
||
if (newError !== error) { | ||
this.logger.error(error) | ||
} | ||
|
||
return newError | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case error masking is disabled that means that every error is an expected error - thus we shouldn't log any error.
const logLevelScores: Record<LogLevel | 'silent', number> = { | ||
debug: 0, | ||
info: 1, | ||
warn: 2, | ||
error: 3, | ||
silent: 4, | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
const noop = () => {} | ||
|
||
/** | ||
* utility for creating a conditional logger for tests. | ||
*/ | ||
export const createCustomLogger = ( | ||
logLevel: LogLevel | 'silent' = globalThis?.process.env['DEBUG'] === '1' | ||
? 'debug' | ||
: 'info', | ||
) => { | ||
const score = logLevelScores[logLevel] | ||
return { | ||
debug: score > logLevelScores.debug ? noop : debugLog, | ||
info: score > logLevelScores.info ? noop : infoLog, | ||
warn: score > logLevelScores.warn ? noop : warnLog, | ||
error: score > logLevelScores.error ? noop : errorLog, | ||
} | ||
} | ||
|
||
const consoleLog = (...args: Array<any>) => console.log(...args) | ||
|
||
const debugLog = console.debug | ||
? (...args: Array<any>) => console.debug(...args) | ||
: consoleLog | ||
const infoLog = console.info | ||
? (...args: Array<any>) => console.info(...args) | ||
: consoleLog | ||
const warnLog = console.warn | ||
? (...args: Array<any>) => console.warn(...args) | ||
: consoleLog | ||
const errorLog = console.error | ||
? (...args: Array<any>) => console.error(...args) | ||
: consoleLog |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kamilkisiela We can use this logger implementation in hive in case my proposal does not make it into yoga v3.
✅ Benchmark Results
|
🚀 Website PreviewThe latest changes to the website are available as preview in: https://260d9549.graphql-yoga.pages.dev |
closes #1584