mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-13 09:28:14 +08:00
🌱 初步完成日志文件的创建、写入 #83
This commit is contained in:
51
src/utils/TGLogger.ts
Normal file
51
src/utils/TGLogger.ts
Normal 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();
|
||||
Reference in New Issue
Block a user