Giter VIP home page Giter VIP logo

simple-logger's Introduction

Overview

Simple "logger" class to be used in any project. Lightweight, straightforward! No configuration of IDs or installing other libraries to simplify this - it simply logs to the console, and is color coded!

Install

First, navigate to your project directory.

To install, type:
npm i honath-simple-logger

Usage

Import

const Logger = require("honath-simple-logger");

Instantiation

const logger = new Logger("info");

Invocation

logger.info({
    action: "Test Logger",
    location: `<functionName> in ${__dirname}`,
    status: 200,
    notes: [
    "Add additional string messages here!",
    "This is a second note."
    ]
});

The above will console out as:

 Test Logger at <functionName> in <directory path where this method was invoked>
Status Code: 200
Add additional string messages here!
This is a second note.

Methods

  • logger.trace()
  • logger.debug()
  • logger.info()
  • logger.warn()
  • logger.error()
  • logger.fatal()

Additional Information

Valid Log Levels and their Colors

  • Trace - Cyan Text
  • Debug - Blue Text
  • Info - Green Text
  • Warn - Yellow Text
  • Error - Red Text
  • Fatal - Red Background
  • Off - Technically Black Text, but will not log anything anyway

Tips and Warnings

  • You do not need to name it "logger", that is just what I chose to use.
  • Invalid Log Levels will send an error message to the console as Magenta text
  • Log level must be a string. It will not throw an error immediately, but will treat anything other than a string as an invalid log level
  • Logger methods destructure the object sent to them, as shown in the example above
  • The action and location parameters are required
  • The status and notes parameters are optional
  • status is intended to be used to reflect HTTP requests and responses, though you could technically use it for anything. There is no hard restriction on data type or length
  • Additional parameters will be ignored

Support

If you'd like to support the development of this and other projects, please feel free to support me on Patreon!

simple-logger's People

Contributors

honath avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.