日志方法增加异步与同步的方法

This commit is contained in:
2025-11-30 21:01:47 +08:00
parent fd37c5c301
commit de8fc13f18
8 changed files with 310 additions and 45 deletions

View File

@@ -235,6 +235,15 @@ type LoggerConfig struct {
// DisableTimestamp 禁用时间戳
DisableTimestamp bool `json:"disableTimestamp"`
// Async 是否使用异步模式默认false即同步模式
// 异步模式日志写入通过channel异步处理不阻塞调用方
// 同步模式:日志直接写入,会阻塞调用方直到写入完成
Async bool `json:"async"`
// BufferSize 异步模式下的缓冲区大小默认1000
// 当缓冲区满时,新的日志会阻塞直到有空间
BufferSize int `json:"bufferSize"`
}
// LoadFromFile 从文件加载配置

View File

@@ -75,7 +75,9 @@
"output": "stdout",
"filePath": "",
"prefix": "app",
"disableTimestamp": false
"disableTimestamp": false,
"async": false,
"bufferSize": 1000
}
}