https://github.com/clems71/koa-request-logger
Koa v2 request logger - MongoDB backend included
https://github.com/clems71/koa-request-logger
koa2 logging mongodb
Last synced: 2 months ago
JSON representation
Koa v2 request logger - MongoDB backend included
- Host: GitHub
- URL: https://github.com/clems71/koa-request-logger
- Owner: clems71
- Created: 2017-05-17T07:23:41.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-19T13:33:08.000Z (about 9 years ago)
- Last Synced: 2025-06-18T08:49:45.259Z (12 months ago)
- Topics: koa2, logging, mongodb
- Language: JavaScript
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# koa-request-logger
[](https://github.com/prettier/prettier)
This is a Koa v2 middleware that logs all incoming requests. The library includes multiple logging backends:
- MongoDB : `require('koa-request-logger/backends/mongodb')`
- Console : `require('koa-request-logger/backends/console')`
The default log packet (the data that is logged to backend) includes the following fields:
- `path` : path without query string
- `method` : `'GET'`, `'POST'`, ...
- `origin` : origin of the request (can be an empty string)
- `userAgent` : user agent header
- `ip` : raw IP address (can be IPv6)
- `responseTime` : response time in ms
- `status` : integer status code
- `timestamp` : JavaScript timestamp (UNIX timestamp in ms)
If `geoTracking` is set to `true` in `requestLogger` options (the default), the log packet will also include a country field
- `country` : country code in ISO Alpha-2 representation
Please note that a backend might ignore some of these fields when storing logs.
## Console backend example
```js
const Koa = require('koa');
const requestLogger = require('koa-request-logger');
const consoleBackend = require('koa-request-logger/backends/console');
const app = new Koa();
// logger setup
app.use(requestLogger(consoleBackend()));
// all the following middleware go here
// ....
// ....
// ....
app.listen(8080);
console.log('listening on port 8080');
```