Skip to content

rappy-log 2.0.0

Install from the command line:
Learn more about npm packages
$ npm install @gabrieljoelc/rappy-log@2.0.0
Install via package.json:
"@gabrieljoelc/rappy-log": "2.0.0"

About this version

Rappy Log

Wraps console log methods so you can set the current log level to only log what you want in the current environment. This is useful for debugging in something like React Native.

Getting started

Add it to your app:

npm install rappy-log

Usage:

import { getCurrentLogLevel, setLogLevel } from 'rappy-log';

const levels = [
  'none',
  'error',
  'info',
  'debug',
  'trace',
];

for (let logCount = 0; logCount < levels.length; logCount++) {
  let msg = `should log ${logCount} time${logCount > 1 ? 's' : ''}`;
  setLogLevel(levels[logCount]);
  console.log('current level:', getCurrentLogLevel());
  console.error(msg);
  console.info(msg);
  console.debug(msg);
  console.trace(msg);
}

Outputs:

current level: none
current level: error
ERROR - should log 1 time
current level: info
INFO - should log 2 times
INFO - should log 2 times
current level: debug
DEBUG - should log 3 times
DEBUG - should log 3 times
DEBUG - should log 3 times
current level: trace
TRACE - should log 4 times
TRACE - should log 4 times
TRACE - should log 4 times
TRACE - should log 4 times

Environment variable

You can also set the log level with an environment variable (see (12-factor)[https://12factor.net/config] for more information).

If you had this app:

# app.js
import { setLogLevel } from 'rappy-log';

setLogLevel(); // if no level parameter is passed, tries to get level from environment

// dope freestyling starts to drop
console.error('And money on the wood');
console.debug('We made a promise and it\'s understood');

Now start the app:

LOG_LEVEL=error node app.js
> And money on the wood

Details


Assets

  • rappy-log-2.0.0.tgz

Download activity

  • Total downloads 0
  • Last 30 days 0
  • Last week 0
  • Today 0

Recent versions

View all