colorjslogger

3.0.1 • Public • Published

colorjslogger

npm version license

Fast and lightweight colorful JS Logger for the browser and Nodejs. It is a perfect logger that supports all browsers.

It allows to print color logs with pre-defined 5 levels of logging (info, warning, error, success, debug). You can enable the VERBOSE flag to print debug logs during the development phase and you can disable it by setting VERBOSE flag to false to avoid printing confidential logs in production.

Features

  • Fast and lightweight
  • Supports multi-color for browser console logs
  • Records all types of logs and allow download it as a file

Requirements

  • None

Installation

NPM

You can install colorjslogger as a dependency using NPM.

$ npm install colorjslogger --save

Yarn

You can install colorjslogger as a dependency using Yarn.

$ yarn add colorjslogger

CDN

json2csv plainjs modules is packaged as an ES6 modules. If your browser supports modules, you can load json2csv plainjs modules directly on the browser from the CDN.

You can import the latest version:

<script type="module">
  import jslogger from 'https://cdn.jsdelivr.net/npm/colorjslogger@latest/src/jslogger.min.js';

  jslogger.info('JSLOGGER', 'Imported ES6Module directly in the browser');
</script>

You can also select a specific version:

<script type="module">
  import jslogger from 'https://cdn.jsdelivr.net/npm/colorjslogger@3.0.1/src/jslogger.min.js';

  jslogger.info('JSLOGGER', 'Imported ES6Module directly in the browser');
</script>

Usage

try {
    jslogger.info(process, message);
    jslogger.warning(process, message);
    jslogger.error(process, message);
    jslogger.success(process, message);
    jslogger.internal(process, message);
    jslogger.debug(process, message);
} catch (err) {
  console.error(err);
}

Parameters

  • process (string): Name of the process or a function in which it is used.
  • message (string): Actual log message that needs to log in the console.
Note

Debug logs will only work if the VERBOSE property is set to true. Here is an example how to do it:

jslogger.setLevelToVerbose(true);

Example

jslogger.info('Authentication', 'Connection in progress');

Log Output Format

UTC Date | AppName | [Process] :: Message

Output

Mon Aug 12 2019 22:37:57 | JSLogger | [Authentication] :: Connection in progress

Change the Default AppName

jslogger.setAppName('SuhaibJanjuaLogger');
jslogger.info('Authentication', 'Connection in progress');

Mon Aug 12 2019 22:37:57 | SuhaibJanjuaLogger | [Authentication] :: Connection in progress

Log information as internal to avoid printing it into the browser console

jslogger.internal('Authentication', 'User with email su****************.com just logged in.');

Download

You can download the recorded logs by the following method:

jslogger.downloadLogs()

License

See LICENSE.md.

Package Sidebar

Install

npm i colorjslogger

Weekly Downloads

20

Version

3.0.1

License

MIT

Unpacked Size

11.7 kB

Total Files

6

Last publish

Collaborators

  • suhaib.janjua