Skip to content

Error in zerolog-writer.go:45 when message has comma in a message body #583

Closed
@polanskya

Description

@polanskya

Example:
l.Debug().Msgf(fmt.Sprintf("Renew licenseID: %s**,** licenseType: %s ", licenseID, licenseType))
OR
l.Debug().Msg(" Renew licenseID: %s licenseType: %s ", licenseID, licenseType))

When message has a comma in a message string there is parsing exception
valStart := getValueIndex(log, keyEnd)
Get Value index is -1

/usr/local/Cellar/go@1.17/1.17.13/libexec/src/runtime/panic.go:90 (0x1032314)
goPanicIndex: panic(boundsError{x: int64(x), signed: true, y: y, code: boundsIndex})
/Users/XXX/dev/projects/go/pkg/mod/github.com/newrelic/go-agent/v3/integrations/logcontext-v2/zerolog!writer@v1.0.1/zerolog-writer.go:82 (0x150793a)
getValueIndex: if p[i] == ':' {
/Users/XXX/dev/projects/go/pkg/mod/github.com/newrelic/go-agent/v3/integrations/logcontext-v2/zerolog!writer@v1.0.1/zerolog-writer.go:60 (0x1507789)
parseJSONLogData: valStart := getValueIndex(log, keyEnd)
/Users/XXX/dev/projects/go/pkg/mod/github.com/newrelic/go-agent/v3/integrations/logcontext-v2/zerolog!writer@v1.0.1/zerolog-writer.go:45 (0x1507552)

Without commas , message prints correctly.

{"level":"debug","time":"2022-09-22T11:47:04.184074-04:00","caller":"license.go:55","message":"Renew 2.0"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions