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

@parthar/json-stream-logger

v1.0.0

Published

Simple/Efficient JSON Logger that writes to streams

Downloads

4

Readme

JSON Stream Logger

Simple/Efficient JSON Logger that writes to streams

Installation

$ npm install @parthar/json-stream-logger --save

Usage

// create instance
var JsonStreamLogger = require("@parthar/json-stream-logger");
var logger = new JsonStreamLogger({
    meta: function () { return Object; }, // meta-data included in every log; defaults: host, pid, time
    level: "debug", // one of the SYSLOG levels; default: "info"
    streams: [] // array of writable streams; default: new-line terminated JSON.stringify'ed output to stdout
});

// logger settings
logger.setlevel("info"); // set log-level; every log less-than-or-equal to set level will be logged
logger.setStreams([...]); // set the log streams

// logging methods
logger.emergency(...); // log emergency message
logger.alert(...); // log alert message
logger.critical(...); // log critical message
logger.error(...); // log error message
logger.warning(...); // log warning message
logger.notice(...); // log notice message
logger.info(...); // log info message
logger.debug(...); // log debug message

Log Levels

Based on Syslog levels as defined in RFC5424

  • 0 : EMERGENCY - system is unusable
  • 1 : ALERT - action must be taken immediately
  • 2 : CRITICAL - system is in critical condition
  • 3 : ERROR - error condition
  • 4 : WARNING - warning condition
  • 5 : NOTICE - normal but significant condition
  • 6 : INFO - purely informational message
  • 7 : DEBUG - messages to debug an application

Log Message Format

Uses utils.format to format arguments, except the last argument which is interpreted as a JSON-object if/when present.

logger.emergency("hello world");
//{"host":"myhost","pid":999,"time":"2018-05-17T14:47:03.456Z","level":"emergency","msg":"hello world"}
logger.alert({"ying": "yang"});
//{"host":"myhost","pid":999,"time":"2018-05-17T14:47:03.457Z","level":"alert","ying":"yang"}
logger.critical("hello %s", "world");
//{"host":"myhost","pid":999,"time":"2018-05-17T14:47:03.458Z","level":"critical","msg":"hello world"}
logger.error("hello %s", "world", "and", "more", {"ying": "yang"});
//{"host":"myhost","pid":999,"time":"2018-05-17T14:47:03.458Z","level":"error","msg":"hello world and more","ying":"yang"}
logger.warning("hello %s %j", "world", {"ping": "pong"});
//{"host":"myhost","pid":999,"time":"2018-05-17T14:47:03.459Z","level":"warning","msg":"hello world {\"ping\":\"pong\"}"}
logger.notice("hello %s %j", "world", {"ping": "pong"}, {"ying": "yang"});
//{"host":"myhost","pid":999,"time":"2018-05-17T14:47:03.459Z","level":"notice","msg":"hello world {\"ping\":\"pong\"}","ying":"yang"}
logger.info("hello %s %% escaped", "world", {"ying": "yang"});
//{"host":"myhost","pid":999,"time":"2018-05-17T14:47:03.459Z","level":"info","msg":"hello world % escaped","ying":"yang"}
logger.debug("hello %s %% escaped %j", "world", {"ping": "pong"}, {"ying": "yang"});
//{"host":"myhost","pid":999,"time":"2018-05-17T14:49:25.823Z","level":"debug","msg":"hello world % escaped {\"ping\":\"pong\"}","ying":"yang"}

Plugins

To build a plugin, simply extend stream.Writable class and implement the write-interface. These plugins can be set as logger-streams.