# RabbitMQ Appender

Push log events to a RabbitMQ (opens new window).

npm install --save @tsed/logger-rabitmq
1

If you want to be sure that all messages have been sent before your programme exits, remember to call logger.shutdown().

# Configuration

  • type - rabbitmq
  • layout - object (optional, defaults to messagePassThroughLayout) - the layout to use for log events (see Layouts).
  • options.host - string (optional, defaults to 127.0.0.1) - the location of the rabbitmq server
  • options.port - integer (optional, defaults to 5672) - the port the rabbitmq server is listening on
  • options.username - string (optional, defaults to guest) - username to use when authenticating connection to rabbitmq
  • options.password - string (optional, defaults to guest) - password to use when authenticating connection to rabbitmq
  • options.routing_key - string (optional, defaults to logstash) - rabbitmq message's routing_key
  • options.durable - string (optional, defaults to false) - will that RabbitMQ lose our queue.
  • options.exchange - string (optional, defaults to log)- rabbitmq send message's exchange
  • options.mq_type - string (optional, defaults to direct) - rabbitmq message's mq_type
  • options.vhost - string (optional, defaults to /) - vhost to use
  • options.shutdownTimeout - integer (optional, defaults to 10000) - maximum time in milliseconds to wait for messages to be sent during log4js shutdown.

# Example

import {Logger} from "@tsed/logger";
import "@tsed/logger-rabbitmq";

const logger = new Logger("loggerName");

logger.appenders.set("stdout", {
  type: "rabbitmq",
  level: ["info"],
  options: {
    host: "127.0.0.1",
    port: 5672,
    username: "guest",
    password: "guest",
    routing_key: "logstash",
    exchange: "exchange_logs",
    mq_type: "direct",
    durable: true
  }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

This configuration will push log messages to the rabbitmq on 127.0.0.1:5672.

Last Updated: 10/26/2023, 6:30:07 AM

Other topics