Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
1. Reverted changes from logging package.
2. Added ReactNative logger in optimizely-sdk package.
  • Loading branch information
zashraf1985 committed Oct 6, 2019
commit f3df4a15a6d31725ef7b8493af0cbf69f628c15c
18 changes: 1 addition & 17 deletions packages/logging/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class ConsoleLogHandler implements LogHandler {
* @param {string[]} logArguments
* @memberof ConsoleLogger
*/
protected consoleLog(logLevel: LogLevel, logArguments: [string, ...string[]]) {
private consoleLog(logLevel: LogLevel, logArguments: [string, ...string[]]) {
switch (logLevel) {
case LogLevel.DEBUG:
console.log.apply(console, logArguments)
Expand All @@ -193,22 +193,6 @@ export class ConsoleLogHandler implements LogHandler {
}
}

export class ReactNativeConsoleLogHandler extends ConsoleLogHandler {
/**
* @private
* @param {LogLevel} logLevel
* @param {string[]} logArguments
* @memberof ConsoleLogger
*/
protected consoleLog(logLevel: LogLevel, logArguments: [string, ...string[]]) {
if (logLevel === LogLevel.ERROR) {
console.warn.apply(console, logArguments);
} else {
super.consoleLog(logLevel, logArguments);
}
}
}

let globalLogLevel: LogLevel = LogLevel.NOTSET
let globalLogHandler: LogHandler | null = null

Expand Down
4 changes: 2 additions & 2 deletions packages/optimizely-sdk/lib/index.react_native.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var logging = require('@optimizely/js-sdk-logging');
var Logger = require('./plugins/logger/index.react_native');
var browserIndex = require('./index.browser');
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.


/**
Expand All @@ -37,7 +37,7 @@ module.exports = {
*/
createInstance: function(config) {
return browserIndex.createInstance({
logger: new logging.ReactNativeConsoleLogHandler(),
logger: new Logger(),
...config,
})
}
Expand Down
26 changes: 26 additions & 0 deletions packages/optimizely-sdk/lib/plugins/logger/index.react_native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var LogLevel = require('@optimizely/js-sdk-logging').LogLevel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the license header comment here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this to 2019 only


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;