Skip to content

staticmukesh/api-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

api-logger

npm version

This package helps you to log HTTP requests in Express Node.js application.

Installation

npm install api-logger

Usage

You can initialize the new instance of api-logger with or without passing existing winston logger. And, then can use the module as middleware in the application.

Using default winston logger

By default, only the Console logging is set on the default api-logger.

var app = require('express')();
var apiLogger = require('api-logger');

app.use(apiLogger());

app.get('/', function(req, res){
	res.send('Hello world');
});

app.listen(3000);

Instantiating your own Logger

If you would prefer to manage the loggers, you can to instantiate them yourself and can pass to api-logger:

var app = require('express')();
var winston = require('winston');
var apiLogger = require('api-logger');

var customLogger = new (winston.Logger)({
    transports: [
      new (winston.transports.Console)(),
      new (winston.transports.File)({ filename: 'somefile.log' })
    ]
  });

app.use(apiLogger({
	logger : customLogger
}));

app.get('/', function(req, res){
	res.send('Hello world');
});

app.listen(3000);

Sample Output

info: 10/11/2016, 3:00:23 PM GET / 200
info: 10/11/2016, 3:00:23 PM GET /favicon.ico 404
info: 10/11/2016, 3:00:35 PM GET /app 404	

About

Logger for Api request in Express Node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published