Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 1.33 KB

README.md

File metadata and controls

50 lines (36 loc) · 1.33 KB

minimal-logger

CircleCI npm version

A minimal logger for Node and React Native

Features:

  • Provides a default logger and a way to get named loggers.
  • Works the same way as console.<debug | error | info | log | trace | warn>.
  • Supports turning individual logger on or off.
  • No messing up with line numbers.
  • No dependencies.

Usage

Install:

yarn add minimal-logger

Default logger:

import logger from 'minimal-logger';

logger.warn('something went wrong.');

Named logger:

import { getLogger } from 'minimal-logger';

getLogger('foo').warn('something went wrong.');

Enable and disable logger:

import { getLogger } from 'minimal-logger';

logger = getLogger('foo');
logger.warn('something went wrong.');
logger.setEnabled(false);
logger.warn('this line will be muted.');

Notes

  • Loggers will be disabled by default if __DEV__ is false or NODE_ENV is not dev or development.
  • Multiple calls to getLogger() with the same name will always return a reference to the same Logger object. Therefore if you disable it in one file, it will disable all references to the same Logger.