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

scribe-bus

v0.0.1

Published

Light logs manager running on redis pub-sub and Scribe-js to ensure you have a smart dashboard to view all your logs.

Downloads

2

Readme

Better Log Management

NPM

Take your console logs like these:

Screenshot

Into a web dashboard like this:

Screenshot

The Challenge

Managing logs can be a daunting task. Especially as your app grows and you need a central log manager. How do you keep uniform logs across your app and how do you then access the same logs.

Enter Redis PubSub

That's where Redis comes in handy. Using the PubSub system, we are able to listen for logs from a central location.

Logging & Exposing Logs

The next challenge is how to save the logs on disk and later access them. For this, we use the awesole Scribe-Js module.

Scribe JS manages the error logs and helps us expose them via an Express JS server.

How To Log Your Messages

First install the module. yarn add scribe-bus

Logging within your app

Use the following code within your app. Note: This logger does not replace the default console (as Scribe-Js works by default).


    //pass redis configurations
    var options = {
        redis: {
            port: 6379,
            host: '127.0.0.1'
        }
    }
    //get the logger instance...
    var {logger} = require('scribe-bus')(options);

    //log away!
    logger.log('This is a log!')
    logger.info('This is a for your information!')
    logger.error('This is an Error')
    logger.warn('This is a warning')

    /**
     * BY default, the log level (info,log,error) etc is used as a tag for your logs.
     * But you can also use custom tags.
     * Just add your tags as a string or array as the 2nd argument.
     * Note: The custom level allows you to define own logs
     **/
    logger.custom('This is a custom message', 'CUSTOM TAG');

    //This is a custom log with two tags
    logger.custom({type:"Object", msg: "Hey Yah!"}, ['OBJECT','Greeting']);
    
    //This also has two tags 1. Level Tag "Log" & "Other_Tag"
    logger.log('This is a log with Two Tags', 'Other_Tag');

Listen to PubSub & Serve Your Logs

Note: The code above does not save any actual logs. To do so, you will need to invoke the listen() method;

    var {logger} = require('scribe-bus');
    logger.listen()

However, if you listen in multiple places within your code, then you will end up creating duplicate events for each will listen to the same exact pub-sub channel/key.

Therefore, the recommended method is to launch a single Express server application that runs the logger.listen() method.

Below is a simple server application (also see server.js in examples folder)


    var express = require('express');
    var app = express();

    //redis options
    var options = {
        redis: {
            port: 6379,
            host: '127.0.0.1'
        }
    }

    //get scribe & logger instances
    var {scribe, logger} = require('scribe-bus')(options);

    //listen for subscribed events
    logger.listen()

    //use the scribe WebPanel
    app.use('/logs', scribe.webPanel());

    //... the rest of the server code

    var port = 3000;

    app.listen(port, function () {
        console.log(`Started server at port ${port}`);
    });

This server achieves two purposes.

  • It creates a pub-sub listener that syncs all log-events with the logger for saving in disk.
  • It spins a route "/logs" (change to whatever suits you) that can then be used to access your logs by going to http://localhost:3000/logs.

You can also drop the three lines needed into any existing express server app and it will work.

API

Initialization

var {scribe, logger} = require('scribe-bus')(options);

Logging

logger[log-level](msg, tags) :

  • log-level: is one of ('log/warning/error/info/dir/custom') e.g. log.info("Your Message")
  • msg: A string or object that you wish to log
  • tags: A tag (String) or Array of tags you wish to add to the message. Note: The "log-level" above is always appended as a tag.