This package helps you to log HTTP requests in Express Node.js application.
npm install api-logger
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.
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);
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);
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