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

primus-logger

v0.0.1

Published

Add logging capabilities to the real-time Primus framework.

Downloads

8

Readme

Primus Logger

Build Status NPM version

primus-logger is a tiny module for the Primus real-time framework that allows you to add context to logging messages.

Even if you're simply outputting data to the console, it is often useful to correlate certain messages with application context (for instance, to log which user was responsible for triggering a certain event). Such metadata usually resides on the Spark object, which this module can dynamically export by prefixing each message with certain object properties.

The modules wraps the winston logging library, which theoretically means that every option supported by winston is also supported by primus-logger (e.g. transport configuration).

Installation

Installation occurs via npm:

npm install primus-logger --save

Usage

Like any other Primus plugin, you only need to create a server instance and use the plugin. It exposes a new option, logging, where all the configuration necessary for the plugin can be defined.

By default, the Console transport of winston is used, which does not use colors or timestamps, with an info level output cut out. The following overrides theses defaults to adds colors and timestamps.

The prefix property uses an object path to get the data from the Spark instance. You can read more about how to formulate your prefix by visiting the object-path project page.

'use strict';

var Primus = require('primus'),
  winston = require('winston');

var server = http.createServer()
  , primus = new Primus(server, {
      logging: {
            prefix: ['id', 'address.ip'],
            transports: [
              new (winston.transports.Console)({
                'timestamp': true,
                'colorize': true
              })
            ]
          }
  });

primus.use('logger', 'primus-logger');

primus.on('connection', function (spark) {
  spark.info('Connected');

  if ('127.0.0.1' !== spark.address.ip) {
    spark.log('error', 'Unexpected ip "' + spark.address.ip + '"');
  }
});

The output on the console will look like this:

2014-01-01T15:00:28.012Z - info: [1388618721010$0/127.0.0.1] Connected
2014-01-01T15:00:28.012Z - error: [1388618721010$0/127.0.0.1] Unexpected ip "127.0.0.2"

Supported levels

The following logging levels are supported on a Spark instance:

  • log (generic, requires a level argument)
  • debug
  • info
  • warn
  • error
  • err (alias of error)

Options

Currently, the only configurable option on the primus-logger plugin, besides dynamic properties (configured as prefix), is the separator string (defaults to /).

Compatibility

This plugin has been tested against Primus 1.5.x only.

License

MIT