npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

multi-loggerjs

v1.0.0

Published

A simple configurable multi level logger.

Downloads

16

Readme

multi-logger

A simple configurable multi level logger.

Version npm npm Downloads Dependencies Build Status coverage Maintainability MIT License

NPM

Install

npm i multi-loggerjs

Usage

Default Usage

const logger = require("multi-loggerjs");

let multiLogger = new logger.MultiLogger();

multiLogger.info("Info !");
multiLogger.success("Success !");
multiLogger.warning("Warning !");
multiLogger.error("Error !");
multiLogger.fatal("Fatal Error !");

Configuration

const logger = require("multi-loggerjs");

const options = {
  dateFormat: "MMMM Do YYYY",
  timeFormat: "h:mm:ss",
  showFullPath: true,
  showDate: true,
  showTime: true,
  showExternalCallerInfo: true
};

let multiLogger = new logger.MultiLogger(options);
multiLogger.info("Configurable logger!");

multi-logger is using String Format for date and time formats.

Custom Loggers & Modifications

const logger = require("multi-loggerjs");
const foregrounds = logger.foregrounds;
const backgrounds = logger.backgrounds;
const levels = logger.levels;

const options = {
  loggers: {
    info: {
      badge: "ℹ",
      foreground: foregrounds.Magenta,
      background: backgrounds.Default,
      isUnderlined: false,
      text: {
        foreground: foregrounds.LightCyan,
        background: backgrounds.Default,
        isUnderlined: true
      },
      label: "Info",
      level: levels.Trace
    },
    status: {
      level: levels.Trace,
      badge: "☺",
      label: "Status",
      foreground: foregrounds.LightGreen,
      background: backgrounds.Default,
      isUnderlined: true,
      text: {
        foreground: foregrounds.White,
        background: backgrounds.LightRed,
        isUnderlined: true
      }
    }
  }
};

let multiLogger = new logger.MultiLogger(options);
multiLogger.info("Modified logger!");
multiLogger.status("New logger!");

Available Foregrounds and Backgrounds

Available foregrounds and backgrounds are as follows; Default, Black, Red, Green, Yellow, Blue, Magenta, Cyan, LightGray, DarkGray, LightRed, LightGreen, LightYellow, LightBlue, LightMagenta, LightCyan, White.

| Foregrounds | Backgrounds | | ------------- |:-------------:| | | |

Log Levels

Available log levels are as follows;

  • Trace: 0
  • Debug: 1
  • Information: 2
  • Warning: 3
  • Error: 4
  • Fatal: 5

Logging Rules

Each logger can write to different sources according to the environment defined configuration. By default the loggers use console for production and development with log level Trace. Each environment can use multiple sources for logging.

const logger = require("multi-loggerjs");

const options = {
  rules: {
    production: {
      writeTo: {
        file: [
          {
            level: levels.Error,
            folderPath: "C:\\Repositories\\multi-logger\\test\\logs",
            fileName: "error.txt",
            size: 1024
          },
          {
            minLevel: levels.Warning,
            folderPath: "C:\\Repositories\\multi-logger\\test\\logs",
            fileName: "warning.txt",
            size: 1024
          }
        ],
        mongoDb: [{ minLevel: levels.Warning, connectionString: "mongodb://localhost:27017/multi-logger-demo" }]
      }
    },
    development: {
      writeTo: { console: [{ minLevel: levels.Trace }] }
    }
  }
};

const multiLogger = new logger.MultiLogger(options);
multiLogger.info("Writes to file and mongo db for production & console for development according to loggers log level!");

Logging Rules Attributes

  • level - Single log level for the matching rule.
  • minLevel - Minimal log level for the matching rule.
  • folderPath - Folder path for the matching rule (Applies only if the rule is "file").
  • fileName - File name for the matching rule (Applies only if the rule is "file").
  • size - Maximum file size in bayts for the matching rule. Creates a new file if the maximum size is reached (Applies only if the rule is "file").
  • connectionString - The connection string needed for the matching rule (Applies only if the rule is "mongoDb").

If level and minLevel is defined for the same rule minLevel will be taking to account.