Comparing version 0.1.3 to 0.2.0
@@ -5,3 +5,4 @@ var zlib = require('zlib'), | ||
util = require('util'), | ||
EventEmitter = require('events').EventEmitter; | ||
EventEmitter = require('events').EventEmitter, | ||
assert = require('assert'); | ||
@@ -22,2 +23,6 @@ /** | ||
this.facility = config.facility || 'Node.js'; | ||
this.deflate = config.deflate || 'optimal'; | ||
assert( | ||
this.deflate === 'optimal' || this.deflate === 'always' || this.deflate === 'never', | ||
'deflate must be one of "optimal", "always", or "never". was "' + this.deflate + '"'); | ||
@@ -119,3 +124,3 @@ this._unsentMessages = 0; | ||
message = { | ||
version : '1.0', | ||
version : '1.1', | ||
timestamp : (timestamp || new Date()).getTime() / 1000, | ||
@@ -170,3 +175,3 @@ host : this.hostname, | ||
zlib.deflate(payload, function (err, buffer) { | ||
function sendPayload(err, buffer) { | ||
if (err) { | ||
@@ -242,3 +247,9 @@ that._unsentMessages -= 1; | ||
}); | ||
}); | ||
} | ||
if (this.deflate === 'never' || (this.deflate === 'optimal' && payload.length <= this._bufferSize)) { | ||
sendPayload(null, payload); | ||
} else { | ||
zlib.deflate(payload, sendPayload); | ||
} | ||
}; | ||
@@ -259,3 +270,3 @@ | ||
client.send(chunk, 0, chunk.length, server.port, server.host, function (err/*, bytes */) { | ||
client.send(chunk, 0, chunk.length, server.port, server.host, function (err) { | ||
that._unsentChunks -= 1; | ||
@@ -300,4 +311,2 @@ | ||
var that = this; | ||
this._onClose = function () { | ||
@@ -310,4 +319,10 @@ that.destroy(); | ||
}; | ||
if (this._unsentChunks === 0 && this._unsentMessages === 0) { | ||
process.nextTick(function () { | ||
that._onClose(); | ||
}); | ||
} | ||
}; | ||
exports.graylog = graylog; |
{ | ||
"name": "graylog2", | ||
"description": "Graylog2 client library for node.js", | ||
"homepage": "http://github.com/Wizcorp/node-graylog2", | ||
"bugs": { | ||
"url": "http://github.com/Wizcorp/node-graylog2/issues" | ||
"name": "graylog2", | ||
"description": "Graylog2 client library for node.js", | ||
"version": "0.2.0", | ||
"author": "Marc Trudel-Belise", | ||
"bugs": { | ||
"url": "http://github.com/Wizcorp/node-graylog2/issues" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Egor Egorov", | ||
"email": "me@egorfine.com" | ||
}, | ||
"version": "0.1.3", | ||
"author": "Marc Trudel-Belise", | ||
"engines": { | ||
"node": ">=0.6.11" | ||
}, | ||
"devDependencies": { | ||
"jshint": "0.9.1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/Wizcorp/node-graylog2.git" | ||
}, | ||
"scripts": { | ||
"test": "node ./test" | ||
}, | ||
"main": "./graylog.js" | ||
{ | ||
"name": "Sean Lang", | ||
"email": "slang800@gmail.com" | ||
} | ||
], | ||
"devDependencies": { | ||
"jshint": "0.9.1" | ||
}, | ||
"engines": { | ||
"node": ">=0.6.11" | ||
}, | ||
"homepage": "http://github.com/Wizcorp/node-graylog2", | ||
"license": "MIT", | ||
"main": "./graylog.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/Wizcorp/node-graylog2.git" | ||
}, | ||
"scripts": { | ||
"test": "node ./test" | ||
} | ||
} |
# node-graylog2 | ||
[![NPM version](http://img.shields.io/npm/v/graylog2.svg?style=flat-square)](https://www.npmjs.org/package/graylog2) [![NPM license](http://img.shields.io/npm/l/graylog2.svg?style=flat-square)](https://www.npmjs.org/package/graylog2) | ||
@@ -32,4 +33,4 @@ Graylog2 client library for Node.js, based on node-graylog. This | ||
servers: [ | ||
{ 'host': 127.0.0.1, port: 12201 }, | ||
{ 'host': 127.0.0.2, port: 12201 } | ||
{ 'host': '127.0.0.1', port: 12201 }, | ||
{ 'host': '127.0.0.2', port: 12201 } | ||
], | ||
@@ -47,2 +48,3 @@ hostname: 'server.name', // the name of this host | ||
}); | ||
``` | ||
@@ -59,5 +61,3 @@ | ||
```javascript | ||
logger.log("What we've got here is...failure to communicate", "Some men you just | ||
can't reach. So you get what we had here last week, which is the way he wants | ||
it... well, he gets it. I don't like it any more than you men."); | ||
logger.log("What we've got here is...failure to communicate", "Some men you just can't reach. So you get what we had here last week, which is the way he wants it... well, he gets it. I don't like it any more than you men."); | ||
``` | ||
@@ -74,5 +74,3 @@ | ||
```javascript | ||
logger.log("What we've got here is...failure to communicate", "Some men you just | ||
can't reach. So you get what we had here last week, which is the way he wants | ||
it... well, he gets it. I don't like it any more than you men.", | ||
logger.log("What we've got here is...failure to communicate", "Some men you just can't reach. So you get what we had here last week, which is the way he wants it... well, he gets it. I don't like it any more than you men.", | ||
{ | ||
@@ -84,2 +82,10 @@ cool: "beans" | ||
Flush all log messages and close down: | ||
```javascript | ||
logger.close(function(){ | ||
console.log('All done - cookie now?'); | ||
process.exit(); | ||
}); | ||
``` | ||
## Example | ||
@@ -96,10 +102,1 @@ | ||
npm install graylog2 | ||
## License | ||
See LICENSE file. Basically, it's a kind of "do-whatever-you-want-for-free" license. | ||
## Original author | ||
Egor Egorov <me@egorfine.com> | ||
30
test.js
var graylog = require('./graylog'), | ||
fs = require('fs'), | ||
assert = require('assert'), | ||
file, | ||
@@ -52,2 +53,15 @@ data, | ||
console.log('---------------------------------------------'); | ||
console.log('Sending without deflate'); | ||
console.log('---------------------------------------------'); | ||
client.deflate = 'never'; | ||
for (var i = 4; i <= 64; i *= 2) { | ||
file = './data/' + i + '.dat'; | ||
data = fs.readFileSync(file); | ||
console.log('sending', file); | ||
client.critical('Test 4 ' + file, data.toString(), {datafile: i + '.dat'}); | ||
} | ||
client.deflate = 'optimal'; | ||
console.log(''); | ||
client.close(function () { | ||
@@ -57,1 +71,17 @@ console.log('Insertion complete. Please check', 'http://' + servers[0].host + ':3000', 'and verify that insertion was successfull'); | ||
}); | ||
console.log('---------------------------------------------'); | ||
console.log('Checking deflate assertion'); | ||
console.log('---------------------------------------------'); | ||
try { | ||
new graylog.graylog({ | ||
servers: servers, | ||
facility: 'Test logger / Node.JS Test Script', | ||
deflate: 'not an option' | ||
}); | ||
throw new Error('should not get here') | ||
} catch (err) { | ||
assert( | ||
err.message === 'deflate must be one of "optimal", "always", or "never". was "not an option"', | ||
'assertion msg was wrong: ' + err.message); | ||
} |
Sorry, the diff of this file is not supported yet
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
348668
325
97