Skip to content

Encode compound types. #1

@ChrisHines

Description

@ChrisHines

At the moment this package does not support logging values of type array, chan, func, map, slice, or struct. Of these, I cannot think of a reason to support chan or func. But I think we need a good story for array, map, slice, and struct.

Precedents

Brandur Leach's logfmt blog post does not explicitly explain how to represent compound types in logfmt, nor does the defacto logfmt definition at github.com/kr/logfmt. There are some ideas in an old Gist by Kieth Rarick. The Gist shows this JSON data:

{"dyno":"web", "metadata":{"stack":["line 1", "line 2"], "msg":"null"}}

converted to logfmt as follows.

dyno=web metadata={stack=["line 1" "line 2"] msg="null"}

But the parser at github.com/kr/logfmt does not handle this syntax.

Logrus relies on Go's %v format in the fmt package and writes:

dyno=web metadata=map[stack:[line 1 line 2] msg:null]

log15 uses Go's %+v format and writes:

dyno=web metadata="map[msg:null stack:[line 1 line 2]]"

Neither of these logging packages produce output that can be easily parsed back into the original data structure.

I have not investigated what the non-Go logfmt libraries do.

Ways Forward

Given that there is not a clear best practice for encoding compound data structures in logfmt, this package must either refuse to handle them (as it does now) or define a robust encoding for these data types.

@kr, @bmizerany, @inconshreveable, @sirupsen: I would appreciate it if any of you would like to comment on this issue.

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