日志功能封装

This commit is contained in:
2024-05-22 18:02:48 +08:00
parent d757f99b5d
commit 68262d0519
5 changed files with 40 additions and 4 deletions

View File

@@ -0,0 +1,30 @@
import RealtimeTagLogManager = UniNamespace.RealtimeTagLogManager;
export class Logger {
private env = uni.getAccountInfoSync().miniProgram.envVersion;
private readonly logger: RealtimeTagLogManager;
constructor() {
const logManager = uni.getRealtimeLogManager();
this.logger = logManager.tag('suke-mp');
}
info(key: string, value: any) {
if(this.env === 'release' || this.env === 'trial') {
this.logger.info(key, value);
}
}
warn(key: string, value: any) {
if(this.env === 'release' || this.env === 'trial') {
this.logger.warn(key, value);
}
}
error(key: string, value: any) {
if(this.env === 'release' || this.env === 'trial') {
this.logger.error(key, value);
}
}
}

View File

@@ -26,6 +26,7 @@ function requestInterceptors() {
// config.header.contentType = "x-www-form-urlencoded"
}
getApp().globalData?.logger.info('request: ', config);
return config;
},
(
@@ -52,6 +53,8 @@ function responseInterceptors() {
return data;
}
getApp().globalData?.logger.info('response: ', config);
// 请求成功则返回结果
if(data.code === 200 || data?.retcode == 0) {
return data || {};