-
Notifications
You must be signed in to change notification settings - Fork 1
Fix browser logging fixes #296
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
Conversation
// Use any specified log level, or warn in production/browser, info otherwise | ||
/* eslint-disable no-restricted-globals */ | ||
level: | ||
typeof process !== 'undefined' && process.env.LOG_LEVEL |
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.
π§ The fix: we now check that process
is defined before accessing
} catch (err: any) { | ||
logger.error('Error logging bandit event', err); | ||
} catch (err) { | ||
logger.error({ err }, 'Error logging bandit event'); |
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.
Pino's API (link) is to have context first, then the log message.
? process.env.LOG_LEVEL | ||
: typeof process === 'undefined' || process.env.NODE_ENV === 'production' | ||
? 'warn' | ||
: 'info', |
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.
https://getpino.io/#/docs/api?id=level-string
Looks like it defaults to 'info'
anyway, but I like that it's explicit here
π― Related PR:
js-client-sdk #257
Eppo Only:
ποΈ Tickets:
Motivation and Context
This common repository is shared with the Node.js and Browser JavaScript SDKs. The latter won't have a global
process
, causing errors unless a dummy globalprocess
is defined.Also, currently, logging is hard-coded to be off (silent) for the Browser SDK. However, having logs can be helpful, especially for debugging.
Description
This PR does not assume
process
will be defined.It also changes the logger's default log level for browser to be
warn
instead of forced off. There is a newsetLogLevel()
method that can be called to change that if desired.How has this been documented?
eppo-docs #698
- Documentation for setLogLevel()How has this been tested?
process
. Also I saw no logs by default, error if I provided a bad SDK key, and then all the info logs if I changed the log level on purpose.