Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/makinhs/restify-log-middleware
Basic log middleware to use with restify
https://github.com/makinhs/restify-log-middleware
Last synced: about 2 months ago
JSON representation
Basic log middleware to use with restify
- Host: GitHub
- URL: https://github.com/makinhs/restify-log-middleware
- Owner: makinhs
- Created: 2016-11-21T16:51:10.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-11-21T16:54:17.000Z (about 8 years ago)
- Last Synced: 2024-10-13T13:37:46.332Z (3 months ago)
- Language: JavaScript
- Size: 1000 Bytes
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# restify-log-middleware
This is a small middleware to use with restify to generate log inside req's using bunyan and elasticsearch modules.
## First thing
```
npm install --save restify-log-middleware
```## Full usage
```javascript
...
var logFactory = require('restify-log-middleware');var options = {
"elasticSearchConfig": {
"indexPattern": "[logstash-]YYYY.MM.DD",
"type": "logs",
"host": "elasticSearchIp:port"
},
"logLevel": 10,
"logName": "myLogName",
"withstdout" : true
};...
//in your routes config
...
var logMiddleware = logFactory.createLogMiddleware('myModuleName', options);
server.post('/some-endpoint', [
logMiddleware,
myController.post
]);
...
//or
...
server.post('/some-endpoint', [
logFactory.createLogMiddleware('myModuleName', options),
myController.post
]);
...
//or to use with before all routes
server.use(logFactory.createLogMiddleware('myModuleName', options));//it will generate an req.log object. You can use it like this:
myController(req, res){
var log = req.log
log = log.child(module: 'controller-module'});
log.trace('Controller started!');
...
log.info('Some info');
...
log.warn('Some warning');
...
}```
## OPTIONS
You need to use at least:
- logLevel //as number (try 10)
- logName //as stringAs optional, you can set up your own elasticSearch configuration like this:
```javascript
elasticSearchConfig: {
"indexPattern": "[logstash-]YYYY.MM.DD",
"type": "logs",
"host": "elasticSearchIp:port"
}
```If you don't need to use `process.stdout`, just turn off this option:
```javascript
"withstdout" : false
```