Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/log4js-node/gelf
GELF Appender for log4js-node
https://github.com/log4js-node/gelf
gelf log4js-node
Last synced: about 2 months ago
JSON representation
GELF Appender for log4js-node
- Host: GitHub
- URL: https://github.com/log4js-node/gelf
- Owner: log4js-node
- License: apache-2.0
- Created: 2018-02-11T21:15:50.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-16T18:48:09.000Z (about 1 year ago)
- Last Synced: 2024-10-31T11:18:50.683Z (about 2 months ago)
- Topics: gelf, log4js-node
- Language: JavaScript
- Size: 1.1 MB
- Stars: 4
- Watchers: 4
- Forks: 10
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Log4JS - GELF appender
This is an optional appender for [log4js-node](https://log4js-node.github.io/log4js-node/).
```bash
npm install @log4js-node/gelf
```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).
## Configuration
* `type` - `@log4js-node/gelf`
* `host` - `string` (defaults to `localhost`) - the gelf server hostname
* `port` - `integer` (defaults to `12201`) - the port the gelf server is listening on
* `hostname` - `string` (defaults to `OS.hostname()`) - the hostname used to identify the origin of the log messages.
* `facility` - `string` (optional)
* `customFields` - `object` (optional) - fields to be added to each log message; custom fields must start with an underscore.## Example (default config)
```javascript
log4js.configure({
appenders: {
gelf: { type: '@log4js-node/gelf' }
},
categories: {
default: { appenders: ['gelf'], level: 'info' }
}
});
```
This will send log messages to a server at `localhost:12201`.## Example (custom fields in config)
```javascript
log4js.configure({
appenders: {
gelf: { type: '@log4js-node/gelf', host: 'gelf.server', customFields: { '_something': 'yep' } }
},
categories: {
default: { appenders: ['gelf'], level: 'info' }
}
});
```
This will result in all log messages having the custom field `_something` set to 'yep'.# Example (custom fields in log message)
```javascript
log4js.configure({
appenders: {
gelf: { type: '@log4js-node/gelf', customFields: { '_thing': 'isathing' } }
},
categories: {
default: { appenders: ['gelf'], level: 'info' }
}
});
const logger = log4js.getLogger();
logger.error({ GELF: true, _thing2: 'alsoathing' }, 'oh no, something went wrong');
```
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.