1.0.1 • Published 5 years ago
s3pweb-logger v1.0.1
This is a simple lib to log message
Installation
npm install s3pweb-logger
Config
Configurations are stored in configuration files within your application, and can be overridden and extended by environment variables, command line parameters, or external sources. See : http://lorenwest.github.io/node-config/
Create a config folder
Create a file(s) with the name of your environment(s) like test.json
Paste this configuration template :
{
"name": "your-application-name",
"logger": {
"source": false,
"console": {
"enable": true,
"level": "debug"
},
"file": {
"enable": true,
"level": "info",
"dir": "./logs"
},
"server": {
"enable": true,
"level": "trace",
"url": "0.0.0.0",
"port": "9998",
"type": "elk"
},
"ringBuffer": {
"enable": true,
"size": 50
}
}
}
- Adapt values with your expectations
Example :
const log = require('s3pweb-logger').logger
const { logger } = require('s3pweb-logger')
const child = log.child({ child: 'childName' })
log.info('one message from log')
logger.info('one message from logger')
child.info('one message from child')
Run example :
Pass the name of your environnement with NODE_ENV=xxxx before node
NODE_ENV=test node example/example.js
Bonus :
To start a ELK stack on docker :
chmod +x example/startElk.sh
./example/startElk.sh
Or with docker compose :
docker-compose -f example/docker-stack.yaml up -d
Open your favorite browser : http://localhost:5601
Create an index with just (replace logstash- by *)