-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complete re-implementation #22
base: master
Are you sure you want to change the base?
Changes from all commits
9ceae36
304d5d1
9e0f1c1
9bf0cfc
d01904f
552de88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
|
||
node_modules | ||
npm-debug.log | ||
.nyc_output |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
node-graylog (C) 2011 Egor Egorov <[email protected]> | ||
Copyright (c) 2017 Wizcorp | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,9 @@ install: | |
test: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happens because you have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah lol, nice catch. I always just run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could remove the Makefile tbh. |
||
npm test | ||
|
||
bench: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would suggest to allow the destination server as an argument (so to allow testing against an arbitrary Graylog/Logstash server). |
||
node ./bench.js | ||
|
||
# target: lint, Lints every JavaScript file in the project that are staged to be comitted. | ||
lint: | ||
./scripts/lint-staged.sh | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,105 @@ | ||
# 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) | ||
# graylog2 | ||
|
||
Graylog2 client library for Node.js, based on node-graylog. This | ||
has been heavily modified to the point where there is not much left | ||
of the original; however, this library should still be compatible | ||
with the old one, except for configuration and the GLOBAL function setup | ||
(some optional arguments in logging calls are not supported; they will be | ||
logged as additional data). | ||
[![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) | ||
|
||
** New: ** Chunked [GELF](https://github.com/Graylog2/graylog2-docs/wiki/GELF) | ||
is now supported. | ||
Graylog2 client library for Node.js | ||
|
||
## Synopsis | ||
## Installation | ||
|
||
```sh | ||
npm install graylog2 --save | ||
``` | ||
|
||
## What is Graylog? | ||
|
||
Graylog is popular logging software. You can get it at http://www.graylog2.org. Incidentally, since this package | ||
uses Graylog's [GELF](http://docs.graylog.org/en/latest/pages/gelf.html) protocol, you can also use this with other | ||
logging software that has GELF support. | ||
|
||
## Usage | ||
|
||
### Available functions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Available events should also be documented. |
||
|
||
* graylog.emergency | ||
* graylog.alert | ||
* graylog.critical | ||
* graylog.error | ||
* graylog.warning | ||
* graylog.notice | ||
* graylog.info | ||
* graylog.debug | ||
* graylog.emergency(short, full, fields, timestamp) | ||
* graylog.alert(short, full, fields, timestamp) | ||
* graylog.critical(short, full, fields, timestamp) | ||
* graylog.error(short, full, fields, timestamp) | ||
* graylog.warning(short, full, fields, timestamp) | ||
* graylog.notice(short, full, fields, timestamp) | ||
* graylog.info(short, full, fields, timestamp) | ||
* graylog.debug(short, full, fields, timestamp) | ||
|
||
Arguments: | ||
|
||
- short (string): A short message to log. | ||
- full (string, optional): Additional details. | ||
- fields (object, optional): An object of key/value pairs to help with filtering. | ||
- timestamp (integer, optional): A custom timestamp (milliseconds). | ||
|
||
### Code snippets | ||
|
||
```javascript | ||
var graylog2 = require("graylog2"); | ||
var logger = new graylog2.graylog({ | ||
```js | ||
var Graylog = require('graylog2'); | ||
var logger = new Graylog({ | ||
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 } | ||
], | ||
hostname: 'server.name', // the name of this host | ||
// (optional, default: os.hostname()) | ||
facility: 'Node.js', // the facility for these log messages | ||
// (optional, default: "Node.js") | ||
bufferSize: 1350 // max UDP packet size, should never exceed the | ||
// MTU of your system (optional, default: 1400) | ||
hostname: 'server.name', // the name of this host (optional, default: os.hostname()) | ||
facility: 'Node.js', // the facility for these log messages (optional, default: "Node.js") | ||
bufferSize: 1350 // max UDP packet size, should not exceed the MTU of your network (optional, default: 1400) | ||
}); | ||
|
||
logger.on('error', function (error) { | ||
console.error('Error while trying to write to graylog2:', error); | ||
console.error('Error while trying to write to Graylog2:', error); | ||
}); | ||
|
||
logger.on('warning', function (error) { | ||
console.error('Non-fatal error while trying to write to Graylog2:', error); | ||
}); | ||
``` | ||
|
||
Short message: | ||
|
||
```javascript | ||
logger.log("What we've got here is...failure to communicate"); | ||
```js | ||
logger.debug("What we've got here is...failure to communicate"); | ||
``` | ||
|
||
Long message: | ||
|
||
```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."); | ||
```js | ||
var short = "What we've got here is...failure to communicate"; | ||
var long = "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.debug(short, long); | ||
``` | ||
|
||
Short with additional data: | ||
|
||
```javascript | ||
logger.log("What we've got here is...failure to communicate", { cool: 'beans' }); | ||
```js | ||
logger.debug("What we've got here is...failure to communicate", { cool: 'beans' }); | ||
``` | ||
|
||
Long with additional data: | ||
|
||
```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.", | ||
{ | ||
cool: "beans" | ||
} | ||
); | ||
``` | ||
```js | ||
var short = "What we've got here is...failure to communicate"; | ||
var long = "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."; | ||
|
||
Flush all log messages and close down: | ||
```javascript | ||
logger.close(function(){ | ||
console.log('All done - cookie now?'); | ||
process.exit(); | ||
}); | ||
logger.debug(short, long, { cool: 'beans' }); | ||
``` | ||
|
||
## Example | ||
|
||
See `test.js`. | ||
Send all pending log messages and close the socket: | ||
|
||
## What is graylog2 after all? | ||
|
||
It's a miracle. Get it at http://www.graylog2.org/ | ||
```js | ||
logger.close(function () { | ||
console.log('All done!'); | ||
}); | ||
``` | ||
|
||
## Installation | ||
### More examples | ||
|
||
npm install graylog2 | ||
See the files in the `test` folder. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
var Graylog = require('.').graylog; | ||
var fs = require('fs'); | ||
var client; | ||
var servers = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would suggest to make this accept CLI arguments, so that you can test against an existing Graylog setup |
||
{ host: '127.0.0.1', port: 12201 } | ||
]; | ||
|
||
function createClient() { | ||
client = new Graylog({ | ||
servers: servers, | ||
facility: 'node-graylog benchmark' | ||
}); | ||
|
||
client.on('error', function (error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is required - wouldn't on('error') trigger a throw anyhow? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. |
||
throw error; | ||
}); | ||
} | ||
|
||
|
||
var i = 0; | ||
var count = 20000; | ||
var small = 'h'.repeat(1000); | ||
var big = 'h'.repeat(25000); | ||
var bigRandom = require('crypto').randomBytes(20000).toString('base64'); | ||
|
||
console.log(''); | ||
|
||
function log(str, label, i, n, cb) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are str, i and n? Variables could use a bit of renaming here. |
||
if (i === 0) { | ||
createClient(); | ||
console.time(label + ' x' + n); | ||
|
||
client.on('drain', function () { | ||
console.timeEnd(label + ' x' + n); | ||
|
||
console.log('Sent:', client.sent, '- Compressed:', client.compressed); | ||
console.log(''); | ||
|
||
if (client.sent !== n) { | ||
throw new Error('Should have sent: ' + n); | ||
} | ||
|
||
cb(); | ||
}); | ||
} | ||
|
||
if (i < n) { | ||
client.log('test', str); | ||
process.nextTick(log, str, label, i + 1, n, cb); | ||
} | ||
} | ||
|
||
function testSmall(cb) { | ||
log(small, 'small', 0, 10000, cb); | ||
} | ||
|
||
function testBig(cb) { | ||
log(big, 'big', 0, 5000, cb); | ||
} | ||
|
||
function testBigAndRandom(cb) { | ||
log(bigRandom, 'bigAndRandom', 0, 2000, cb); | ||
} | ||
|
||
function end() { | ||
console.log('Complete.'); | ||
console.log('Please check your logging service and verify that insertion was successful.'); | ||
console.log(''); | ||
} | ||
|
||
testSmall(function () { | ||
testBig(function () { | ||
testBigAndRandom(end); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed this, since there's literally nothing left of the original implementation.