1.0.0 • Published 2 years ago

@noahvarghese/logger v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Typescript npm Continuous Deployment Continuous Integration Statements Lines Functions Branches License: MIT

Logger

Javascript/Typescript logger. Basic right now, just used to share implementation across projects. At some point may be able to store logs instead of just outputting to std{err,out}.

Installation

npm i @noahvarghese/logger

Usage

import Logger from "@noahvarghese/logger";

// Typically set in a .env file, on deployment, or within CI
process.env["LOG_LEVEL"] = 7;

/**
 * Setting the environment variable LOG_LEVEL dictates which logging calls will be output
 * The numbers are the environment variable options
 * -1 to disable all
 *
 * enum LogLevel {
 * ERROR=0,
 * TEST=1,
 * WARN=2,
 * DEBUG=3,
 * LOG=4,
 * CMD=5,
 * SQL=6
 * }
 *
 */

// Can override environment and turn off all logs by passing true to the init function
const disableLogs = false;

// Required to load environment variable into class
Logs.init(disableLogs);

// Sample calls and output
Logs.Error("error"); // [ ERROR ]: error [path to function where error ocurred]

Logs.Test("test"); // [ TEST ]: test [path to function where error ocurred]

Logs.Warn("warn"); // [ WARN ]: warn [path to function where error ocurred]

Logs.Debug("debug"); // [ DEBUG ]: debug [path to function where error ocurred]

Logs.Log("log"); // [ LOG ]: log

Logs.Cmd("cmd"); // [ CMD ]: cmd

Logs.Sql("sql"); // [ SQL ]: sql

Development - Getting Started

git clone https://github.com/noahvarghese/logger
cd ./logger
npm i
# Configures pre commit hook and shell preferences
npm run init