优化一些功能

This commit is contained in:
yml2213
2026-07-29 14:02:56 +08:00
parent 2c88edb741
commit f64838f8db
19 changed files with 313 additions and 85 deletions
+5
View File
@@ -53,6 +53,7 @@ func levelPriority(level string) int {
// AsyncLogWriter 异步日志写入器,队列满时丢弃日志以保护主链路。
type AsyncLogWriter struct {
mu sync.RWMutex
dst io.Writer
ch chan []byte
wg sync.WaitGroup
@@ -79,6 +80,8 @@ func (w *AsyncLogWriter) Write(p []byte) (int, error) {
if w == nil {
return len(p), nil
}
w.mu.RLock()
defer w.mu.RUnlock()
if atomic.LoadUint32(&w.closed) == 1 {
return len(p), nil
}
@@ -106,6 +109,8 @@ func (w *AsyncLogWriter) Close() error {
if w == nil {
return nil
}
w.mu.Lock()
defer w.mu.Unlock()
if atomic.CompareAndSwapUint32(&w.closed, 0, 1) {
close(w.ch)
w.wg.Wait()