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

@vladmandic/pilogger

v0.5.1

Published

Simple Logger for NodeJS

Downloads

831

Readme

PiLogger: Simple Logger for NodeJS

Why

Because out of all of the existing modules, I couldn't find one that does what I needed and doesn't carry large number of unnecessary dependencies. There are far more complex loggers available, but sometimes all you need is simplicity with specific feature-set.
This module is written in pure ES6 with minimal dependencies.

Features

  • Extremely lightweight
  • Color coding of different log levels for console output
  • Support for console and file logging
  • Prefix messages with timestamp
  • Maintening configurable ring buffer of past messages
  • Automatic expansion of object parameters
  • Automatic concating of multiple parameters
  • All logging functions are asynchronous for non-blocking operations

Configuration

Configuration is optional.
If not configured, logging will be to console only and with default format
Configuring inspect options controls how object output is handled

const log = require('pilogger');
const options = {
  options.dateFormat: 'YYYY-MM-DD HH:mm:ss',
  ringLength: 100,
  logFile: './application.log',
  accessFile: './accesss.log',
  clientFile: './client.log',
  inspect: {
    showHidden: true,
    depth: 5,
    colors: true,
    showProxy: true,
    maxArrayLength: 1024,
    maxStringLength: 10240,
    breakLength: 200,
    compact: 64,
    sorted: false,
    getters: true,
  }
}
log.configure(options);

Usage

Messages that are printed to console only, useful for debugging

  log.print(...msg);

Messages that are mirrored to console and logFile (if set), each one prefixed and color coded

  log.blank(...msg);
  log.data(...msg);
  log.state(...msg);
  log.info(...msg);
  log.warn(...msg);
  log.error(...msg);

Example output (note that markdown rules strip colored output):

  2020-08-08 10:36:55 INFO:  piscan version 0.0.1
  2020-08-08 10:36:55 INFO:  User: root Platform: linux Arch: x64 Node: v14.4.0
  2020-08-08 10:36:55 STATE: Running as root with full capabilities
  2020-08-08 10:37:08 DATA:  host: pi ip: 192.168.0.100 time: 12,210
  2020-08-08 10:37:10 DATA:  mac: DC:A6:32:1B:74:D5 vendor: Raspberry Pi os: Linux 5.4
  2020-08-08 10:37:12 DATA:  ports: 22,139,445,514,873

Messages that are mirrored to console and logFile (if set), each one prefixed and color coded and with time measurement

  const t0 = process.hrtime.bigint();
  // do your stuff here
  log.timed(t0, ...msg);

Example output:

  2020-08-08 10:39:59 TIMED:  1,004 ms Test function execution

Messages that are output to accessFile (if set) only
Useful for detailed application access log that you don't want printed to console

  log.access(...msg);

Messages that are output to clientFile (if set) only
Useful for logging of any other messages that you don't want printed to console

  log.client(...msg);

Access to history ring buffer.
obj.time is message timestamp, obj.tag is message type (info, state, data, warn, error), obj.msg is parsed & concatened message string

  for (const line in log.ring) {
    console.log(log.ring[line].time, log.ring[line].tag), log.ring[line].msg);
  }