Skip to content

Support JSON formatting of logs #145

@carlpett

Description

@carlpett

common/log supports a json formatter for the log output, which common/promlog does not. Would a PR to add a flag for switching between json/plain text be acceptable? This would make it much easier to integrate exporters etc into environments which mandate structured logging (vs having an extra binary to rewrite the logs).
go-kit already has the necessary NewJSONLogger function, which could be conditionally used instead of NewLogfmtLogger into here:

common/promlog/log.go

Lines 58 to 63 in c7de230

func New(al AllowedLevel) log.Logger {
l := log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr))
l = level.NewFilter(l, al.o)
l = log.With(l, "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller)
return l
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions