https://github.com/dial-once/node-logtify-logstash
Logstash chain link for logtify logger
https://github.com/dial-once/node-logtify-logstash
Last synced: about 2 months ago
JSON representation
Logstash chain link for logtify logger
- Host: GitHub
- URL: https://github.com/dial-once/node-logtify-logstash
- Owner: dial-once
- License: mit
- Created: 2017-05-23T15:13:09.000Z (almost 8 years ago)
- Default Branch: develop
- Last Pushed: 2018-11-22T10:36:39.000Z (over 6 years ago)
- Last Synced: 2025-03-12T10:05:33.165Z (2 months ago)
- Language: JavaScript
- Size: 45.9 KB
- Stars: 2
- Watchers: 8
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-logtify-logstash
[](https://circleci.com/gh/dial-once/node-logtify-logstash)
[](http://sonar.dialonce.net/dashboard?id=node-logtify-logstash)
[](http://sonar.dialonce.net/dashboard?id=node-logtify-logstash)
[](http://sonar.dialonce.net/dashboard?id=node-logtify-logstash)
[](http://proxy.dialonce.net/sonar/api/badges/measure?key=node-logtify-logstash&metric=coverage)
[](http://sonar.dialonce.net/dashboard?id=node-logtify-logstash)
[](http://sonar.dialonce.net/dashboard?id=node-logtify-logstash)Logstash subscriber for logtify logger
## Installation
```
npm i -S logtify-logstash
```## Usage
Used with[logtify](https://github.com/dial-once/node-logtify) module.```js
require('logtify-logstash')({ LOGSTASH_PORT: 3000, LOGSTASH_HOST: 'app.on.thenet' });
const { stream, logger } = require('logtify')();
logger.log('error', new Error('Test error'));
logger.info('Hello world!');
```The subscriber will make sure that a message will be sent to Logstash if:
* ``message.level >= 'MIN_LOG_LEVEL_LOGSTASH' || 'MIN_LOG_LEVEL'``
* ``process.env.LOGSTASH_LOGGING !== 'true' || settings.LOGSTASH_LOGGING !== true``## Usage within child_process.fork()
Since within child_process we need to pipe socket's tcp channel, the best way to manage logging is to transfer them via ipc channel:```js
const cp = require('child_process');
const { stream } = require('logtify')();// creating a forked process
const process = cp.fork('/some.js', [], {
env: { FORKED: true }
});process.on('message', data => {
// passing message from child to logger
stream.log(data.level, data.message, ...data.meta)
});```
```js
// some.jsconst { logger, stream } = require('logtify')();
// if from forked process
if (process.env.FORKED) {
stream.log = (level, message, ...meta) => {
// if ipc channel was not closed
if (process.channel) {
process.send({
level,
message,
meta: meta || []
});
}
};
}logger.info('Hello world', { from: 'forked_process' });
```**Settings**:
Module can be configured by both env variables or config object. However, env variables have a higher priority.
```js
{
LOGSTASH_HOST: 'app.on.thenet',
LOGSTASH_PORT: 3000,
LOGSTASH_LOGGING: true|false, // true by default
MIN_LOG_LEVEL_LOGSTASH: 'silly|verbose|info|warn|error',
LOG_TIMESTAMP = 'true'
LOG_ENVIRONMENT = 'true'
LOG_LEVEL = 'true'
LOG_REQID = 'true' // only included when provided with metadata
LOG_CALLER_PREFIX = 'true' // additional prefix with info about caller module/project/function
JSONIFY = 'true' // converts metadata to json
}
```