log4js-node / rabbitmq

RabbitMQ appender for log4js-node
Apache License 2.0
8 stars 4 forks source link

Rabbit Topic embed log level into routing key #4

Closed charithf closed 2 years ago

charithf commented 5 years ago

I'm interested in the rabbitmq log appender. Can I put the log level into the routing key? Is there a way to configure this? or else is there a way to access the log level via the payload?

kmacpher67 commented 4 years ago

what layout type: did you choose, it's configurable from the base log4js feature. Just add it to the bottom of the rabbit {} list of config attributes:

    type: '@log4js-node/rabbitmq',
    protocol: 'amqps',
       .....  0,
    layout: { type: 'json', separator: ',' }
  }

I implemented "custom" json layout, which inherited the color and everything layout. My rabbit logs have this: "level":{"level":20000,"levelStr":"INFO","colour":"green"}

export interface BaseLayout { type: 'basic'; export interface ColoredLayout { type: 'colored' | 'coloured';

Pick a standard layout or customize you own.

function timestampLevelAndCategory(loggingEvent, colour) {
  return colorize(
    util.format(
      '[%s] [%s] %s - ',
      dateFormat.asString(loggingEvent.startTime),
      loggingEvent.level.toString(),
      loggingEvent.categoryName
    ),
    colour
  );
}