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

winston-axon

v2.0.0

Published

A message oriented transport for Winston based on axon

Downloads

10

Readme

winston-axon

This is a message oriented Transport for winston based on axon-secure.

Motivation

If you have a large application with a lot of independent services, you can easy log every service with a unique socket logging endpoint using axon-secure as message-oriented library.

Installation

Install winston-axon as usual:

$ npm install winston-axon

Options

When you add winston-axon to your winston logger, you can provide this options:

  • host: (Default: 127.0.0.1) Remote host of the socket logging endpoint
  • port: (Default: 3000) Remote port of the socket logging endpoint
  • timestamp: (Default false) Boolean flag indicating if we should add a timestamp to the output. If function is specified, its return value will be used instead of timestamps
  • secure: (Default: false) set true to encrypt every message
  • cipher: (Default: aes256) the cipher used for encryption
  • secret: (Default: secret remember to change it!) the shared password for encryption.

Usage

To use this plugin you must have a socket logging endpoint (server) and at least a logger (client).

Server

Create your own server use this simple example:

// dependencies
var axon = require('axon-secure');
var winston = require('winston');

// set socket with encryption
var sock = axon.socket('pull', {
  secure: true,
  cipher: 'aes256',
  secret: 'password'
});
// or set socket without encryption
// var sock = axon.socket('pull');
sock.bind('tcp://127.0.0.1:3000');

// create a customized Console Transport
var consoleTransport = new winston.transports.Console({
  level: 'debug',
  colorize: true,
  timestamp: false
});

// create new Logger
var logger = new (winston.Logger)({
  transports: [
    consoleTransport // add other Transport types if you need
  ],
  exitOnError: true
});

// wait for incoming logs
sock.on('message', function(msg) {
  logger.log(msg.level, msg);
});

logger.info('server started');

Save as server.js and start the server:

$ node server.js

info: server started

Client

Into the client simply add winston-axon as new Transport to your winston instance:

var winston = require('winston');
var Axon = require('winston-axon').Axon;
winston.add(Axon, {
  level: 'debug',
  timestamp: new Date(),
  secure: true,
  cipher: 'aes256',
  secret: 'password'
});
winston.debug({ message: 'Test Object Log Message', error: false });
winston.log('info', 'Test Log Message', { anything: 'This is metadata' });

Save as client.js and start it:

$ node client.js

info: Test Log Message anything=This is metadata

Now in your previous terminal session (that when the server is running) you see this new lines:

debug:  level=debug, message=Debug text only message, timestamp=2014-03-14T14:22:18.536Z
debug:  custom=Test Object Log Message, error=false, level=debug, message=Debug exented message, timestamp=2014-03-14T14:22:18.537Z
info:  anything=This is metadata, level=info, message=Test Log Message, timestamp=2014-03-14T14:22:18.538Z

Note that into the client terminal you see only the info message whereas into the server terminal you see all messages because the server has a customized level of the Console Transport.

For more information please refer to winston and axon-secure documentations.

Run Tests

Like other Transport plugins, all of the winston-axon tests are written in vows, and designed to be run with npm.

$ npm test