Skip to content
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

Merged
merged 5 commits into from
Nov 4, 2023
Merged

Conversation

estrattonbailey
Copy link
Member

@estrattonbailey estrattonbailey commented Nov 4, 2023

This is a port of the logger I wrote at a previous job for a RN application. Couple of key benefits:

  • supports stuff you'd expect like log levels and debug contexts
  • helps us report more specific/actionable errors to Sentry
  • handles formatting and pretty printing
  • will help clear up noise in the console once we port over usages

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.

Comment on lines +16 to +19
"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",
Copy link
Member Author

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
Copy link
Member Author

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",
Copy link
Member Author

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...

Comment on lines +1 to +9
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'
Copy link
Member Author

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.

Copy link
Collaborator

@pfrazee pfrazee left a 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

Comment on lines +8 to +10
export const DebugContext = {
// e.g. composer: 'composer'
} as const
Copy link
Member Author

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
Copy link
Member Author

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

@estrattonbailey estrattonbailey merged commit e49a3d8 into main Nov 4, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants