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

petit

v0.3.0

Published

Tinyiest possible logger.

Downloads

6

Readme

petit

Tinyiest possible logger. Node.js / IO.js.

Install

npm install petit

Usage

var logger = require('petit').get();
logger.info('Hello there.');

Scoping

If you have a moderately complex app with multiple modules or files, you can use petit's .scope() method which will prepend a string to the log output, showing where that output originated from.

logger.info('This is shown without any prefix.');

var scoped = logger.scope('component');
scoped.info('This will be shown with a "component" prefix before it.');

Now, Given that petit holds a shared reference for the logger initialized by .get(), you can have different scoped loggers that output to the same stream from different parts in your app. For example:

// main.js
var logger = require('petit').get();

// other.js
var logger = require('petit').get().scope('other');

Exports

petit.get(options)

Return the last initialized logger instance. If none exists, initializes a new one, and sets that one as the current.

var logger = require('petit').get(options);

This function is also aliased as the module's root exports, meaning you can call it like this:

var logger = require('petit')(options);

petit.new(options)

Initializes a new logger instance with the given set of options, whether a previous logger exists or not. This provides a way to have multiple logger instances, optionally writing to different streams.

var petit         = require('petit'),
    stdout_logger = petit.new(),
    stream_logger = petit.new({ stream: someWritableStream }),
    file_logger   = petit.new({ file: '/tmp/output.log' });

petit.scope(string)

Shortcut for calling .scope() over the logger returned by .get().

var logger = require('petit').scope('something');

Options

  • level: Log level. Options are: 'debug', 'info', 'notice', 'warn', 'error' and 'critical'. Default is info.
  • show_date: If false, hides the date from the log output. Defauts to true.
  • stream: Uses stream as the output stream where the log is written to. Defaults to process.stdout.
  • file: Creates a writeStream on file and uses it as the output stream. Optional.

Example

// index.js

var logger = require('petit')(),
    engine = require('./engine');

exports.boot = function() {
  logger.debug('Starting the engines...');
  engine.start(function() {
    logger.info('Engine started!');
  });
}

// engine.js

var logger = require('petit').scope('engine');

exports.start = function(cb) {
  if (cb == null)
    return logger.warn('No callback passed!');

  // (magic happens)
  cb();
}

Small print

Written by Tomás Pollak. (c) Fork, Ltd. MIT License.