Socket
Book a DemoInstallSign in
Socket

rappy-log

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rappy-log

Wraps console log methods so you can set the current log level to only log what you want in the current environment.

1.0.2
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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:

yarn add rappy-log

Usage:

const log = require('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' : ''}`;
  log.setLevel(levels[logCount]);
  console.log('current level:', log.getCurrentLevel());
  log.error(msg);
  log.info(msg);
  log.debug(msg);
  log.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
const log = require('rappy-log');

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

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

Now start the app:

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

Keywords

log

FAQs

Package last updated on 17 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.