Created
December 22, 2014 12:40
-
-
Save jmcbee/35cf8030ce6876fc6c73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var winston = require('winston'); | |
var Syslog = winston.transports.SyslogConsole = function (options) { | |
var Producer = require('glossy').Produce; | |
winston.Transport.call(this, options); | |
this.producer = new Producer({ | |
appName: options.appName || 'winston', | |
host: options.host || require('os').hostname(), | |
facility: options.facility || 'local6' | |
}); | |
this.appName = options.appName || 'winston'; | |
this.name = 'syslog-shit'; | |
this.level = options.level || 'emerg'; | |
}; | |
require('util').inherits(Syslog, winston.Transport); | |
Syslog.prototype.log = function(level, msg, meta, callback) { | |
var line; | |
var data = {}; | |
data[this.appName] = meta; | |
line = this.producer.produce({ | |
severity: level, // or a relevant string | |
host: this.host, | |
appName: this.appName, | |
date: new Date(Date()), | |
message: msg, | |
structuredData: data | |
}); | |
if (!line) { | |
return callback(true); | |
} | |
process.stdout.write(line + '\n'); | |
callback(null, true); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment