Unified JavaScript logging system. KISS, light and library free.

Overview

Logger.js

License

Logger.js is a JavaScript ES6 module that offers a unified console output across Firefox and Chromium based browsers. It handles standard errors raised for example, with new Error(), and is also able to handle custom errors to fit you application needs.

With ~3Ko minified, Logger.js is designed to be stable and remain as light as possible. It is meant to be used application wide to abstract this output layer into basic calls.

Get Started

This repository was made to store documentation, test bench and source code. If you want to include this component in your project, you either need the src/Logger.js file if you have an assets bundler in your project, or use the dist/Logger.min.js to use the minified component. This minified file is compiled in ES5 JavaScript for compatibility reasons. The unminified file is, in the contrary, coded in ES6 JavaScript.

Logger.js can be used to only handle console output, handling either JavaScript error and custom errors. Simply use component as follows :

/* Import the Js component */
import Logger from 'src/Logger.js';
/* Create an event handler with no arguments for JavaScript errors only */
const appLogger = new Logger();
/* ...Or, if you want have custom errors for your app */
const appLogger = new Logger({
  errors: {
    "MY_ERROR": {
      "severity": "error",
      "title": "Title",
      "message": "Message"
    }/* ... */
  }
});

The Logger is now ready to raise errors :

/* Raise standard JavaScript errors */
appLogger.raise(new Error('Unicorn error'));
/* Raise custom error sent in constructor by its key */
appLogger.raise("MY_ERROR");

Advanced usage

This component is also made to work with a notification handler, to have a single point of entry for both console error and UI output. Especially with Notification.js that is able to work out of the box, but any notification handler that offers a new() method with type, title and message arguments will do the trick (see documentation for further details). Here is how to provide such notification handler :

/* Import the Js components */
import Notification from 'my/notification/handler.js';
import Logger from 'src/Logger.js';
/* Just send the notification handler to the constructor */
const appLogger = new Logger({
  notification: Notification
});
/* Notification handler must implement the following method */
Notification.new = options => {
  // string : options.type
  // string : options.title
  // string : options.message
}

You're now good to go! If however you need more information, you can read the online documentation.

Development

If you clone this repository, you can npm install to install development dependencies. This will allow you to build dist file, run the component tests or generate the documentation ;

  • npm run build to generate the minified file ;
  • npm run dev to watch for any change in source code ;
  • npm run web-server to launch a local development server ;
  • npm run doc to generate documentation ;
  • npm run test to perform all tests at once ;
  • npm run testdev to keep browsers open to debug tests ;
  • npm run beforecommit to perform tests, generate doc and bundle the JavaScript.

To avoid CORS when locally loading the example HTML file, run the web server. Please do not use it on a production environment. Unit tests are performed on both Firefox and Chrome ; ensure you have both installed before running tests, otherwise they might fail.

If you have any question or idea, feel free to DM or open an issue (or even a PR, who knows) ! I'll be glad to answer your request.

You might also like...

🌗 1 line of code to apply auto dark / light theme and support custom theme for your website. Super fast and lightweight theme library.

themes.js A super lightweight and fast Theme library with auto system color scheme detection in JavaScript. Features Auto detect Dark / Light mode by

Nov 29, 2022

A simple and light jquery library for toast notification!

What is notify message? Notify message it's a simple jquery library for create a simple and light push notification in your website! How does this wor

Feb 23, 2022

A free and open-source point-of-sale (POS) system for retail and wholesale businesses with support for multiple branches, stockkeeping locations, POS profiles and price lists.

Note: This is a beta version of the software. You are advised to proceed with caution! Overview A free and open-source point-of-sale (POS) system for

Jan 27, 2022

Please do not use this tracker to scam anyone! This is free and will be forever free. This tracking will never ask for seed phrases nor private keys. Keep safe!

CryptoBlades Tracker Related modules express - web application framework for node pug - template engine stylus - pre-processor CSS mongoose - nodejs o

Oct 13, 2022

The LMS (Life Management System) is a free tool for personal knowledge management and goal management based on Obsidian.md.

The LMS (Life Management System) is a free tool for personal knowledge management and goal management based on Obsidian.md.

README Documentation | 中文帮助 The LMS (Life Management System) is a tool for personal knowledge management and goal management based on Obsidian.md. It

Dec 21, 2022

Free computer-aided transcription system for stenographers

Free computer-aided transcription system for stenographers

AlleyCAT is a free, open-source computer-aided transcription (CAT) system for stenographers. It lets you write and edit documents such as court transc

Nov 6, 2022

Denail of service system for the Dentistimo system. Used to improve the tolerance and testing fail safe functionality.

 Denail of service system for the Dentistimo system. Used to improve the tolerance and testing fail safe functionality.

Distributed Systems - Dos Testing DoS (Denail of Service) System for Testing and Practical demonstration of systems capability to handle a basic DDoS

Nov 8, 2022

🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

🐬 HypeScript Introduction This is a simplified implementation of TypeScript's type system that's written in TypeScript's type annotations. This means

Dec 20, 2022
Releases(1.2.0)
Owner
Arthur Beaulieu
Web UI/UX engineer – Paris 🇫🇷
Arthur Beaulieu
Keyboard shortcut handler. KISS, light and library free.

Shortcut.js Shortcut.js is a JavaScript ES6 component that offers a global keyboard event handler. This way one can declare and react to any combinati

Arthur Beaulieu 4 Sep 28, 2022
A small logging proxy server for intercepting and logging code completion requests from copilot.

PilotWatch PilotWatch is a small logging proxy server written in node.js for intercepting and logging code completion requests from Github's Copilot.

John Robinson 7 May 8, 2023
In this project, I implement a Simple To Do List with the CRUD (create, read, update, delete) methods. I followed the JavaScript, CSS, HTML, DRY, KISS and YAGNI Best practices.

To Do list: add & remove In this project, I implement a Simple To Do List with the CRUD (create, read, update, delete) methods. All the elements of th

Olivier 6 Nov 20, 2022
The Frontend of Escobar's Inventory Management System, Employee Management System, Ordering System, and Income & Expense System

Usage Create an App # with npx $ npx create-nextron-app my-app --example with-javascript # with yarn $ yarn create nextron-app my-app --example with-

Viver Bungag 4 Jan 2, 2023
Utilities for parsing and manipulating LaTeX ASTs with the Unified.js framework

unified-latex Monorepo for @unified-latex packages. These packages provide a JS/TypeScript interface for creating, manipulating, and printing LaTeX Ab

Jason Siefken 29 Dec 27, 2022
A unified and lightweight web application framework for multiple platforms.

Handlers.js Handlers.js is a unified and lightweight web application framework for multiple platforms. import handlerJS from "handlers.js"; const App

186526 7 Jul 26, 2022
Incredible drastically simplifies creation of developer video content. It offers a unified workflow to storyboard, record, collaborate and produce the video.

?? Introduction Incredible drastically simplifies creation of developer video content. It offers a unified workflow to storyboard, record, collaborate

Incredible 113 Dec 6, 2022
Blogkit - A unified blogging engine built with Next.js

Blogkit (beta) Blogkit is a unified blog engine inspired by Sairin. Get started with starter templates Template Description blogkit-notion-starter Not

2nthony 7 Jun 9, 2022
Unified-myst is a monorepo containing packages for using MyST

unified-myst (IN-DEVELOPMENT) unified-myst is a monorepo containing packages for using MyST (Markedly Structured Text), within the unified ecosystem.

Executable Books 5 Apr 14, 2022
A JavaScript library to apply light-dark theme in web pages with the help of css variables

Theme Changer The simplest JavaScript library to apply light - dark theme in your website. First Check Out One Example How to use Files index.html sty

Abinash Karmakar 8 Dec 20, 2022