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

plop-logger

v3.1.7

Published

Basic logger

Downloads

51

Readme

Plop Logger

Travis (.org) GitHub npm npm bundle size Snyk Vulnerabilities for npm package

Why another logger?

There are already plenty of logging related lib on npm. This is just a basic personal side project, so if you need a production-ready lib, you probably should use another lib.

This lib try to find the right balance between simplicity and features, with a good quality code.

Basic usage

Install with npm i plop-logger or yarn add plop-logger.

import { LogLevel, Logger } from "plop-logger";

// Get a logger with the `plop` name
const logger = Logger.getLogger("plop");

// Set level (default to Info)
logger.level = LogLevel.Debug;

// Basic usage
logger.trace("a trace message"); // omitted because level is Debug (> Trace)
logger.debug("a debug message"); // displayed because level is Debug
logger.info("a debug message"); // displayed because level is Debug (< Info)
logger.warn("a debug message"); // ...
logger.error("a debug message"); // ...

// Avoid computation if not necessary
logger.trace(() => `sum: ${1 + 1}`); // computation omitted
logger.info(() => `mult: ${3 * 14}`); // computation done

// Add an argument
logger.info("message to print", "Plop!"); // 'Plop!' is an argument

Configuration

You can configure the logger with the static Logger.config property.

import { defaultConfig, Logger } from "plop-logger";

// Create a custom config
// using ISO Date
// every logger named 'service' or 'service.*' should log warnings and errors
// but the logger named 'service.plopper' should log everything
const customConfig = {
  ...defaultConfig,
  levels: {
    service: "warn",
    "service.plopper": "trace" // level is case-insensitive
  },
  formatDate(date: Date) {
    return date.toISOString();
  }
};

// Setting the custom config
Logger.config = customConfig;

// Try it
const logger = Logger.getLogger("plop");
logger.info("test"); // Info 2019-08-10T17:23:19.736Z plop - test

Configuration:

  • appender: Console : the appender, by default using the global console,
  • defaultLevel: LogLevel: the default level, by default Info,
  • levels: LoggerLevels: can configure level by name or parent name, empty by default,
  • formatLevel(level: LogLevel): string: display the level, by default LogLevel[level],
  • formatDate(now: Date): string: display the log date, by default Date#toLocaleTimeString(),
  • formatName(name: string): string: display the name, by default the name,
  • formatMessage(message: string): string: format the message, by default the message,
  • formatArg(arg: any | null): string: format the argument, by default use toString() or the empty string,
  • formatDump(obj: any): string[]: format an object for a dump, by default use JSON#stringify.

Color Configuration

You can use a colorful configuration:

import { Logger } from "plop-logger";
import { colorConfig } from "plop-logger/extra/colorConfig";

// Use the colorConfig
Logger.config = colorConfig;
// ...

example Color Configuration

Color + Emoji Configuration

The key feature of this project is the color + emoji configuration :

import { Logger } from "plop-logger";
import { colorEmojiConfig } from "plop-logger/extra/colorEmojiConfig";

// Use the colorEmojiConfig
Logger.config = colorEmojiConfig;
// ...

example Color + Emoji Configuration