'use strict'; /** * 请求日志模型,对应 request_logs 表 * @param {Egg.Application} app egg application * @return {object} requestLog model */ module.exports = app => { const { BIGINT, STRING, INTEGER, TEXT, DATE } = app.Sequelize; const RequestLog = app.model.define('request_log', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' }, method: { type: STRING(10), allowNull: false, comment: '请求方法' }, url: { type: STRING(500), allowNull: false, comment: '请求地址(含 query)' }, headers: { type: TEXT, comment: '请求头(敏感字段已脱敏)' }, request_body: { type: TEXT, comment: '请求报文(敏感字段已脱敏)' }, response_body: { type: TEXT, comment: '响应报文' }, status: { type: INTEGER, comment: 'HTTP 状态码' }, user_id: { type: BIGINT.UNSIGNED, comment: '解析到的用户ID,未登录为空' }, ip: { type: STRING(45), comment: '请求方IP' }, duration: { type: INTEGER, comment: '耗时(毫秒)' }, created_at: { type: DATE, comment: '创建时间' }, updated_at: { type: DATE, comment: '更新时间' }, }); return RequestLog; };