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

scrib

v0.0.1

Published

A logger utility

Downloads

2

Readme

Scrib

A logger utlity for Node.js using adapters.

Scrib itself is just an event emitter with some fancy methods. The real wok is done by its adapters. When you initialize Scrib, you load one or more adapters for it. When you tell Scrib to log something, it's going to tell every adapter about your log and they'll handle it in their way e.g. send an e-mail or write to a log file.

For Scrib everything is a message. Every error, warning or log is a message. Each message has following properties:

  • message: A short message describing itself
  • data = {}: Optional data (e.g. API response)
  • priority = 0: The message's importance as a number equal or greater than 0
  • id = null: An ID to specify the message. Useful for errors
  • category = null: A category to group messages (e.g. Database)
  • time = Date.now(): The timestamp when we logged

Example

npm install scrib

var Scrib = require("Scrib"),
    logger = new Scrib({
        "local": {
            file: "./log.txt"
        },
        function(e) {
            
            // If during Scrib's startup an error appeared we should stop the process
            if(e) throw e;
            
            logger.put("Hello World");
        });

This example loads the local-adapter for Scrib. After Scrib finished loading it's going to call the callback.

Adapters

API

new Scrib(adapters, callback)

Initalizes a new logger. adapters is a object where each key is an adapter's name and the value is an config object which is going to be passed into the adapter. Scrib first tries to require scrib-{ADAPTER} and then the file directly (see the code). callback is a callback where the first argument is an error.

new Scrib({
    // Will require scrib-local
    "local": {},
    
    // Wll require ./adapter.js
    "./adapter.js": {},
    function(e) {}
);

Scrib.put(message, data, priority, id, category)

The simplest way to log something:

logger.put("API limit reached", { limit: 5000 }, 10, "API_LIMIT", "API");

Scrib.register(id, message, priority, category)

Scrib.log(id, data)

If we don't want to call Scrib.put each time using priority, category and message, we can simply register a message and then log it using Scrib.log and the ID:

logger.register("API_LIMIT", "API limit reached", 10, "API");
logger.log("API_LIMIT", { limit: 5000 });

Scrib.catch(error, data)

This transforms an Error object into a message and then logs it:

try {
    throw new Error("Ups");
} catch(e) 
    logger.catch(e);
}

If e is an error thrown by libuv, Scrib will trun it into a message: message is e.description, id is e.code, data.errno is e.errno. Additional data from e is merged into data (see code).

Events

Scrib inherits from EventEmitter and has its functions.

  • log: Emitted for each log
  • id:ID: Emitted for each log if it's ID is ID, e.g. id:API_TIMEOUT
  • category:CATEGORY: Emitted for each log if it's category is category, e.g. category:API

Testing Build Status

git clone git://github.com/Acconut/scrib.git
cd scrib
npm install
npm test

Licensed under the MIT License.