Create Stylized Console Logs – Logger.js

Category: Javascript | October 17, 2020
Author:ArthurBeaulieu
Views Total:33 views
Official Page:Go to website
Last Update:October 17, 2020
License:MIT

Preview:

Create Stylized Console Logs – Logger.js

Description:

Logger.js is a JavaScript library that helps output stylized console logs in browser dev tools to improve readability.

Supports both Firefox and Chromium-based browsers (Chrome, MS Edge, etc).

How to use it:

1. Import the Logger as an ES module.

import Logger from ‘./src/Logger.js’;

2. Console logs can be raised from JavaScript errors (new Error()), or using a custom error format, with a theme (info, error, warning, success), title, and message.

let MyLogger = new Logger({
    errors: {
      "SAMPLE_ERROR_1": {
        "title": "Error 1 title",
        "message": "Some justification. See log for details.",
        "severity": "error"
      },
      "SAMPLE_ERROR_2": {
        "title": "Error 2 title",
        "message": "Some justification. See log for details.",
        "severity": "warning"
      },
      "SAMPLE_ERROR_3": {
        "title": "Error 3 title",
        "message": "Some justification. See log for details.",
        "severity": "info"
      },
      "SAMPLE_ERROR_4": {
        "title": "Error 4 title",
        "message": "Some justification. See log for details.",
        "severity": "success"
      }
    }
});
MyLogger.raise('SAMPLE_ERROR_1');
MyLogger.raise('SAMPLE_ERROR_2');
MyLogger.raise('SAMPLE_ERROR_3');
MyLogger.raise('SAMPLE_ERROR_4');
MyLogger.raise(new Error('TypeError'));

You Might Be Interested In:


Leave a Reply