Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #42 from wpreul/master

Fixing memory issue when logs get backed up
  • Loading branch information...
commit 4f86b73ecc9f085f40521dd05887cc5d86f2427b 2 parents ba2e6ad + 412c472
Wyatt Preul geek authored
Showing with 117 additions and 6 deletions.
  1. +6 −5 lib/monitor.js
  2. +1 −1  package.json
  3. +110 −0 test/monitor.js
11 lib/monitor.js
View
@@ -250,16 +250,17 @@ internals.Monitor.prototype._broadcastFile = function () {
}
if (this._isProcessingLogs) {
- return setImmediate(this._broadcastFile.bind(this));
+ self._doBroadcast = true;
+ return;
}
this._isProcessingLogs = true;
- var totalLogged = 0;
var logged = function () {
- totalLogged++;
- if (totalLogged === keysLength) {
- self._isProcessingLogs = false;
+ self._isProcessingLogs = false;
+ if (self._doBroadcast) {
+ self._doBroadcast = false;
+ self._broadcastFile();
}
};
2  package.json
View
@@ -1,7 +1,7 @@
{
"name": "good",
"description": "Server and process monitoring plugin",
- "version": "0.5.4",
+ "version": "0.5.5",
"author": "Van Nguyen <the.gol.effect@gmail.com>",
"contributors":[
"Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)",
110 test/monitor.js
View
@@ -620,6 +620,116 @@ describe('Monitor', function () {
});
});
+ it('handles large amounts of log events', function (done) {
+
+ var folderPath = Path.join(__dirname, 'logs');
+
+ var options = {
+ subscribers: {}
+ };
+
+ var dest = Path.join(folderPath, 'mylog7.log');
+
+ options.subscribers[dest] = { events: ['log'] };
+
+ makePack(function (pack, server) {
+
+ var monitor = new Monitor(pack, options);
+
+ expect(monitor._eventQueues.log).to.exist;
+
+ server.log('ERROR', 'included in output');
+ server.log('ERROR', 'here is one more error');
+ server.log('ERROR', 'here is one more error');
+ server.log('ERROR', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+
+ setTimeout(function () {
+
+ server.log('ERROR', 'another error');
+ server.log('ERROR', 'another error');
+ server.log('ERROR', 'another error');
+ server.log('ERROR', 'another error');
+
+ setTimeout(function () {
+
+ var file = Fs.readFileSync(dest + '.001');
+ var formatted = file.toString().split('\n');
+
+ var result = JSON.parse('[' + formatted + ']');
+ expect(result[0].data).to.equal('included in output');
+ expect(result.length).to.equal(17);
+
+ done();
+ }, 10);
+ }, 10);
+ });
+ });
+
+ it('handles large amounts of log events with multiple file subscribers', function (done) {
+
+ var folderPath = Path.join(__dirname, 'logs');
+
+ var options = {
+ subscribers: {}
+ };
+
+ var dest1 = Path.join(folderPath, 'mylog8.log');
+ var dest2 = Path.join(folderPath, 'mylog9.log');
+
+ options.subscribers[dest1] = { events: ['log'] };
+ options.subscribers[dest2] = { events: ['log'] };
+
+ makePack(function (pack, server) {
+
+ var monitor = new Monitor(pack, options);
+
+ expect(monitor._eventQueues.log).to.exist;
+
+ server.log('ERROR', 'included in output');
+ server.log('ERROR', 'here is one more error');
+ server.log('ERROR', 'here is one more error');
+ server.log('ERROR', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+ server.log('MYTAG', 'here is one more error');
+
+ setTimeout(function () {
+
+ server.log('ERROR', 'another error');
+ server.log('ERROR', 'another error');
+ server.log('ERROR', 'another error');
+ server.log('ERROR', 'another error');
+
+ setTimeout(function () {
+
+ var file = Fs.readFileSync(dest1 + '.001');
+ var formatted = file.toString().split('\n');
+
+ var result = JSON.parse('[' + formatted + ']');
+ expect(result[0].data).to.equal('included in output');
+ expect(result.length).to.equal(17);
+
+ done();
+ }, 10);
+ }, 10);
+ });
+ });
+
it('doesn\'t overwrite log file with several initial log events', function (done) {
var folderPath = Path.join(__dirname, 'logs');
Please sign in to comment.
Something went wrong with that request. Please try again.