8000 docs(gelf): gelf docs added · commontime/log4js-node@7993a3f · GitHub
[go: up one dir, main page]

Skip to content

Commit 7993a3f

Browse files
author
Gareth Jones
committed
docs(gelf): gelf docs added
1 parent 183992a commit 7993a3f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

docs/gelf.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# GELF appender
2+
3+
The GELF appender supports sending log messages over UDP to a [GELF](http://docs.graylog.org/en/2.2/pages/gelf.html) compatible server such as [Graylog](https://www.graylog.org). It uses node's core UDP support and does not require any other dependencies. If you use this appender, remember to call `log4js.shutdown` when your application terminates, so that all messages will have been sent to the server and the UDP socket can be closed. The appender supports passing custom fields to the server in both the config, and in individual log messages (see examples below).
4+
5+
## Configuration
6+
7+
* `type` - `gelf`
8+
* `host` - `string` (defaults to `localhost`) - the gelf server hostname
9+
* `port` - `integer` (defaults to `12201`) - the port the gelf server is listening on
10+
* `hostname` - `string` (defaults to `OS.hostname()`) - the hostname used to identify the origin of the log messages.
11+
* `facility` - `string` (optional)
12+
* `customFields` - `object` (optional) - fields to be added to each log message; custom fields must start with an underscore.
13+
14+
## Example (default config)
15+
```javascript
16+
log4js.configure({
17+
appenders: {
18+
gelf: { type: 'gelf' }
19+
},
20+
categories: {
21+
default: { appenders: ['gelf'], level: 'info' }
22+
}
23+
});
24+
```
25+
This will send log messages to a server at `localhost:12201`.
26+
27+
## Example (custom fields in config)
28+
```javascript
29+
log4js.configure({
30+
appenders: {
31+
gelf: { type: 'gelf', host: 'gelf.server', customFields: { '_something': 'yep' } }
32+
},
33+
categories: {
34+
default: { appenders: ['gelf'], level: 'info' }
35+
}
36+
});
37+
```
38+
This will result in all log messages having the custom field `_something` set to 'yep'.
39+
40+
# Example (custom fields in log message)
41+
```javascript
42+
log4js.configure({
43+
appenders: {
44+
gelf: { type: 'gelf', customFields: { '_thing': 'isathing' } }
45+
},
46+
categories: {
47+
default: { appenders: ['gelf'], level: 'info' }
48+
}
49+
});
50+
const logger = log4js.getLogger();
51+
logger.error({ GELF: true, _thing2: 'alsoathing' }, 'oh no, something went wrong');
52+
```
53+
This will result in a log message with the custom fields `_thing` and `_thing2`. Note that log message custom fields will override config custom fields.

0 commit comments

Comments
 (0)
0