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

logger3

v1.0.0

Published

A simple but in-depth logger. Customize by composition.

Downloads

9

Readme

logger3

a simple but in depth logger for node.js, Customize by Composition.

The idea for this tool is composing logging functions, so you can make the logs look exactly how you want or need them to.

Usage

You just import the module, and call log.

const log = require('logger3');

log('Hello World');

That's not interesting, lets compose a simple prefix in front of the message.

const log = require('logger3');

const prefixed = log.prefix('[DEBUG]');

prefixed('Hello World, Debug Edition');
// -> [DEBUG] Hello World, Debug Edition

Prefixes can also be functions that get executed every time a log happens, this can be used for timestamps.

const log = require('logger3');

const timestamped = log.prefix(() => `[${Date.now()}]`);

timestamped('Hello World, Timestamped');
// -> [1558056117302] Hello World, Debug Edition
//
// Will vary depending when you run it.

You can also chain the logging modifiers

const log = require('logger3');

const chained = log.prefix(() => `[${Date.now()}]`).suffix('[SUFFIX]');

chained('Hello World');
// -> [1558056117302] Hello World, Debug Edition [SUFFIX]
//
// Will vary depending when you run it.

There are also a bunch of built in formatters, and colors. Colors are based on the chalk module, so you can use their api of chaining properties.

const log = require('logger3');
const { format, color } = log;

const red = log.make(color.red);
const brackets = log.make(format.paren);
const time = log.prefix(format.bracket(format.time));

red('Hello World');
brackets('Hello World');
time('Hello World');

// Hello World        (in red)
// (Hello World)
// [21:26:35] Hello World

When using in a project, you should create a file where you compose all your log functions, which are used by the rest of the program.

const log = require('logger3');
const { format, color } = log;

const bracketTime = format.bracket(format.time);

module.exports.info = log.make(color.blue).prefix('[INFO] ').prefix(bracketTime);
module.exports.warn = log.make(color.yellow).prefix('[WARN] ').prefix(bracketTime);
module.exports.error = log.make(color.red).prefix('[ERROR]').prefix(bracketTime);
module.exports.debug = log.make(color.magenta).prefix('[DEBUG]').prefix(bracketTime);

API

Logger

Get a blank logger with const log = require('logger3');

  • log() Logs to the console
  • log.prefix(prefix) Applies a prefix, returns a logger
  • log.suffix(suffix) Applies a suffix, returns a logger
  • log.make(maker) Applies a transformer function, returns a logger

Formatters (log.format)

Get the formatters object with const format = require('logger3').format;;

  • format.bracket(item) Formats text with [brackets]
  • format.paren(item) Formats text with (parenthesis)
  • format.brace(item) Formats text with {braces}
  • format.createFormatter((item) => ${item}) Creates a formatter, used by the other formatters to ensure a string is passed
  • format.timestamp() returns the timestamp (see Date.now);
  • format.time() returns the time formatted to HH:MM:SS;

Colors

Get the colors object with const color = require('logger3').color;. You can chain the properties to apply a color, background, and other text decoration, provided your terminal supports it.

Available Properties

  • reset
  • bold
  • dim
  • italic
  • underline
  • inverse
  • hidden
  • strikethrough
  • visible
  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • gray
  • redBright
  • greenBright
  • yellowBright
  • blueBright
  • magentaBright
  • cyanBright
  • whiteBright
  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite
  • bgBlackBright
  • bgRedBright
  • bgGreenBright
  • bgYellowBright
  • bgBlueBright
  • bgMagentaBright
  • bgCyanBright
  • bgWhiteBright