2017-12-22 15:24:31 +00:00
|
|
|
/*
|
|
|
|
* @flow
|
|
|
|
*/
|
2017-03-02 13:10:10 +00:00
|
|
|
import { windowOrGlobal } from './';
|
|
|
|
|
2017-12-22 15:24:31 +00:00
|
|
|
import type ModuleBase from './ModuleBase';
|
|
|
|
|
2017-03-02 13:10:10 +00:00
|
|
|
((base) => {
|
|
|
|
window = base || window;
|
2018-01-05 17:20:02 +00:00
|
|
|
// $FlowFixMe: Why are we using localStorage at all?
|
2017-03-02 13:10:10 +00:00
|
|
|
if (!window.localStorage) window.localStorage = {};
|
|
|
|
})(windowOrGlobal);
|
|
|
|
|
2017-06-29 16:24:34 +00:00
|
|
|
// clean up time
|
2017-03-02 13:10:10 +00:00
|
|
|
|
2018-01-05 18:23:38 +00:00
|
|
|
const NATIVE_LOGGERS: { [string]: Object } = {};
|
2017-12-22 15:24:31 +00:00
|
|
|
|
2018-01-05 18:23:38 +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];
|
|
|
|
};
|
2018-01-03 20:00:38 +00:00
|
|
|
|
|
|
|
export const initialiseLogger = (module: ModuleBase, logNamespace: string) => {
|
2018-01-05 18:23:38 +00:00
|
|
|
const key = getModuleKey(module);
|
|
|
|
if (!NATIVE_LOGGERS[key]) {
|
|
|
|
NATIVE_LOGGERS[key] = require('bows')(`🔥 ${logNamespace.toUpperCase()}`);
|
2017-12-22 15:24:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-29 16:24:34 +00:00
|
|
|
export default class Log {
|
|
|
|
static createLogger(namespace) {
|
|
|
|
return require('bows')(namespace);
|
2017-03-02 13:10:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-29 16:24:34 +00:00
|
|
|
static setLevel(booleanOrDebugString) {
|
|
|
|
window.localStorage.debug = booleanOrDebugString;
|
|
|
|
window.localStorage.debugColors = !!booleanOrDebugString;
|
2017-03-02 13:10:10 +00:00
|
|
|
}
|
|
|
|
}
|