winston-loggly-syslog
v1.0.0
Published
Loggly winston transport that uses syslog endpoint
Downloads
4
Readme
winston-loggly-syslog
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.