From 05ad3a18ee35c3061391ee26bddc2fe5c8ccfe82 Mon Sep 17 00:00:00 2001 From: leiyun Date: Sat, 21 Mar 2026 00:31:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/base.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/controller/base.js b/src/controller/base.js index 25f7710..f7d8760 100644 --- a/src/controller/base.js +++ b/src/controller/base.js @@ -18,11 +18,17 @@ const WHITE_LIST = [ module.exports = class extends think.Controller { async __before() { - console.log('[TEST-CONSOLE] base __before 被调用, path:', this.ctx.path); - think.logger.info('[TEST-LOGGER] base __before 被调用, path:', this.ctx.path); - const path = this.ctx.path; + // 记录请求开始时间 + this._requestStart = Date.now(); + const dayjs = require('dayjs'); + const params = { ...this.get(), ...this.post() }; + console.log('=================== 请求开始 ==================='); + console.log(`path: ${path}`); + console.log(`params: ${JSON.stringify(params)}`); + console.log(`time: ${dayjs().format('YYYY-MM-DD HH:mm:ss')}`); + // 白名单放行(同时匹配带.html后缀的路径) const pathNoSuffix = path.replace(/\.html$/, ''); if (WHITE_LIST.includes(path) || WHITE_LIST.includes(pathNoSuffix)) { @@ -67,6 +73,15 @@ module.exports = class extends think.Controller { } } + async __after() { + const dayjs = require('dayjs'); + const elapsed = ((Date.now() - (this._requestStart || Date.now())) / 1000).toFixed(3); + console.log(`result: ${JSON.stringify(this.ctx.body || '').slice(0, 500)}`); + console.log(`time: ${dayjs().format('YYYY-MM-DD HH:mm:ss')}`); + console.log(`耗时: ${elapsed}秒`); + console.log('=================== 请求结束 ==================='); + } + // 加载用户权限 async loadUserPermissions() { if (!this.adminUser) return;