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

cantina-log

v4.1.2

Published

JSON logging for Cantina apps

Downloads

3

Readme

cantina-log

JSON-powered logging for Cantina applications. Extends jog with some Cantina-specific functionality.

Usage

Setting up your app:

var app = require('cantina').createApp();

app.boot(function (err) {

  // Load the logging plugin.
  app.require('cantina-log');

  // Load the rest of your plugins.

  app.start();
});

Start logging...

// Perferred logging method:
app.log('type', {
  // data
})

// console.log-style logging.
app.log('My message with %s tokens in it', 'some');

// dump an object.
app.log({my: 'data'});

// Use levels:
app.log.info('type', { /* data */ });
app.log.debug('type', { /* data */ });
app.log.warn('type', { /* data */ });
app.log.error('type', { /* data */ });

Configuration

The following configuration (defaults shown) is supported.

{
  log: {
    trace: true,
    req: {
      enable: true,
      exclude: /(\.js$)|(\.css$)|(\/images.*)|(favicon.ico)|(\.hbs$)/
    }
  }
}
  • trace - Adds file and line number to all log entries. Should be turned OFF in production.
  • req
    • enable - Adds middleware that logs all requests.
    • exclude - A regular expression identifying paths to exclude from the logs.

Overriding console

  • app.log.replaceConsole() - Override console's logging methods with app.log variants.
  • app.log.restoreConsole() - Restore console to its orginal state.

Using a custom jog store

jog logs using a 'store'. The default is StdStore which logs to stdout and stderr. If you prefer to use a FileStore, RedisStore, or something custom you can tell the app like so:

var app = require('cantina').createApp()
  , jog = require('jog2');

app.boot(function (err) {
  // Pre-log app setup.

  // Specify your store.
  app.loggerStore = new jog.FileStore('/tmp/log');

  // Load the logging plugin.
  app.require('cantina-log');

  // Load the rest of your plugins.

  app.start();
});

Data serialization

You may find yourself logging simliar kinds of application object, such as 'user' models. You can log the raw user objects and implement a serializer to santize it for the logs.

app.hook('log:serialize').add(function (data, next) {
  if (data.user) {
    var user = data.user;
    data.user = {
      id: user.id,
      name: user.first + ' ' + user.last,
      // ... etc.
    };
  }
  next();
});

CLI

Now that your log output is in nice, parseable JSON, you may want to be able to read it on the command-line in a more human-friendly format. Joli is a CLI that helps you format newline-separated JSON object (like the ones cantina-log outputs).

Please see joli's README for full documentation.


Developed by Terra Eclipse

Terra Eclipse, Inc. is a nationally recognized political technology and strategy firm located in Santa Cruz, CA and Washington, D.C.