Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

restify-log-middleware

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restify-log-middleware

Basic log middleware to use with restify

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29
increased by2800%
Maintainers
1
Weekly downloads
 
Created
Source

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

...
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 string

As optional, you can set up your own elasticSearch configuration like this:

 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:

    "withstdout" : false

FAQs

Package last updated on 21 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc