-
Notifications
You must be signed in to change notification settings - Fork 83
fix: Added logger for react native which uses console.warn for error #360
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
Changes from 1 commit
5d97c0c
f3df4a1
2f3e7c4
a640d79
6f933ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
2. Added ReactNative logger in optimizely-sdk package.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| var LogLevel = require('@optimizely/js-sdk-logging').LogLevel; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add the license header comment here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change this to |
||
|
|
||
| function getLogLevelName(level) { | ||
| switch(level) { | ||
| case LogLevel.INFO: return 'INFO'; | ||
| case LogLevel.ERROR: return 'ERROR'; | ||
| case LogLevel.WARNING: return 'WARNING'; | ||
| case LogLevel.DEBUG: return 'DEBUG'; | ||
| default: return 'NOTSET'; | ||
| } | ||
| } | ||
|
|
||
| export default class ReactNativeLogger { | ||
| log(level, message) { | ||
| const formattedMessage = `[OPTIMIZELY] - ${getLogLevelName(level)} ${new Date().toISOString()} ${message}`; | ||
| switch (level) { | ||
| case LogLevel.INFO: console.info(formattedMessage); break; | ||
| case LogLevel.ERROR: | ||
| case LogLevel.WARNING: console.warn(formattedMessage); break; | ||
| case LogLevel.DEBUG: | ||
| case LogLevel.NOTSET: console.log(formattedMessage); break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = ReactNativeLogger; | ||
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.
Let's not make this entry point depend on another entry point. It should be independent.
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 means a lot of repeated code in both the entry points. is that ok?
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.
Yes that's OK. It's not that much repeated code, and we don't want the promise polyfill, the pending events dispatcher, or listening for the pagehide event.