Browse Source

✨ feat: 增加url路径记录

Pchen. 8 months ago
parent
commit
00597c0ad4
2 changed files with 4 additions and 4 deletions
  1. 1 1
      lib/API.js
  2. 3 3
      lib/requestLog.js

+ 1 - 1
lib/API.js

@@ -125,7 +125,7 @@ class API {
                     delete data.data
                     delete data.data
                 }
                 }
 
 
-                this.requestLog.insertLog(req, data, this.namespace, this.method)
+                this.requestLog.insertLog(req, data, this.namespace, this.method, this.path)
                 return originalJson(data)
                 return originalJson(data)
             }
             }
 
 

+ 3 - 3
lib/requestLog.js

@@ -9,7 +9,7 @@ class RequestLog {
         this.searcher = ipSearcher.newWithFileOnly(path.join(__dirname, '../plugin/ip2region/ip2region.xdb'))
         this.searcher = ipSearcher.newWithFileOnly(path.join(__dirname, '../plugin/ip2region/ip2region.xdb'))
     }
     }
 
 
-    async insertLog(req, res, namespace, method) {
+    async insertLog(req, res, namespace, method, path) {
         try {
         try {
             const time = new Date().getTime()
             const time = new Date().getTime()
             const ip = this.getClientIp(req)
             const ip = this.getClientIp(req)
@@ -26,8 +26,8 @@ class RequestLog {
                 reqData = req.body
                 reqData = req.body
             }
             }
 
 
-            let sql = 'INSERT INTO requestLog (create_user, create_time, method, reqData, code, ip, ua, deviceType, apiName, location) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
-            let r = await db.query(sql, [reqData.uuid ?? '', time, method, reqData, res.code, ip, userAgent, deviceType, namespace ?? '未知', ipData ?? '未知'])
+            let sql = 'INSERT INTO requestLog (create_user, create_time, method, reqData, code, ip, ua, deviceType, apiName, location, url) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
+            let r = await db.query(sql, [reqData.uuid ?? '', time, method, reqData, res.code, ip, userAgent, deviceType, namespace ?? '未知', ipData ?? '未知', path])
             if (!r || r.affectedRows !== 1)
             if (!r || r.affectedRows !== 1)
                 this.logger.error(`插入日志信息失败!数据库错误`)
                 this.logger.error(`插入日志信息失败!数据库错误`)
         } catch (error) {
         } catch (error) {