https://github.com/staticmukesh/api-logger
Logger for Api request in Express Node.js
https://github.com/staticmukesh/api-logger
Last synced: 13 days ago
JSON representation
Logger for Api request in Express Node.js
- Host: GitHub
- URL: https://github.com/staticmukesh/api-logger
- Owner: staticmukesh
- License: mit
- Created: 2016-09-15T13:07:50.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-20T16:12:35.000Z (over 9 years ago)
- Last Synced: 2025-12-26T13:38:15.522Z (5 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
api-logger
=========
[](https://badge.fury.io/js/api-logger)
This package helps you to log HTTP requests in Express Node.js application.
Installation
------------
```sh
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.
```javascript
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:
```javascript
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
```javascript
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
```