Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The log rotation format is chaotic, leading to truncation and missing corresponding line breaks. #4395

Open
JellyTony opened this issue Sep 25, 2024 · 1 comment

Comments

@JellyTony
Copy link

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior, if applicable:

  1. The code is

    func TestZap(t *testing.T) {
     sync, err := logx.NewLogger("../logs/stat.log", logx.DefaultRotateRule("../logs/stat.log", "-", 0, false), false)
     assert.NoError(t, err)
     syncer := zapcore.AddSync(sync)
     encoder := zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig())
     core := zapcore.NewCore(encoder, syncer, zapcore.DebugLevel)
    
     logger := zap.New(core)
     logger.Sync()
    
     // {"level": ... ,"ts" ... ,"msg":"hello world"}
     // 一行日志大约 60B,写入 100000 次,总大小为 6 MB+
     for i := 0; i < 100000; i++ {
     	logger.Debug("hello world")
     	logger.Info("hello world")
     	logger.Warn("hello world")
     	logger.Error("hello world")
     }

}


2. The error is

{"level":"info","ts":1727265133.6969411,"msg":"hello world"}
{"level":"info","ts":1727265133.6969411,"msg":"hello world"}{"level":"error","ts":1727265133.6970549,"msg":"hello world"}{"level":"error","ts":1727265133.6970549,"msg":"hello world"}
{"level":"info","ts"::1727265133.697073,"msg":"hello world"}
{"level":"info","ts":1727265133.697075,"msg":"hello world"}
{"level":"error","ts":1727265133.6970859,"msg":"hello world"{"level":"error","ts":1727265133.6970859,"msg":"hello world"}
{"level":"info","ts":1727265133.697118,"msg":"hello world"}
}
{"level":"info","ts":1727265133.697118,"msg":"hello world"}
}{"level":"error","ts":1727265133.69714,"msg":"hello world"}
{"level":"error","ts":1727265133.69714,"msg":"hello world"}

{"level":"info","ts":1727265133.6971579,"msg":"hello world"}
{"level":"info","ts":1727265133.6971579,"msg":"hello world"}{"level":"info","ts":1727265133.6971579,"msg":"hello world"}{"level":"info","ts":1727265133.6971579,"msg":"hello world"}
{"level":"warn","ts":1727265133.697186,"msg":"hello world"}


**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environments (please complete the following information):**
- OS: [e.g. Linux]
- go-zero version [e.g. 1.2.1]
- goctl version [e.g. 1.2.1, optional]

**More description**
go-zero 的日志轮转,我发现在使用 zap 的时候 日志会混乱,{"level":"error","ts":"2024-09-25T16:22:30.567+0800","caller":"logger/logging_test.go:150","msg":"test msg","
"a":123,"v":1g_test.go:1374-09-25T16:22:30.567+0800","caller":"logger/logging_test.go:150","msg":"test msg","a":123,"v":1}
"a":123,"v":1g_test.go:1374-09-25T16:22:30.567+0800","caller":"logger/logging_test.go:150","msg":"test msg","a":123,"v":1}
"a":123,"v":1g_test.go:1374-09-25T16:22:30.567+0800","caller":"logger/logging_test.go:150","msg":"test msg","a":123,"v":1}

"a":123,"v":1g_test.go:1374-09-25T16:22:30.567+0800","caller":"logger/logging_test.go:150","msg":"test msg","
"a":123,"v":1g_test.go:1374-09-25T16:22:30.567+0800","caller":"logger/logging_test.go:150","msg":"test msg","v":1,"a":123}
"a":123,"v":1g_test.go:1374-09-25T16:22:30.567+0800","caller":"logger/logging_test.go:150","msg":"test msg","v":1,"a":123}
"a":123,"v":1g_test.go:1374-09-25T16:22:30.567+0800","caller":"logger/logging_test.go:150","msg":"test msg","v":1,"a":123}输出类似这种,我仔细看了一下是 channel 缓冲导致的,在同时打印多种日志级别即会出现
@kevwan kevwan changed the title 日志轮转格式混乱,导致被截取和没有对应的换行等 The log rotation format is chaotic, leading to truncation and missing corresponding line breaks. Sep 25, 2024
@kevwan
Copy link
Contributor

kevwan commented Oct 2, 2024

Does it work well if you only use logx?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants