fix: 日志系统
This commit is contained in:
		
							parent
							
								
									47fb785c9a
								
							
						
					
					
						commit
						4226dbf1f2
					
				| @ -1,16 +1,19 @@ | ||||
| // 日志向外暴露的方法 | ||||
| import dayTs from './Date'; | ||||
| import worker from '@ohos.worker'; | ||||
| import { EnvironmentConfigurationType, LogWorkerMessage, WorkerMessageType } from '../model/index'; | ||||
| import Prompt from '@system.prompt'; | ||||
| import { LogWorkerMessage, WorkerMessageType } from '../model/index'; | ||||
| 
 | ||||
| const MAX_MESSAGE_LENGTH = 300; | ||||
| const LOG_CHUNK_PREFIX = '[切割消息序号'; | ||||
| 
 | ||||
| class logWorker { | ||||
|   private workerInstance = new worker.ThreadWorker("entry/ets/workers/Log.ets") | ||||
|   // 是否开启日志 | ||||
|   private isLogEnabled: boolean = true; | ||||
|   // 是否开启日志 1开启 | ||||
|   private isLogEnabled: string = "0"; | ||||
| 
 | ||||
|   constructor() { | ||||
|     console.log("当前环境配置单例模式") | ||||
|   } | ||||
| 
 | ||||
|   // 正常日志 | ||||
|   log(...args: ESObject[]) { | ||||
| @ -33,16 +36,10 @@ class logWorker { | ||||
|   } | ||||
| 
 | ||||
|   // 初始化板子,需要判断duolun是否存在,不存在则创建 | ||||
|   init() { | ||||
|     const config = AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration"); | ||||
|     if (!config) { | ||||
|       Prompt.showToast({ | ||||
|         message: "请先配置环境变量" | ||||
|       }) | ||||
|       return; | ||||
|     } | ||||
|     this.isLogEnabled = config.isOpenLog === "1" ? true : false; | ||||
|     if (this.isLogEnabled) { | ||||
|   init(isOpenLog: string) { | ||||
|     console.log(`当前环境配置初始化: ${isOpenLog}`); | ||||
|     this.isLogEnabled = isOpenLog; | ||||
|     if (this.isLogEnabled === "1") { | ||||
|       this.workerInstance = new worker.ThreadWorker("entry/ets/workers/Log.ets"); | ||||
|       let data: LogWorkerMessage = { | ||||
|         type: WorkerMessageType.Init | ||||
| @ -61,7 +58,8 @@ class logWorker { | ||||
| 
 | ||||
|   // 通用日志方法 | ||||
|   private logWithLevel(level: 'log' | 'info' | 'error', ...args: ESObject[]): void { | ||||
|     if (this.isLogEnabled) { | ||||
|     console.log("当前环境查看", this.isLogEnabled, "日志级别:", level) | ||||
|     if (this.isLogEnabled === "1") { | ||||
|       const message = this.formatMessage(...args); | ||||
|       if (message.length > MAX_MESSAGE_LENGTH) { | ||||
|         this.logLongMessage(level, message); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user