log4js-node

A port of log4js to node.js

View the Project on GitHub

Logstash UDP Appender

This appender sends log events to a logstash server via UDP. It uses the node.js core UDP support, and so requires no extra dependencies. Remember to call log4js.shutdown in your application if you want the UDP socket closed cleanly.

Configuration

Example

log4js.configure({
  appenders: {
    logstash: {
      type: 'logstashUDP',
      host: 'log.server',
      port: '12345',
      logType: 'application',
      fields: { biscuits: 'digestive', tea: 'tetley' }
    }
  },
  categories: {
    default: { appenders: ['logstash'], level: 'info' }
  }
});
const logger = log4js.getLogger();
logger.info("important log message", { cheese: 'gouda', biscuits: 'hobnob' });

This will result in a JSON message being sent to log.server:12345 over UDP, with the following format:

{
  '@version': '1',
  '@timestamp': '2014-04-22T23:03:14.111Z',
  'type': 'application',
  'message': 'important log message',
  'fields': {
    'level': 'INFO',
    'category': 'default',
    'biscuits': 'hobnob',
    'cheese': 'gouda',
    'tea': 'tetley'
  }
}