Nonlinear Performance Magnification

    winston-loggly-syslog

    1.0.0 • Public • Published

    winston-loggly-syslog

    NPM version NPM downloads ![MIT License][license-image]

    A [Loggly][0] transport for [winston][1] 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

    Install

    npm i winston-loggly-syslog

    DownloadsWeekly Downloads

    5

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • mathrawka