-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add new logger #1813
Add new logger #1813
Conversation
"test": "NODE_ENV=test jest --forceExit --testTimeout=20000 --bail", | ||
"test-watch": "NODE_ENV=test jest --watchAll", | ||
"test-ci": "NODE_ENV=test jest --ci --forceExit --reporters=default --reporters=jest-junit", | ||
"test-coverage": "NODE_ENV=test jest --coverage", |
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.
Making sure logging isn't enabled in test modes
@@ -1 +1,3 @@ | |||
SENTRY_AUTH_TOKEN= | |||
EXPO_PUBLIC_LOG_LEVEL=debug |
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.
This env var will need to be added to prod builds, probably set to info
but up for discussion
@@ -80,6 +80,7 @@ | |||
"babel-plugin-transform-remove-console": "^6.9.4", | |||
"base64-js": "^1.5.1", | |||
"bcp-47-match": "^2.0.3", | |||
"date-fns": "^2.30.0", |
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.
Do we have something else in here already...
export const IS_TEST = process.env.NODE_ENV === 'test' | ||
export const IS_DEV = __DEV__ | ||
export const IS_PROD = !IS_DEV | ||
export const LOG_DEBUG = process.env.EXPO_PUBLIC_LOG_DEBUG || '' | ||
export const LOG_LEVEL = (process.env.EXPO_PUBLIC_LOG_LEVEL || 'info') as | ||
| 'debug' | ||
| 'info' | ||
| 'warn' | ||
| 'error' |
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.
I've found a module file to be super helpful with testing since you can mock the variables more easily than globals. Expo automatically replaces process.env.<var>
calls with the strings.
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.
Nice! I just reviewed the code, havent tested, but lgtm
export const DebugContext = { | ||
// e.g. composer: 'composer' | ||
} as const |
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.
First ones I'd add are contexts for session model, feeds related (especially polling), analytics, notifications
@@ -41,7 +41,7 @@ export type AppInfo = z.infer<typeof appInfo> | |||
export class RootStoreModel { | |||
agent: BskyAgent | |||
appInfo?: AppInfo | |||
log = new LogModel() | |||
log = logger |
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.
Just did this for now to show how it's a drop-in replacement
This is a port of the logger I wrote at a previous job for a RN application. Couple of key benefits:
Peep first commit for actual code. Subsequent commits were fixing TS errors and replacing instances of passing an
Error
class as the second argument. This would really be fine, but we should be consistent.