uber-go / zap

Blazing fast, structured, leveled logging in Go.
https://pkg.go.dev/go.uber.org/zap
MIT License
22.1k stars 1.44k forks source link

There are many '\n' in the json-style log #1455

Closed yangyang233333 closed 3 months ago

yangyang233333 commented 3 months ago

Describe the bug There are many '\n' in the json-style log

To Reproduce

func main() {
    config := zap.NewProductionConfig()
    logger, err := config.Build()
    if err != nil {
        panic(err)
    }
    Log := logger.Sugar()

    Log.Infof("key", "value1 \n value2 ...")
}

Expected behavior Want:

{"level":"info","ts":1722577303.808197,"caller":"gotest/main.go:32","msg":"key%!(EXTRA string=value1
 value2 ...)"}

Actual:

{"level":"info","ts":1722577303.808197,"caller":"gotest/main.go:32","msg":"key%!(EXTRA string=value1 \n value2 ...)"}

Additional context Add any other context about the problem here.

tchung1118 commented 3 months ago

Our JSONEncoder is meant to encode logs into JSON format, and it escapes all keys and values appropriately to meet the JSON specification. You can choose to display JSON-encoded logs however you want, but this is out of zap's control.