Sfoglia il codice sorgente

新增日志

master
leiyun 3 giorni fa
parent
commit
05ad3a18ee
1 ha cambiato i file con 18 aggiunte e 3 eliminazioni
  1. +18
    -3
      src/controller/base.js

+ 18
- 3
src/controller/base.js Vedi File

@@ -18,11 +18,17 @@ const WHITE_LIST = [


module.exports = class extends think.Controller { module.exports = class extends think.Controller {
async __before() { 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; 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后缀的路径) // 白名单放行(同时匹配带.html后缀的路径)
const pathNoSuffix = path.replace(/\.html$/, ''); const pathNoSuffix = path.replace(/\.html$/, '');
if (WHITE_LIST.includes(path) || WHITE_LIST.includes(pathNoSuffix)) { 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() { async loadUserPermissions() {
if (!this.adminUser) return; if (!this.adminUser) return;


Caricamento…
Annulla
Salva