Skip to content

Instantly share code, notes, and snippets.

@jmcbee
Created December 22, 2014 12:40
Show Gist options
  • Save jmcbee/35cf8030ce6876fc6c73 to your computer and use it in GitHub Desktop.
Save jmcbee/35cf8030ce6876fc6c73 to your computer and use it in GitHub Desktop.
'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