Log corruption and content interleaving when using Logger and Async TSVLogger simultaneously
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start by reading the Logger, TSVLogger, AsyncWriter, and FileWriter implementations, then run the provided TestSyncAndAsyncLoggerConsistency case. Trace how the writers handle concurrent writes to separate files and check whether the test reproduces the interleaving. Done when the async TSV output contains only complete expected lines and the test passes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Library Version: v1.0.121
Description: I encountered a log corruption issue when using a synchronous Logger and an asynchronous TSVLogger (wrapped with AsyncWriter) in the same test case. Even though the two loggers are configured to write to different files, the output in the asynchronous log file becomes interleaved and corrupted.
Specifically, fragments of the JSON format from the synchronous logger (e.g., {"time":) appear inside the TSV logger's output file, and the messages are truncated or mixed together.
Code:
func TestSyncAndAsyncLoggerConsistency(t *testing.T) {
syncFile := "consistency_sync.log"
asyncFile := "consistency_async.log"
// 1. Define a synchronous JSON logger
syncLogger := Logger{
Writer: &FileWriter{Filename: syncFile},
}
// 2. Define an asynchronous TSV logger
asyncLogger := TSVLogger{
Writer: &AsyncWriter{
ChannelSize: 4096,
DisableWritev: false,
DiscardOnFull: false,
Writer: &FileWriter{Filename: asyncFile},
},
}
for i := 0; i < 1000; i++ {
msg := "hello file writer"
// Write JSON log
syncLogger.Info().Str("line", msg).Msg("")
// Write TSV log
asyncLogger.New().Str(msg).Msg()
}
if err := syncLogger.Writer.(io.Closer).Close(); err != nil {
t.Fatalf("close sync logger: %+v", err)
}
if err := asyncLogger.Writer.(io.Closer).Close(); err != nil {
t.Fatalf("close async logger: %+v", err)
}
// Helper to check content consistency
LinesEqual := func(path string, content string) error {
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
// In this case, we expect the async log to only contain "hello file writer"
if scanner.Text() != content {
return errors.New("content mismatch: " + scanner.Text() + " != " + content)
}
}
return scanner.Err()
}
err := LinesEqual(asyncFile, "hello file writer")
if err != nil {
t.Fatalf("read async file: %+v", err)
}
}
Actual Output in consistency_async.log: The log file contains corrupted lines like:
hello file writer
hello file writer
{"time":le writer
{"time":le writer
hello file writer
{"time":le writer
- Ngôn ngữ chính
- Go
- Star
- 881
- Fork
- 64
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của phuslu/log
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
-
Fails to build in gccgoĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
-
bug: ConsoleWriterĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 32/100
-
About message fieldĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
Issue tương tự
-
Feature Request: clone buttonĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
cicd needs-triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày