0.17.0 • Published 2 years ago
@yunnysunny/request-logging v0.17.0
request-logging
Print the express request log to console or save it to external data source by providing onReqFinished callback function.
Installation
npm install @yunnysunny/request-logging --save
Usage
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const requestLog = require('@yunnysunny/request-logging').default;
const app = express();
app.enable('trust proxy');
// view engine setup
app.set('port', port);
app.use(requestLog());
app.use(bodyParser.json({limit: '1mb'}));
app.use(bodyParser.urlencoded({
extended: false,
limit: '1mb'
}));API
See api document.
Fields
If you want to save request logging to mongodb, this is the fields description, which you will used to create a mongoose schema:
| name | type | description |
|---|---|---|
| req_id | String | The unique id for one log record, can been changed by given genId function. |
| domain | String | The domain of current server. |
| original_url | String | The original url contains query string. |
| path | String | The request path doesn't contain query string. |
| router | String | The request router for express. |
| user_agent | String | The user agent. |
| custom_headers | Object | The specific headers you wanna save. |
| custom_envs | Object | The specific env variables you wanna save. |
| method | String | The http request method. |
| ip | String | The client's ip. |
| server_ip | String | The server's ip. |
| server_host | String | The server's hostname. |
| duration | Number | The millisecond the request costed. |
| pid | Number | The server's process id. |
| req_seq | Number | The inner request number, auto increased when new request come. |
| content_length_req | Number | The content-length of the request headers. |
| content_length | Number | The content-length of the response headers. |
| status_code | Number | The status code of current HTTP response. |
| res_code | Number | The inner response code, which will been get from the response header of res-code or res.locals._res_code. |
| res_data | String/any | The response data, which will been get from res.locals._res_data. |
| req_time | Number | The timestamp of begin time of current request occured. |
| req_time_string | String | The time of begin time, formatted in ISO 8601 Extended Format. |
| req_data | String/any | The request data, which would form query string or form data. |
| referer | String | The HTTP referer header. |
| session | Object | The session of current request. |
| aborted | Boolean | Whether the request has aborted. |
We suggest you use such mongoose schema, which is compatible when the fields is changed:
const {Schema} = require('mongoose');
const requestLogSchema = new Schema({
req_time: Date
},{
timestamps: {
createdAt: 'created_at',
updatedAt : 'updated_at'
},
strict: false
});
module.exports = requestLogSchema;Breaking changes
0.17.x
req_idis now an unique string, the originalreq_idhas renamed toreq-seq.hostis renamed toserver_ip.hostnameis renamed todomain.
0.16.x
- Remove
kafkaSchedulemongooseModelalarmoption, please useonReqFinishedinstead. - The default
dataFormatfunction will use JSON.stringify to return string, since it's safe for elasticsearch. If you want to return with you own format, please pass thedataFormatparameter yourself.
License
0.17.0
2 years ago
0.16.0
2 years ago
0.16.1
2 years ago
0.16.2
2 years ago
0.13.0
4 years ago
0.14.0
4 years ago
0.15.0
4 years ago
0.15.1
4 years ago
0.12.1
6 years ago
0.12.0
6 years ago
0.11.1
6 years ago
0.11.0
6 years ago
0.10.0
6 years ago
0.9.0
6 years ago
0.8.0
7 years ago
0.7.0
7 years ago
0.6.0
7 years ago
0.5.2
7 years ago
0.5.1
7 years ago
0.5.0
7 years ago
0.4.0
8 years ago
0.3.0
8 years ago
0.2.0
8 years ago
0.1.1
8 years ago
0.1.0
8 years ago
0.0.1
8 years ago