forked from stelcheck/node-graylog2
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit tests and virtually full coverage
- Loading branch information
Ron Korving
committed
Jan 13, 2017
1 parent
d01904f
commit 552de88
Showing
15 changed files
with
680 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
|
||
node_modules | ||
npm-debug.log | ||
.nyc_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
* 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./lib/Graylog'); |
Oops, something went wrong.