diff --git a/lib/utils/index.js b/lib/utils/index.js index d832503c..bbe1031e 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -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 */ diff --git a/lib/utils/log.js b/lib/utils/log.js index 44e36261..c94da3dc 100644 --- a/lib/utils/log.js +++ b/lib/utils/log.js @@ -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; - } -} diff --git a/package.json b/package.json index 1e32cfad..1bddc3d2 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/tests/src/firebase.js b/tests/src/firebase.js index cf36cd50..4810a7cf 100644 --- a/tests/src/firebase.js +++ b/tests/src/firebase.js @@ -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',