Socket
Book a DemoInstallSign in
Socket

js-console-logger

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

js-console-logger

A configurable, lightweight, opinionated JavaScript logger.

0.1.2
latest
Source
npmnpm
Version published
Weekly downloads
59
118.52%
Maintainers
1
Weekly downloads
 
Created
Source

js-console-logger

A configurable, lightweight, opinionated JavaScript logger.

Defined log levels are trace, debug, info, warn and error.

Installation

    npm i js-console-logger --save

Usage

    import 'js-console-logger';

Examples

Usage is very similar to console object.

NOTE: consoleLevel is set to trace.

    logger.trace('Network', 'API is not reposding', { url: 'www.google.com', ua: 'bot' });
    logger.debug('Network', 'API is not reposding', { url: 'www.google.com', ua: 'bot' });
    logger.info('Network', 'API is not reposding', { url: 'www.google.com', ua: 'bot' });
    logger.warn('Network', 'API is not reposding', { url: 'www.google.com', ua: 'bot' });
    logger.error('Network', 'API is not reposding', { url: 'www.google.com', ua: 'bot' });

demo screenshot

Configure example

Default configuration is good enough to start. But you can configure few options

    import { consoleConfig } from 'js-console-logger';
    // import { LogLevel } from 'js-console-logger/lib/types';

    const isProd = process.env.NODE_ENV === 'production';

    consoleConfig.setDisableConsole(isProd); // default false

    consoleConfig.setConsoleLevel('info');
    // default info, Use types in TS.

    consoleConfig.setDisableReport(!isProd); //

    consoleConfig.setReportFn((obj) => {
        // report it to somewhere, call api etc.
    });

    consoleConfig.setReportLevel('error');
    // default error, Use types in TS.

To dispatch an action on report.

    import { consoleConfig } from 'js-console-logger';
    import store from '../utils/store';
    import { reportLog } from '../containers/App/actions';

    const reportFn = (obj) => {
        store.dispatch(reportLog(obj));
    };

    consoleConfig.setReportFn(reportFn);

Keywords

js

FAQs

Package last updated on 09 Dec 2018

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.