log4js-node-amqp
An AMQP appender for log4js-node
Installation:
npm install log4js-node-amqp
Usage:
Configure in code:
var log4js = ;var amqpAppender = ; log4js;
or configure via configure()
You could also require()
a config .json or .js file here, any Javascript object will work with log4js.
log4js;
Log things:
var logger = log4js;// strings worklogger;// so do objectslogger;
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: log4jslayoutsmessagePassThroughLayout // 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 { // }
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- 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;
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
Copyright (c) 2015 Max Nachlinger