2017-12-22 15:24:31 +00:00
|
|
|
/*
|
|
|
|
* @flow
|
|
|
|
*/
|
2017-03-02 13:10:10 +00:00
|
|
|
|
2018-03-05 01:58:42 +00:00
|
|
|
import INTERNALS from './internals';
|
2017-12-22 15:24:31 +00:00
|
|
|
import type ModuleBase from './ModuleBase';
|
|
|
|
|
2018-01-05 18:23:38 +00:00
|
|
|
const NATIVE_LOGGERS: { [string]: Object } = {};
|
2017-12-22 15:24:31 +00:00
|
|
|
|
2018-01-25 18:25:39 +00:00
|
|
|
const getModuleKey = (module: ModuleBase): string =>
|
|
|
|
`${module.app.name}:${module.namespace}`;
|
2018-01-05 18:23:38 +00:00
|
|
|
|
|
|
|
export const getLogger = (module: ModuleBase) => {
|
|
|
|
const key = getModuleKey(module);
|
|
|
|
return NATIVE_LOGGERS[key];
|
|
|
|
};
|
2018-01-03 20:00:38 +00:00
|
|
|
|
2018-03-05 01:58:42 +00:00
|
|
|
export const LEVELS = {
|
|
|
|
debug: 0,
|
|
|
|
info: 1,
|
|
|
|
warn: 2,
|
|
|
|
error: 3,
|
|
|
|
};
|
|
|
|
|
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]) {
|
2018-03-05 01:58:42 +00:00
|
|
|
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);
|
|
|
|
},
|
|
|
|
};
|
2017-12-22 15:24:31 +00:00
|
|
|
}
|
|
|
|
};
|