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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@elbanby/loggy

v0.6.0

Published

Simple and fast JSON logger

Readme

Loggy

Simple and fast JS JSON logger.

const Loggy = require("@elbanby/loggy");

// Simple log message
Loggy.log(`successfully connected to DB`, __filename);

// logging an error
if (error) {
    Loggy.error("Error occurred while connecting to db", error, __filename);
    process.exit(1);
}

// customizing your stdout
Loggy.setOutStream((data) => { 
    // write to file or do as you please with it
});

Loggy.setErrorStream((data) => {
    // write to file or do as you please with it
});
[log] - [Sun, 22 Sep 2019 11:28:09 GMT] 
{
        message: successfully connected to DB
        module: /Users/omarelbanby/development/loggy/test/loggy.test.js
}

[error] - [Sun, 22 Sep 2019 11:28:10 GMT] 
  {
          message: oh shoot an error occured
          stacktrace: Error: shoot
          module: /Users/omarelbanby/development/loggy/test/loggy.test.js
  }

Motivation

The motivation behind Loggy is quite simple in every NodeJS project I work on there are almost the same kind of problems:

1- Developers tend to forget random console log messages which pollutes the stdout

2- Developers usually need to log error messages. However, later down the line, an unexpected error occurs, and the console message is too generic to hunt down.

Loggy attempts to solve these issues by standardizing the way developers log messages in their codebase. Depending on the log level, different parameters are needed. That ensures the log is descriptive and shows the filename where the error occurred + the stack trace, which makes debugging a lot easier. In addition, Loggy forces the user to write a message for the anticipated error, and this leads to a more thoughtful logging mechanism.

How to use

Importing

const Loggy = require("@elbanby/loggy");

When you import Loggy you get back a singleton instance which can be shared across your code base.

Configuration

To configure Loggy you can use the config function which you can pass any of the following configs:

const Loggy = require("@elbanby/loggy");

Loggy.config({
    outStream: (data) => {
        const file = fs.appendFile("./logs", data, _ => console.log("Finished writing to log file"));
    },
    errorStream: (data) => {
        const file = fs.writeFile("./errors", data, _ => console.log("Finished writing to error file") );
    },
    pretty: true,
    isJson: false
});

Please note if you use your custom outStream or/and errorStream the pretty option doesn't take effect. However, if you are just logging to the console and/or redirecting the logs you can easily have pretty logging

node app.js 1> logs.log 2> error.log

Also please note that if you pass any invalid configuration to the config object, Loggy will throw an error, reflecting that the key you used is invalid option

Custom formatter

Right now I am using the format function to format the output for json and pretty print. Also to add the date the log level.

If you feel like you want to customize the formatter for your application, you can easily do that. However, you will have to handle the entire formatting process yourself.

To do that you overwrite the format function

Loggy.format = (logLevel, data) => {
    return data;
};

Please note that loglevel is an object that includes "type" and "color". Here is an example

  log: {
        type: "log",
        color: '\x1b[32m'
    }

Function signatures for all log levels available

Loglevel | parameters | example | :---: | :---: | :---: | info | (message, module) | Loggy.info(message, module)| log | (message, module) | Loggy.log("successfully connected to DB", __filename); | warn | (message, module) | Loggy.warn("Retrying to establish connection", __filename); | error | (message, stacktrace, module) | Loggy.error("Error occurred while connecting to db", error, __filename); |