all files / firebase/utils/ log.js

73.68% Statements 14/19
50% Branches 7/14
100% Functions 3/3
73.68% Lines 14/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                1494×   1464× 1464×                 30× 30× 30× 30×   1387×       77×                          
/*
 * @flow
 */
 
import INTERNALS from './internals';
import type ModuleBase from './ModuleBase';
 
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 LEVELS = {
  debug: 0,
  info: 1,
  warn: 2,
  error: 3,
};
 
export const initialiseLogger = (module: ModuleBase, logNamespace: string) => {
  const key = getModuleKey(module);
  Eif (!NATIVE_LOGGERS[key]) {
    const prefix = `🔥 ${logNamespace.toUpperCase()}`;
    NATIVE_LOGGERS[key] = {
      debug(...args) {
        Iif (__DEV__ && LEVELS.debug >= LEVELS[INTERNALS.OPTIONS.logLevel])
          console.log(...[prefix, ...args]);
      },
      info(...args) {
        Iif (__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);
      },
    };
  }
};