Skip to content

Commit

Permalink
Don't wrap fields
Browse files Browse the repository at this point in the history
Wrapping fields looks a bit nicer, but actually makes things quite a bit
harder to process with standard shell tools.

Want all errors with all data? With wrapping just a "grep" won't be
enough, and even grep -A1 won't be because not all might be wrapped.

This just makes everything easier at the expensive of being harder to
read on dev. I considered adding an option, but don't really want to add
the complexity. We'll see how this goes.
  • Loading branch information
arp242 committed Nov 4, 2019
1 parent d0db6c3 commit 6f91b37
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 32 deletions.
22 changes: 2 additions & 20 deletions output_std.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,10 @@ func format(l Log) string {
i++
}

sort.Strings(data)
wrap := b.Len()
if enableColors {
wrap -= 13
}
for i := range data {
wrap += len(data[i]) + 1

// This entry makes it go beyond 80 lines, so add newline to
// previous.
if i > 0 && wrap >= 80 {
wrap = 8
l := len(data[i-1])
data[i-1] = data[i-1][:l-1] + "\n\t"
}
if i != len(data)-1 {
data[i] += " "
}
}
sort.Strings(data) // Map order is random, so be predictable.

b.WriteString(" {")
b.WriteString(strings.Join(data, ""))
b.WriteString(strings.Join(data, " "))
b.WriteString("}")
}

Expand Down
12 changes: 0 additions & 12 deletions zlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@ func TestLog(t *testing.T) {
}, "ERROR: w00t {http_form=\"\" http_method=\"PUT\" http_url=\"/path?k=v&a=b\"}\n\ttesting.tRunner\n\t\t/fake/testing.go:42"},

{func() { FieldsLocation().Print("print") }, "INFO: print {location=\"zlog_test.go:65\"}"},

// Wrap very long fields.
{func() {
Fields(F{
"a": "hello, world",
"b": "asdadsas",
"c": "asdadsadsa",
"d": "qwe asd zxc",
"e": "qwewqewq zxc",
"f": "asdasd zxc",
}).Print("wrap")
}, "INFO: wrap {a=\"hello, world\" b=\"asdadsas\" c=\"asdadsadsa\"\n\td=\"qwe asd zxc\" e=\"qwewqewq zxc\" f=\"asdasd zxc\"}"},
}

for i, tt := range tests {
Expand Down

0 comments on commit 6f91b37

Please sign in to comment.