🌱 初步完成日志文件的创建、写入 #83

This commit is contained in:
目棃
2024-01-22 16:51:41 +08:00
parent 297474af9c
commit be028a318d
7 changed files with 387 additions and 9 deletions

51
src/utils/TGLogger.ts Normal file
View File

@@ -0,0 +1,51 @@
/**
* @file utils/TGLogger.ts
* @description 日志工具
* @since Beta v0.4.2
*/
import { info, warn, error } from "tauri-plugin-log-api";
/**
* @description 日志工具
* @since Beta v0.4.2
*/
class TGLogger {
/**
* @description 输出日志-信息
* @since Beta v0.4.2
* @param {string} message 日志信息
* @param {boolean} [write] 是否写入日志文件,默认为 true
* @returns {Promise<void>} 无返回值
*/
async Info(message: string, write: boolean = true): Promise<void> {
if (write) await info(message);
console.info(message);
}
/**
* @description 输出日志-警告
* @since Beta v0.4.2
* @param {string} message 日志信息
* @param {boolean} [write] 是否写入日志文件,默认为 true
* @returns {Promise<void>} 无返回值
*/
async Warn(message: string, write: boolean = true): Promise<void> {
if (write) await warn(message);
console.warn(message);
}
/**
* @description 输出日志-错误
* @since Beta v0.4.2
* @param {string} message 日志信息
* @param {boolean} [write] 是否写入日志文件,默认为 true
* @returns {Promise<void>} 无返回值
*/
async Error(message: string, write: boolean = true): Promise<void> {
if (write) await error(message);
console.error(message);
}
}
export default new TGLogger();