JSPM

pretty-logger

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 28
  • Score
    100M100P100Q60698F

A colorized extenstion of 'basic-logger' supporting error, warning, debug and info messages with timestamp.

Package Exports

  • pretty-logger

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pretty-logger) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Pretty-Logger

Pretty Logger for nodejs allows for color coded error, warning, info, debug and trace console messages with (or without) timestamp. This is a modified version of the basic-logger project to use colors.

Screenshot of pretty logger in action

Installation

npm install pretty-logger --save

Accepted Colors

black, red, green, yellow, blue, magenta, cyan, white, gray, grey, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, dim, rainbow, zebra, america, random, reset

Usage

    var Logger = require('pretty-logger');
    // configure level one time, it will be set to every instance of the logger
    Logger.setLevel('warning'); // only warnings and errors will be shown
    Logger.setLevel('warning', true); // only warnings and errors will be shown and no message about the level change will be printed

    var customConfig = {
        showMillis: true,
        showTimestamp: true,
        info: "gray",
        error: ["bgRed", "bold"],
        debug: "rainbow"
    };

    var log = new Logger(customConfig) // custom config parameters will be used, defaults will be used for the other parameters
    //var log = new Logger(); // you can also do this to accept the defaults

    log.error("An error occurred"); // will be red
    log.warn("I've got a bad feeling about this!"); // will be yellow
    log.info("Something just happened, thought you should know!"); // will be green
    log.debug("The value of x is: " + x); // will be blue
    log.trace("Heres some more stuff to help out."); // will be gray

Config options

For the error, info, warn, debug, and trace properties you can find the accepted colors on the colors repo.

  • showTimestamp - Show the timestamp with every message.
  • showMillis - Show milliseconds in the timestamp.
  • printObjFunc - The function to apply objects to, if logged. Default is util.inspect.
  • prefix - String that is prepended to every message logged with this instance.
  • error- String or array that represents the color of the error text. Default is "red".
  • info- String or array that represents the color of the info text. Default is "green".
  • warn- String or array that represents the color of the warning text. Default is "yellow".
  • debug- String or array that represents the color of the debug text. Default is "cyan".
  • trace- String or array that represents the color of the trace text. Default is "grey".

Future versions

  • log to file

v0.1.2

  • Add ability to have multiple color/styles -Credit to wvbe
  • Fix issue #3 reported by jackwilsdon