Skip to content

Instantly share code, notes, and snippets.

@Eseperio
Last active May 5, 2021 11:27
Show Gist options
  • Save Eseperio/8f6769f195884fb53535b8e9a6412774 to your computer and use it in GitHub Desktop.
Save Eseperio/8f6769f195884fb53535b8e9a6412774 to your computer and use it in GitHub Desktop.
Simple prefixed javascript logger

Simple prefixed javascript logger

This is a very simple way to get your logs prefixed, so you can easily know which messages belong to your scripts.

Installation

Add to your classes using import {Logger} from "./logger"; or remove export and include the class in your main script.

Usage

Call Logger.log() as you previously called console.log. No matter the amount of parameters or their format. warn, error and info methods are already supported.

export class Logger {
static prefix = "[YourAppNameHere] ";
static log(...args) {
console.log(Logger.prefix, ...args);
}
static warn(...args) {
console.warn(Logger.prefix, ...args);
}
static error(...args) {
console.error(Logger.prefix, ...args);
}
static info(...args) {
console.info(Logger.prefix, ...args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment