Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/s3pweb/s3pweb-logger
A simple lib to log message using bunyan to console, file and logstash.
https://github.com/s3pweb/s3pweb-logger
bunyan console file logger logging logstash nodejs
Last synced: 3 months ago
JSON representation
A simple lib to log message using bunyan to console, file and logstash.
- Host: GitHub
- URL: https://github.com/s3pweb/s3pweb-logger
- Owner: s3pweb
- License: isc
- Created: 2018-11-12T13:18:58.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-29T21:28:49.000Z (about 1 year ago)
- Last Synced: 2024-11-13T14:13:22.120Z (3 months ago)
- Topics: bunyan, console, file, logger, logging, logstash, nodejs
- Language: JavaScript
- Homepage:
- Size: 1.58 MB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![npm (scoped)](https://img.shields.io/npm/v/@s3pweb/s3pweb-logger)](https://www.npmjs.com/package/@s3pweb/s3pweb-logger)
This is a simple lib to log messages built on top of [bunyan](https://github.com/trentm/node-bunyan).
This lib can send logs to the console, to a file or to a logstash instance.# Installation
npm install @s3pweb/s3pweb-logger
# Configuration
The constructor expect a config object following this format:
```json
{
"name": "your-application-name",
"logger": {
"source": false,
"console": {
"enable": true,
"level": "debug"
},
"file": {
"enable": true,
"level": "info",
"dir": "./logs",
"addHostnameToPath": true
},
"server": {
"enable": true,
"level": "trace",
"url": "0.0.0.0",
"port": "9998",
"type": "elk"
},
"ringBuffer": {
"enable": true,
"size": 5
}
}
}
```# Example
```js
const Logger = require('@s3pweb/s3pweb-logger')const log = new Logger(config).get()
const child = log.child({ child: 'childName' })log.info('one message from log')
child.info('one message from child')
```# Tests
Set the name of your environment with NODE_ENV=xxxx before node
```bash
NODE_ENV=test node example/example.js
```# Bonus
To start a ELK stack on docker :
```bash
chmod +x example/startElk.sh./example/startElk.sh
```Or with docker compose :
```bash
docker-compose -f example/docker-stack.yaml up -d
```Open your favorite browser : http://localhost:5601
Create an index with just * (replace logstash-* by *)