Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

winston-loggly-syslog

NPM version NPM downloads MIT License

A Loggly transport for winston that uses Loggly's syslog interface.

Installation

Installing winston-loggly-syslog

  $ npm install winston
  $ npm install winston-loggly-syslog

There is only one required option for logging to Loggly:

  • token: API Token for your account on Loggly

Usage

  var winston = require('winston')

  //
  // Requiring `winston-loggly-syslog` will expose
  // `winston.transports.Loggly`
  //
  var logglyWinston = require('winston-loggly-syslog').Loggly

  var logger = new winston.Logger({
    transports: [
      new winston.transports.Loggly({
        token: 'abc'
      })
    ]
  })

  logger.info('this is my message')

For more some advanced logging, you can take advantage of custom formatting and setting tags in Loggly:

  var winston = require('winston')

  //
  // Requiring `winston-loggly-syslog` will expose
  // `winston.transports.Loggly`
  //
  var logglyWinston = require('winston-loggly-syslog').Loggly

  var logger = new winston.Logger({
    transports: [
      new winston.transports.Loggly({
        token: 'abc',
        tags: ['tag1', 'tag2'],
        logFormat: function(message, meta) {
          if (!meta) meta = {}
          meta['message'] = message
          return JSON.stringify(meta)
        }
      })
    ]
  })

  logger.info('this is my message')

The Loggly transport is also capable of emitting events for error and connect so you can log to other transports:

var winston = require('winston')
  , Loggly = require('winston-loggly-syslog').Loggly

var logger
  , consoleLogger = new winston.transports.Console({
      level: 'debug',
      timestamp: function() {
        return new Date().toString()
      },
      colorize: true
    })
  , logglyTransport = new Loggly({
      token: 'abc'
    })

logglyTransport.on('error', function(err) {
  logger && logger.error(err)
})

logglyTransport.on('connect', function(message) {
  logger && logger.info(message)
})

var logger = new winston.Logger({
  levels: {
    debug: 0,
    info: 1,
    warn: 2,
    error: 3
  },
  transports: [
    logglyTransport,
    consoleLogger
  ]
})

logger.info('this is my message ' + new Date().getTime())

Currently, the Loggly transport only supports TLS logging over TCP.

Credits

The code is based on the original version of winston-papertrail.

License: MIT

About

A Loggly transport for winston that uses Loggly's syslog interface

Resources

License

Releases

No releases published

Packages

No packages published