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

45 lines
1.2 KiB
JavaScript
Raw Normal View History

/*
* @flow
*/
2017-03-02 13:10:10 +00:00
import { windowOrGlobal } from './';
import type ModuleBase from './ModuleBase';
2018-01-25 18:25:39 +00:00
(base => {
2017-03-02 13:10:10 +00:00
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 } = {};
2018-01-25 18:25:39 +00:00
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]) {
2018-01-25 18:25:39 +00:00
// eslint-disable-next-line global-require
NATIVE_LOGGERS[key] = require('bows')(`🔥 ${logNamespace.toUpperCase()}`);
}
};
export default class Log {
static createLogger(namespace: string) {
2018-01-25 18:25:39 +00:00
// eslint-disable-next-line global-require
return require('bows')(namespace);
2017-03-02 13:10:10 +00:00
}
static setLevel(booleanOrDebugString: boolean | string) {
window.localStorage.debug = booleanOrDebugString;
window.localStorage.debugColors = !!booleanOrDebugString;
2017-03-02 13:10:10 +00:00
}
}