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

ziplog

v3.0.0

Published

Distributed logging library

Downloads

8

Readme

Ziplog

Ziplog is a simple, flexible logger, built to handle console logging in a multithreaded environment.

Simple usage

const logger = require('ziplog');

logger.info('Test log message', { logType: 'module-1' }, { lineNum: 277 });

logger.error(new Error('Test error'));

The output of these log commands:

{
    "app": "ziplog",
    "log": "module-1",
    "lvl": "INFO",
    "@timestamp": "2018-10-11T15:07:42.076Z",
    "message": "Test log message",
    "data": {
        "lineNum": 277
    }
}
{
    "app": "ziplog",
    "log": "general",
    "lvl": "ERROR",
    "@timestamp": "2018-10-11T15:07:42.077Z",
    "error": {
        "message": "Test error"
    },
    "message": "Test error"
}

By default, the log levels in decreasing order of severity are [ 'error', 'warn', 'info', 'debug', 'trace' ]. Each of these levels becomes a function on the logger, accepting a variatic number of arguments that may include a mix of log messages, errors, and arbitrary data objects. The logType parameter is a special data object key that is assigned to the log key of the log output.

The logger can be intialized with custom configuration as follows:

const logger = require('ziplog');

logger.initStandalone({
	// Override for the supported log levels, sorted by decreasing severity. Each of these becomes a named log function.
	logLevels: [ 'error', 'info', 'silly' ],
	// Any log message less severe than this level will be ignored.
	minLogLevel: [ 'info' ],
	// Suppress the stack trace from logged errors.
	suppressErrorStack: true,
	// Explicity set the 'app' field on log messages. This is pulled from package.json by default.
	appName: 'ziplog-test',
	// Data-writeable stream to write log entries to. Data is written to stdout by default.
	writeStream: process.stderr
});

Multithreaded logging

When logging from multiple node threads simultaneously, the messages as written to standard output can become interwoven and jumbled. Ziplog provides a log server and client system to ensure this doesn't happen. Under this architecture, the singleton log server is solely responsible for logging to the console, and clients send their messages to it over UNIX sockets. This setup is initialized as follows:

// Main file
const logger = require('ziplog');
const child_process = require('child-process');

logger.initServer({ /* logger config */ })
	.then(() => {
		logger.info('Log from main');
		child_process.fork('subprocess.js');
	});
// subprocess.js
const logger = require('ziplog');

logger.initClient({ /* logger config */ })
	.then(() => {
		logger.info('Log from sup process');
	});

The socket files for inter-thread communication are stored in a directory named ziplog-socket in the project root directory. You should add this directory to .gitignore.