rabbitmq-logger

0.0.7 • Public • Published

Log messages to RabbitMQ

A Winston Transport module for sending logs to RabbitMQ

NPM

Node.js CI Known Vulnerabilities Total alerts Language grade: JavaScript DeepScan grade

This library was primarily designed to be used as a transport module for Winston logger. It can also be used as a simple utility for sending messages to RabbitMQ with minimum effort for configuration.

Installation

npm install rabbitmq-logger --save 
Requires Node >= 8.3.0 to run

Usage

var winston = require('winston');
require('rabbitmq-logger');
 
var logger = winston.createLogger({
    transports: [
        new  winston.transports.RabbitmqTransport({
            name:  'name',
            level:  'debug',
            url:  'amqp://url:port'
        })
    ]
});
 
logger.info('Hello World!');

Usage as a RabbitMQ helper utility

var winston = require('winston');
require('rabbitmq-logger');
 
var mq = winston.createLogger({
    transports: [
        new  winston.transports.RabbitmqTransport({
            url:  'amqp://url:port'
        })
    ]
});
 
module.exports = {
    mq
}
 
mq.log('xyz', 'Hello World!');

Options

The module can be customized using the following options :

  • name : The logger name, common option for Winston transports
  • level: The logging level (debug/info/warn/error). The level name is used as the default routing key while sending to RabbitMQ. Can have custom strings if required.
  • url: The RabbitMQ server url which is going to be used for creating connection. If not specified, it takes WINSTON_RABBITMQ_URL environment variable as the url or uses default value amqp://localhost:5672
  • socketOpts: Options that are going to used for creating connection to RabbitMQ socketOpts: {}
  • exchange: RabbitMQ Exchange that is going to be used for sending messages
  • exchangeOptions: Options that are going to be used for by channel for sending messages to exchange exchangeOptions:{}
  • logToConsole: Boolean value that enables logging to console if sending messages to RabbitMQ is not required
  • timestamp: By default it returns the current timestamp in ISO format. Can be overridden if required
  • debug: Takes a custom function that can be used for getting debug messages from the library. Only enabled if the logging level is also set as debug

Message Format

{
    level: <log_level or custom_key>,
    message: <message_body>,
    name: <name of the logger instance>,
    src: <system hostname>
}

Package Sidebar

Install

npm i rabbitmq-logger

Weekly Downloads

14

Version

0.0.7

License

SEE LICENSE IN LICENSE

Unpacked Size

53.5 kB

Total Files

14

Last publish

Collaborators

  • debarghya