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

log-skidder

v1.2.2

Published

Provides a common logging interface.

Downloads

10

Readme

Log Skidder

Log Skidder is a universal system for managing logging events and console output.

Build Status Maintainability Test Coverage Known Vulnerabilities

Description

Log Skidder is designed to be a isomorphic interface for Node JS or browser environments to manage logging. In a browser multiple applications on a page can use Log Skidder and they will link to a single instance automatically. It provides a common interface for log handlers that are used with events in all applications linked. It can also capture the console methods as well. Meaning even apps that are not specifically written for Log Skidder can be caputered and managed.

Installing

npm i -D log-skidder

How To Implement

To implement into a project you just need to

import skid from 'log-skidder';

This will bootstrap the Log Skidder system and provide a LogSkidder object.

LogSkidder Parameters and Methods

- original: Object that stores the original console methods.
- hookConsoleMethods(): This method will replace the console methods to the log manager undefined.
- unhookConsoleMethods(): This will return the original native console methods.
- group(): This method returns the log manager name specified.  If name is not found it will return a new log manager with the specified group.
- store(): Store method takes a event object and places it verbatim into the log stack and runs the handlers.  Useful for placing events from external sources.

In your application bootstrap you will want to make a log manager specifically for your application. To do so just add a line like bellow.

const logMgr = skid.group('My App');

LogManager Parameters and Methods

- error(): Method to use in the exact way you would use console.error
- log(): Method to use in the exact way you would use console.log
- warn(): Method to use in the exact way you would use console.warn
- put(): With this method you can specify custom event types.  First argument is a string that specifies the event type. All arguments past the first is treated as the log message.
- list(): Returns a list of events that matches the event type parameter specified.
- clear(): This method clears events from the log stack.

With this log manager you can easily log events. Just use them exactly you would use the console counter parts.

logMgr.error("uh oh something broke.");

This will log an error for the "My App". To get a list of errors enter the following.

logMgr.list('error');

If you want to see all logged events don't specify a type.

logMgr.list();

Handlers

In order to make the logging more useful you can add handlers. A handler is a callback that is ran when a new event of any type is triggered by any attached app. The handler callback is passed the triggering event as a parameter. The handler decides what it wants to do with the event given to it. For example a handler could choose to send to remote logger any errors that come from a particular app name but ignore everything else. Here is an example of adding a handler in Log Skidder.

skid.handlers.add(newEvent => {
    if (newEvent.eventType === 'error') {
        remoteLogger(newEvent);
    }
});

But if you want to list off all the events based off of either event type or app name you can do that via the method called search(). The search method takes a single object parameter. This object can optionally specify either the groupName or the eventType, or both. For an example.

skid.search({
    groupName: "My App",
    eventType: "warn",
})

OR

skid.handlers.search({
    groupName: "My App",
    eventType: "warn",
});

This will return a list of all the warnings from "My App". But you can list all events by writing...

skid.handlers.search({});

To remove events you can use the method remove using a specifier like above.

skid.remove({
    groupName: 'Bad Group',
    eventType: 'log',
});

This will remove all log events in group 'Bad Group. Specifying a event type but not a group will remove events of the specified type in all groups. As well as specify a group name without a event type will remove all events in the specified group.

Special Browser Information

If your using this module in your front-end project you can include it in your source if your using Typescript or Babel. Or you can include the module in the page directly. The file dist/log-skidder.js is browser safe. When Log Skidder is loaded in a browser it will add a object named LogSkidder to the window object. It can be used exactly like the source compiled one.