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

log4js-node-amqp

v2.0.0

Published

An AMQP appender for log4js-node

Downloads

15

Readme

log4js-node-amqp

An AMQP appender for log4js-node

travis npm standard

Installation:

npm install log4js-node-amqp

Usage:

Configure in code:

var log4js = require('log4js');
var amqpAppender = require('log4js-node-amqp');

log4js.addAppender(
  amqpAppender.appender({
    // more config options available
    connection: {
      url: "amqp://guest:guest@localhost:5672"
    },
    // this is a space for you to add custom bits to every log message
    additionalInfo: {
      machine: require("os").hostname(),
      applicationName: 'example application'
    }
  }),
  'amqp-example'
);

or configure via configure() You could also require() a config .json or .js file here, any Javascript object will work with log4js.

log4js.configure({
  appenders: [
    {
      type: 'console'
    },
    {
      type: 'log4js-node-amqp',
      connection: {
        url: "amqp://guest:guest@localhost:5672"
      },
      // this is a space for you to add custom bits to every log message
      additionalInfo: {
        machine: require("os").hostname(),
        applicationName: 'example application'
      }
      category: 'amqp-example'
    }
  ]
});

Log things:

var logger = log4js.getLogger('amqp-example');
// strings work
logger.info('a string of log data.');
// so do objects
logger.info({name: 'a string', type: 'a silly example'});

You can also have a look at the example.

Configuration

This is a log4js appender which uses the awesome node-amqp package and shares a good bit of config with it.

 {
   // see https://github.com/postwait/node-amqp#connection
  connection: {
    url: "amqp://guest:guest@localhost:5672",
    clientProperties: {
      product: 'log4js'
    }
  },
  // see https://github.com/postwait/node-amqp#connectionexchange
  exchange: {
    name: 'logExchange',
    type: 'fanout',
    durable: true,
    autoDelete: false
  },
  // see https://github.com/postwait/node-amqp#queue - specifying a queue is optional, if you don't
  // specify one, logs will be published to the exchange. If you do specify a queue, it will be 
  // automatically created and bound to the exchange.
  queue: {
    name: 'logQ',
    durable: true,
    autoDelete: false
  },
  // see https://github.com/postwait/node-amqp#exchangepublishroutingkey-message-options-callback
  publish: {
    mandatory: true,
    deliveryMode: 2, // persistent
    routingKey: 'msg'
  },
  // interval at which to flush messages to the queue, 0 means "immediate"
  sendInterval: 0,
  // a log4js layout, this is ignored if the logged item is an object
  layout: log4js.layouts.messagePassThroughLayout,
  // this is a space for you to add custom bits to every log message
  additionalInfo: {
    //
  },
  // if you'd like to alter the logEvent before it's sent to the exchange
  logEventInterceptor: function(logEvent, additionalInfo) {
    //
  }
}

What's sent to the exchange?

// Everything log4js provides, + whatever you added to additionalInfo 
// (keys in additionalInfo are added as keys to the log message).
{
  timestamp: Fri Dec 20 2013 20:54:22 GMT-0800 (PST),
  data: 'test-message',
  level: { level: 20000, levelStr: 'INFO' },
  category: 'test'
}

// if you specified a logEventInterceptor in options,
// then whatever logEventInterceptor returns will be sent, e.g.:
log4js.configure({
  appenders: [
    {
      type: 'log4js-node-amqp',
      // more config here
      logEventInterceptor: function(logEvent, additionalInfo) {
        return (logEvent.data || {}).message; // send a simple string to the exchange
      }
    }
  ]
});

Reading things from the log-queue

If you want some ideas on how to read things from the log queue, have a look at this simple log reader example.

License

The MIT License

Copyright (c) 2015 Max Nachlinger