[internals] remove bows logger + window shims - fixes #858

This commit is contained in:
Salakar 2018-03-05 01:58:42 +00:00
parent fdf3e0fb56
commit 820bb0b0d4
4 changed files with 32 additions and 32 deletions

View File

@ -170,12 +170,6 @@ export function tryJSONStringify(data: mixed): string | null {
}
}
export const windowOrGlobal =
// eslint-disable-next-line no-restricted-globals
(typeof self === 'object' && self.self === self && self) ||
(typeof global === 'object' && global.global === global && global) ||
this;
/**
* No operation func
*/

View File

@ -1,18 +1,10 @@
/*
* @flow
*/
import { windowOrGlobal } from './';
import INTERNALS from './internals';
import type ModuleBase from './ModuleBase';
(base => {
window = base || window;
// $FlowFixMe: Why are we using localStorage at all?
if (!window.localStorage) window.localStorage = {};
})(windowOrGlobal);
// clean up time
const NATIVE_LOGGERS: { [string]: Object } = {};
const getModuleKey = (module: ModuleBase): string =>
@ -23,22 +15,33 @@ export const getLogger = (module: ModuleBase) => {
return NATIVE_LOGGERS[key];
};
export const LEVELS = {
debug: 0,
info: 1,
warn: 2,
error: 3,
};
export const initialiseLogger = (module: ModuleBase, logNamespace: string) => {
const key = getModuleKey(module);
if (!NATIVE_LOGGERS[key]) {
// eslint-disable-next-line global-require
NATIVE_LOGGERS[key] = require('bows')(`🔥 ${logNamespace.toUpperCase()}`);
const prefix = `🔥 ${logNamespace.toUpperCase()}`;
NATIVE_LOGGERS[key] = {
debug(...args) {
if (__DEV__ && LEVELS.debug >= LEVELS[INTERNALS.OPTIONS.logLevel])
console.log(...[prefix, ...args]);
},
info(...args) {
if (__DEV__ && LEVELS.info >= LEVELS[INTERNALS.OPTIONS.logLevel])
console.log(...[prefix, ...args]);
},
warn(...args) {
if (__DEV__ && LEVELS.warn >= LEVELS[INTERNALS.OPTIONS.logLevel])
console.warn(...args);
},
error(...args) {
console.error(...args);
},
};
}
};
export default class Log {
static createLogger(namespace: string) {
// eslint-disable-next-line global-require
return require('bows')(namespace);
}
static setLevel(booleanOrDebugString: boolean | string) {
window.localStorage.debug = booleanOrDebugString;
window.localStorage.debugColors = !!booleanOrDebugString;
}
}

View File

@ -72,7 +72,6 @@
"wml": "0.0.82"
},
"dependencies": {
"bows": "^1.6.0",
"opencollective": "^1.0.3",
"postinstall-build": "^5.0.1",
"prop-types": "^15.6.1"

View File

@ -4,8 +4,12 @@ import firebase from 'firebase';
import RNfirebase from './../firebase';
import DatabaseContents from './tests/support/DatabaseContents';
RNfirebase.database.enableLogging(true);
RNfirebase.firestore.enableLogging(true);
// RNfirebase.database.enableLogging(true);
// RNfirebase.firestore.enableLogging(true);
// RNfirebase.utils().logLevel = 'debug';
// RNfirebase.utils().logLevel = 'info';
RNfirebase.utils().logLevel = 'warn'; // default
const config = {
apiKey: 'AIzaSyDnVqNhxU0Biit9nCo4RorAh5ulQQwko3E',