react-native-firebase/lib/utils/log.js

42 lines
1.0 KiB
JavaScript
Raw Normal View History

/*
* @flow
*/
2017-03-02 13:10:10 +00:00
import { windowOrGlobal } from './';
import type ModuleBase from './ModuleBase';
2017-03-02 13:10:10 +00:00
((base) => {
window = base || window;
// $FlowFixMe: Why are we using localStorage at all?
2017-03-02 13:10:10 +00:00
if (!window.localStorage) window.localStorage = {};
})(windowOrGlobal);
// clean up time
2017-03-02 13:10:10 +00:00
const NATIVE_LOGGERS: { [string]: Object } = {};
const getModuleKey = (module: ModuleBase): string => `${module.app.name}:${module.namespace}`;
export const getLogger = (module: ModuleBase) => {
const key = getModuleKey(module);
return NATIVE_LOGGERS[key];
};
export const initialiseLogger = (module: ModuleBase, logNamespace: string) => {
const key = getModuleKey(module);
if (!NATIVE_LOGGERS[key]) {
NATIVE_LOGGERS[key] = require('bows')(`🔥 ${logNamespace.toUpperCase()}`);
}
};
export default class Log {
static createLogger(namespace) {
return require('bows')(namespace);
2017-03-02 13:10:10 +00:00
}
static setLevel(booleanOrDebugString) {
window.localStorage.debug = booleanOrDebugString;
window.localStorage.debugColors = !!booleanOrDebugString;
2017-03-02 13:10:10 +00:00
}
}