bunyan-syslog
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -9,4 +9,2 @@ // Copyright 2013 Mark Cavage, Inc. All rights reserved. | ||
var assert = require('assert-plus'); | ||
var bunyan = require('bunyan'); | ||
var moment = require('moment'); | ||
@@ -20,4 +18,33 @@ | ||
var HOSTNAME = os.hostname(); | ||
var STR_FMT = '[object %s<host=%s, port=%d, proto=%s>]'; | ||
var STR_FMT = '[object %s<facility=%d, host=%s, port=%d, proto=%s>]'; | ||
// Harcoded from https://github.com/trentm/node-bunyan so this module | ||
// can have minimal dependencies | ||
var bunyan = { | ||
FATAL: 60, | ||
ERROR: 50, | ||
WARN: 40, | ||
INFO: 30, | ||
DEBUG: 20, | ||
TRACE: 10, | ||
safeCycles: function safeCycles() { | ||
var seen = []; | ||
function bunyanCycles(k, v) { | ||
if (!v || typeof (v) !== 'object') { | ||
return (v); | ||
} | ||
if (seen.indexOf(v) !== -1) { | ||
return ('[Circular]'); | ||
} | ||
seen.push(v); | ||
return (v); | ||
} | ||
return (bunyanCycles); | ||
} | ||
}; | ||
// Syslog Levels | ||
var LOG_EMERG = 0; | ||
@@ -67,3 +94,3 @@ var LOG_ALERT = 1; | ||
function time(t) { | ||
return (moment(t || new Date()).format('MMM DD:HH:mm:ss')); | ||
return (new Date(t).toJSON()); | ||
} | ||
@@ -150,2 +177,3 @@ | ||
'SyslogStream', | ||
this.facility, | ||
this.host, | ||
@@ -152,0 +180,0 @@ this.port, |
// Copyright 2013 Mark Cavage, Inc. All rights reserved. | ||
var EventEmitter = require('events').EventEmitter; | ||
var net = require('net'); | ||
var util = require('util'); | ||
var assert = require('assert-plus'); | ||
var SyslogStream = require('./sys'); | ||
@@ -11,2 +14,36 @@ | ||
///--- Globals | ||
var PROXY_EVENTS = [ | ||
'connect', | ||
'data', | ||
'drain', | ||
'end', | ||
'timeout' | ||
]; | ||
///--- Helpers | ||
function createSocket(opts) { | ||
assert.object(opts, 'options'); | ||
assert.string(opts.host, 'options.host'); | ||
assert.number(opts.port, 'options.port'); | ||
assert.object(opts.proxy, 'options.proxy'); | ||
var s = net.connect({ | ||
host: opts.host, | ||
port: opts.port | ||
}); | ||
PROXY_EVENTS.forEach(function (e) { | ||
s.on(e, EventEmitter.prototype.emit.bind(opts.proxy, e)); | ||
}); | ||
return (s); | ||
} | ||
///--- API | ||
@@ -20,20 +57,32 @@ | ||
this.queue = []; | ||
this.socket = net.connect({ | ||
host: self.host, | ||
port: self.port | ||
}); | ||
this.socket.once('connect', function () { | ||
self.queue.forEach(function (buf) { | ||
self.socket.write(buf); | ||
(function connect(event) { | ||
if (self.socket) { | ||
if (self.listeners(event).length > 1) { | ||
self.emit.apply(self, arguments); | ||
return; | ||
} | ||
PROXY_EVENTS.forEach(function (e) { | ||
self.socket.removeAllListeners(e); | ||
}); | ||
self.socket.removeAllListeners('close'); | ||
self.socket.removeAllListeners('error'); | ||
if (self.socket.destroy) | ||
self.socket.destroy(); | ||
} | ||
self.socket = createSocket({ | ||
host: self.host, | ||
port: self.port, | ||
proxy: self | ||
}); | ||
}); | ||
this.socket.on('close', this.emit.bind(this, 'close')); | ||
this.socket.on('connect', this.emit.bind(this, 'connect')); | ||
this.socket.on('data', this.emit.bind(this, 'data')); | ||
this.socket.on('drain', this.emit.bind(this, 'drain')); | ||
this.socket.on('end', this.emit.bind(this, 'end')); | ||
this.socket.on('error', this.emit.bind(this, 'error')); | ||
this.socket.on('timeout', this.emit.bind(this, 'timeout')); | ||
self.socket.on('close', setTimeout.bind(null, connect, 1000)); | ||
self.socket.on('error', setTimeout.bind(null, connect, 1000)); | ||
self.socket.once('connect', function () { | ||
self.queue.forEach(function (buf) { | ||
self.socket.write(buf); | ||
}); | ||
}); | ||
}()); | ||
} | ||
@@ -45,4 +94,13 @@ util.inherits(TCPStream, SyslogStream); | ||
TCPStream.prototype.close = function close() { | ||
var self = this; | ||
this.writable = false; | ||
this.socket.end(); | ||
PROXY_EVENTS.forEach(function (e) { | ||
self.socket.removeAllListeners(e); | ||
}); | ||
self.socket.removeAllListeners('close'); | ||
self.socket.removeAllListeners('error'); | ||
this.socket = null; | ||
}; | ||
@@ -49,0 +107,0 @@ |
{ | ||
"name": "bunyan-syslog", | ||
"description": "Syslog Stream for Bunyan", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "Mark Cavage", | ||
"main": "./lib/index.js", | ||
"dependencies": { | ||
"assert-plus": "0.1.2", | ||
"bunyan": "0.16.8", | ||
"moment": "1.7.2" | ||
"assert-plus": "0.1.2" | ||
}, | ||
"devDependencies": { | ||
"bunyan": "0.16.8", | ||
"tap": "0.3.3" | ||
@@ -14,0 +13,0 @@ }, |
@@ -19,3 +19,3 @@ bunyan-syslog is a stream for [bunyan](https://github.com/trentm/node-bunyan) | ||
stream: bsyslog.createSyslogStream({ | ||
facility: bsyslog.local0, | ||
facility: bsyslog.facility.local0, | ||
host: '192.168.0.1', | ||
@@ -22,0 +22,0 @@ port: 514 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3891694
1
438
2
- Removedbunyan@0.16.8
- Removedmoment@1.7.2
- Removedbunyan@0.16.8(transitive)
- Removeddtrace-provider@0.2.4(transitive)
- Removedmoment@1.7.2(transitive)