fluent-logger
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -21,3 +21,10 @@ var FluentSender = require('./sender').FluentSender; | ||
return new FluentSender(tag, options); | ||
}, | ||
support: { | ||
log4jsAppender: function(options){ | ||
var log4jsSupport = require('../lib/log4js'); | ||
return log4jsSupport.appender(options); | ||
} | ||
} | ||
} |
@@ -15,7 +15,6 @@ var util = require('util'); | ||
this._socket = null; | ||
this._queue = []; | ||
this._queueTail = -1; | ||
this._sendQueue = []; // queue for items waiting for being sent. | ||
this._sendQueueTail = -1; | ||
this._eventEmitter = new EventEmitter(); | ||
} | ||
// util.inherits(FluentSender, EventEmitter); | ||
@@ -26,6 +25,6 @@ FluentSender.prototype.emit = function(label, data, callback){ | ||
item.callback = callback; | ||
self._queue.push(item); | ||
self._queueTail++; | ||
self._sendQueue.push(item); | ||
self._sendQueueTail++; | ||
self._connect(function(){ | ||
self._sendQueue(); | ||
self._flushSendQueue(); | ||
}); | ||
@@ -40,3 +39,3 @@ }; | ||
FluentSender.prototype.end = function(label, data){ | ||
FluentSender.prototype.end = function(label, data, callback){ | ||
var self = this; | ||
@@ -46,5 +45,9 @@ if( (label != null && data != null) ){ | ||
self._close(); | ||
callback && callback(err); | ||
}); | ||
}else{ | ||
self._close(); | ||
process.nextTick(function(){ | ||
self._close(); | ||
callback && callback(err); | ||
}); | ||
} | ||
@@ -64,3 +67,3 @@ }; | ||
var tag = [self.tag, label].join('.'); | ||
var time = (new Date()).getTime() / 1000; | ||
var time = (new Date()).getTime() / 1000; | ||
var packet = [tag, time, data]; | ||
@@ -91,21 +94,24 @@ return { | ||
}else{ | ||
callback(); | ||
process.nextTick(function(){ | ||
callback(); | ||
}); | ||
} | ||
}; | ||
FluentSender.prototype._sendQueue = function(){ | ||
FluentSender.prototype._flushSendQueue = function(){ | ||
var self = this; | ||
var pos = self._queue.length - self._queueTail - 1; | ||
var item = self._queue[pos]; | ||
var pos = self._sendQueue.length - self._sendQueueTail - 1; | ||
var item = self._sendQueue[pos]; | ||
if( item === undefined ){ | ||
// nothing written; | ||
}else{ | ||
self._queueTail--; | ||
self._sendQueueTail--; | ||
self._sendQueue.shift(); | ||
self._socket.write(new Buffer(item.packet), function(){ | ||
self._queue.shift(); | ||
self._sendQueue(); | ||
process.nextTick(function(){ | ||
item.callback && item.callback(); | ||
}); | ||
item.callback && item.callback(); | ||
}); | ||
process.nextTick(function(){ | ||
self._flushSendQueue(); | ||
}); | ||
// TODO: how should we recorver if dequeued items are not sent. | ||
} | ||
@@ -112,0 +118,0 @@ }; |
{ | ||
"name": "fluent-logger", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"main": "./lib/index.js", | ||
@@ -14,3 +14,8 @@ "author": { | ||
}, | ||
"devDependencies": { | ||
"mocha": "", | ||
"chai": "", | ||
"log4js": "" | ||
}, | ||
"keywords": ["logger", "fluent"] | ||
} | ||
} |
@@ -21,3 +21,3 @@ # fluent-logger for node.js | ||
host: 'localhost', | ||
port: 24224 | ||
port: 24224, | ||
timeout: 3.0 | ||
@@ -29,7 +29,24 @@ }); | ||
## Logging Library Support | ||
### log4js | ||
Befre using [log4js] support, you should install it IN YOUR APPLICATION. | ||
var log4js = require('log4js'); | ||
log4js.addAppender(require('fluent-logger').support.log4jsAppender('mytag', { | ||
host: 'localhost', | ||
port: 24224, | ||
timeout: 3.0 | ||
})); | ||
var logger = log4js.getLogger('foo'); | ||
logger.info('this log record is sent to fluent daemon'); | ||
## License | ||
Apache License, Version 2.0 | ||
Apache License, Version 2.0. | ||
[fluent-logger-python]: https://github.com/fluent/fluent-logger-python | ||
@@ -1,62 +0,31 @@ | ||
var assert = require('assert'); | ||
var expect = require('chai').expect; | ||
var sender = require('../lib/sender'); | ||
var fluentd = require('../lib/testHelper').fluentd; | ||
var async = require('async'); | ||
module.exports = { | ||
"test send object": function(){ | ||
var s = new sender.FluentSender('debug'); | ||
s.end('test send object', { | ||
string: 'a', | ||
number: 1, | ||
object: { | ||
a: 'b' | ||
}, | ||
array: [1,2,3], | ||
bool: true, | ||
null: null, | ||
undefined: undefined | ||
}, function(err){ | ||
assert.isNull(err); | ||
}); | ||
}, | ||
"test once": function(){ | ||
var s = new sender.FluentSender('debug'); | ||
s.end('test once', 'test once', function(){ | ||
assert.eql(s._queueTail.length, 0); | ||
}); | ||
assert.eql(s._queue.length, 1); | ||
}, | ||
"test many": function(){ | ||
var s = new sender.FluentSender('debug'); | ||
s.emit('test many', 'test many1', function(){ | ||
s.emit('test many', 'test many2', function(){ | ||
s.end(); | ||
describe("FluentSender", function(){ | ||
it('shoud send records', function(done){ | ||
fluentd(function(port, finish){ | ||
var s1 = new sender.FluentSender('debug', { port: port }); | ||
var emits = []; | ||
for(var i=0; i<10; i++){ | ||
(function(k){ | ||
emits.push(function(done){ s1.emit('record', k, done); }); | ||
})(i); | ||
} | ||
emits.push(function(){ | ||
finish(function(data){ | ||
expect(data.length).to.be.equal(10); | ||
for(var i=0; i<10; i++){ | ||
expect(data[i].tag).to.be.equal("debug.record"); | ||
expect(data[i].data).to.be.equal(i); | ||
} | ||
done(); | ||
}); | ||
}); | ||
async.series(emits); | ||
}); | ||
}, | ||
}); | ||
"test many async": function(){ | ||
var s = new sender.FluentSender('debug'); | ||
var order = -1; | ||
s.emit('test many async', 'test many' + (++order), function(){ | ||
assert.eql(order, 2); | ||
order--; | ||
}); | ||
s.emit('test many async', 'test many' + (++order), function(){ | ||
assert.eql(order, 1); | ||
order--; | ||
});; | ||
s.emit('test many async', 'test many' + (++order), function(){ | ||
assert.eql(order, 0); | ||
order--; | ||
s.end(); | ||
});; | ||
assert.eql(s._queue.length, 3); | ||
}, | ||
"test connection error": function(){ | ||
it('should raise error when connection fails', function(done){ | ||
var s = new sender.FluentSender('debug', { | ||
@@ -67,26 +36,50 @@ host: 'localhost', | ||
s.on('error', function(err){ | ||
assert.eql(err.code, 'ECONNREFUSED'); | ||
assert.eql(s._queue.length, 1); | ||
expect(err.code).to.be.equal('ECONNREFUSED'); | ||
done(); | ||
}); | ||
s.emit('test connection error', 'foobar'); | ||
assert.eql(s._queue.length, 1); | ||
}, | ||
}); | ||
"test queueing": function(){ | ||
var s = new sender.FluentSender('queuing', { | ||
host: 'localhost', | ||
port: 65535 | ||
it('should assure the sequence.', function(done){ | ||
fluentd(function(port, finish){ | ||
var s = new sender.FluentSender('debug', {port: port}); | ||
s.emit('1st record', '1st data'); | ||
s.emit('2nd record', '2nd data'); | ||
s.end('last record', 'last data', function(){ | ||
finish(function(data){ | ||
expect(data[0].tag).to.be.equal('debug.1st record'); | ||
expect(data[0].data).to.be.equal('1st data'); | ||
expect(data[1].tag).to.be.equal('debug.2nd record'); | ||
expect(data[1].data).to.be.equal('2nd data'); | ||
expect(data[2].tag).to.be.equal('debug.last record'); | ||
expect(data[2].data).to.be.equal('last data'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('should resume the connection automatically and flush the queue', function(done){ | ||
var s = new sender.FluentSender('debug'); | ||
s.emit('1st record', '1st data'); | ||
s.on('error', function(err){ | ||
assert.eql(err.code, 'ECONNREFUSED'); | ||
assert.eql(s._queue.length, 1); | ||
s.port = 24224; | ||
s.end('test queueing', 'done', function(){ | ||
assert.eql(s._queue.length, 0); | ||
expect(err.code).to.be.equal('ECONNREFUSED'); | ||
fluentd(function(port, finish){ | ||
s.port = port; | ||
s.emit('2nd record', '2nd data'); | ||
s.end('last record', 'last data', function(){ | ||
finish(function(data){ | ||
expect(data[0].tag).to.be.equal('debug.1st record'); | ||
expect(data[0].data).to.be.equal('1st data'); | ||
expect(data[1].tag).to.be.equal('debug.2nd record'); | ||
expect(data[1].data).to.be.equal('2nd data'); | ||
expect(data[2].tag).to.be.equal('debug.last record'); | ||
expect(data[2].data).to.be.equal('last data'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
assert.eql(s._queue.length, 2); | ||
}); | ||
s.emit('test queueing', 'pended'); | ||
} | ||
}; | ||
}); | ||
}); |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
43569
11
1076
51
3
2
3