-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
output: handle WithName like zapr does #391
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ func testOutput(t *testing.T, format string) { | |
klogr: createLogger().V(0), | ||
text: "test", | ||
keysAndValues: []interface{}{"akey", "avalue"}, | ||
expectedOutput: ` "msg"="test" "akey"="avalue" | ||
expectedOutput: `"msg"="test" "akey"="avalue" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like that this empty space at the start is going away. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. That space was the result of some overly simplistic code for injecting the prefix, which is now gone. |
||
`, | ||
expectedKlogOutput: `"test" akey="avalue" | ||
`, | ||
|
@@ -51,25 +51,29 @@ func testOutput(t *testing.T, format string) { | |
klogr: createLogger().V(0).WithName("me"), | ||
text: "test", | ||
keysAndValues: []interface{}{"akey", "avalue"}, | ||
expectedOutput: `me "msg"="test" "akey"="avalue" | ||
// Sorted by keys. | ||
expectedOutput: `"msg"="test" "akey"="avalue" "logger"="me" | ||
`, | ||
expectedKlogOutput: `"me: test" akey="avalue" | ||
// Not sorted by keys. | ||
expectedKlogOutput: `"test" logger="me" akey="avalue" | ||
`, | ||
}, | ||
"should log with multiple names and values passed to keysAndValues": { | ||
klogr: createLogger().V(0).WithName("hello").WithName("world"), | ||
text: "test", | ||
keysAndValues: []interface{}{"akey", "avalue"}, | ||
expectedOutput: `hello/world "msg"="test" "akey"="avalue" | ||
// Sorted by keys. | ||
expectedOutput: `"msg"="test" "akey"="avalue" "logger"="hello.world" | ||
`, | ||
expectedKlogOutput: `"hello/world: test" akey="avalue" | ||
// Not sorted by keys. | ||
expectedKlogOutput: `"test" logger="hello.world" akey="avalue" | ||
`, | ||
}, | ||
"may print duplicate keys with the same value": { | ||
klogr: createLogger().V(0), | ||
text: "test", | ||
keysAndValues: []interface{}{"akey", "avalue", "akey", "avalue"}, | ||
expectedOutput: ` "msg"="test" "akey"="avalue" | ||
expectedOutput: `"msg"="test" "akey"="avalue" | ||
`, | ||
expectedKlogOutput: `"test" akey="avalue" akey="avalue" | ||
`, | ||
|
@@ -78,7 +82,7 @@ func testOutput(t *testing.T, format string) { | |
klogr: createLogger().V(0), | ||
text: "test", | ||
keysAndValues: []interface{}{"akey", "avalue", "akey", "avalue2"}, | ||
expectedOutput: ` "msg"="test" "akey"="avalue2" | ||
expectedOutput: `"msg"="test" "akey"="avalue2" | ||
`, | ||
expectedKlogOutput: `"test" akey="avalue" akey="avalue2" | ||
`, | ||
|
@@ -87,7 +91,7 @@ func testOutput(t *testing.T, format string) { | |
klogr: createLogger().WithValues("akey", "avalue"), | ||
text: "test", | ||
keysAndValues: []interface{}{"akey", "avalue"}, | ||
expectedOutput: ` "msg"="test" "akey"="avalue" | ||
expectedOutput: `"msg"="test" "akey"="avalue" | ||
`, | ||
expectedKlogOutput: `"test" akey="avalue" | ||
`, | ||
|
@@ -96,7 +100,7 @@ func testOutput(t *testing.T, format string) { | |
klogr: createLogger().WithValues("akey9", "avalue9", "akey8", "avalue8", "akey1", "avalue1"), | ||
text: "test", | ||
keysAndValues: []interface{}{"akey5", "avalue5", "akey4", "avalue4"}, | ||
expectedOutput: ` "msg"="test" "akey1"="avalue1" "akey4"="avalue4" "akey5"="avalue5" "akey8"="avalue8" "akey9"="avalue9" | ||
expectedOutput: `"msg"="test" "akey1"="avalue1" "akey4"="avalue4" "akey5"="avalue5" "akey8"="avalue8" "akey9"="avalue9" | ||
`, | ||
expectedKlogOutput: `"test" akey9="avalue9" akey8="avalue8" akey1="avalue1" akey5="avalue5" akey4="avalue4" | ||
`, | ||
|
@@ -105,7 +109,7 @@ func testOutput(t *testing.T, format string) { | |
klogr: createLogger().WithValues("akey", "avalue"), | ||
text: "test", | ||
keysAndValues: []interface{}{"akey", "avalue2"}, | ||
expectedOutput: ` "msg"="test" "akey"="avalue2" | ||
expectedOutput: `"msg"="test" "akey"="avalue2" | ||
`, | ||
expectedKlogOutput: `"test" akey="avalue2" | ||
`, | ||
|
@@ -114,7 +118,7 @@ func testOutput(t *testing.T, format string) { | |
klogr: createLogger(), | ||
text: "test", | ||
keysAndValues: []interface{}{"akey", "avalue", "akey2"}, | ||
expectedOutput: ` "msg"="test" "akey"="avalue" "akey2"="(MISSING)" | ||
expectedOutput: `"msg"="test" "akey"="avalue" "akey2"="(MISSING)" | ||
`, | ||
expectedKlogOutput: `"test" akey="avalue" akey2="(MISSING)" | ||
`, | ||
|
@@ -124,7 +128,7 @@ func testOutput(t *testing.T, format string) { | |
text: "test", | ||
keysAndValues: []interface{}{"akey", "avalue", "akey2"}, | ||
// klogr format sorts all key/value pairs. | ||
expectedOutput: ` "msg"="test" "akey"="avalue" "akey2"="(MISSING)" "keyWithoutValue"="(MISSING)" | ||
expectedOutput: `"msg"="test" "akey"="avalue" "akey2"="(MISSING)" "keyWithoutValue"="(MISSING)" | ||
`, | ||
expectedKlogOutput: `"test" keyWithoutValue="(MISSING)" akey="avalue" akey2="(MISSING)" | ||
`, | ||
|
@@ -133,7 +137,7 @@ func testOutput(t *testing.T, format string) { | |
klogr: createLogger(), | ||
text: "test", | ||
keysAndValues: []interface{}{"akey", "<&>"}, | ||
expectedOutput: ` "msg"="test" "akey"="<&>" | ||
expectedOutput: `"msg"="test" "akey"="<&>" | ||
`, | ||
expectedKlogOutput: `"test" akey="<&>" | ||
`, | ||
|
@@ -143,7 +147,7 @@ func testOutput(t *testing.T, format string) { | |
text: "test", | ||
keysAndValues: []interface{}{"akey", "avalue", "akey2"}, | ||
// klogr format sorts all key/value pairs. | ||
expectedOutput: ` "msg"="test" "akey"="avalue" "akey2"="(MISSING)" "basekey1"="basevar1" "basekey2"="(MISSING)" | ||
expectedOutput: `"msg"="test" "akey"="avalue" "akey2"="(MISSING)" "basekey1"="basevar1" "basekey2"="(MISSING)" | ||
`, | ||
expectedKlogOutput: `"test" basekey1="basevar1" basekey2="(MISSING)" akey="avalue" akey2="(MISSING)" | ||
`, | ||
|
@@ -152,7 +156,7 @@ func testOutput(t *testing.T, format string) { | |
klogr: createLogger().V(0), | ||
text: "test", | ||
keysAndValues: []interface{}{"err", errors.New("whoops")}, | ||
expectedOutput: ` "msg"="test" "err"="whoops" | ||
expectedOutput: `"msg"="test" "err"="whoops" | ||
`, | ||
expectedKlogOutput: `"test" err="whoops" | ||
`, | ||
|
@@ -161,7 +165,7 @@ func testOutput(t *testing.T, format string) { | |
klogr: createLogger().V(0), | ||
text: "test", | ||
keysAndValues: []interface{}{"err", &customErrorJSON{"whoops"}}, | ||
expectedOutput: ` "msg"="test" "err"="WHOOPS" | ||
expectedOutput: `"msg"="test" "err"="WHOOPS" | ||
`, | ||
expectedKlogOutput: `"test" err="whoops" | ||
`, | ||
|
@@ -170,7 +174,7 @@ func testOutput(t *testing.T, format string) { | |
klogr: createLogger().V(0), | ||
text: "test", | ||
err: errors.New("whoops"), | ||
expectedOutput: ` "msg"="test" "error"="whoops" | ||
expectedOutput: `"msg"="test" "error"="whoops" | ||
`, | ||
expectedKlogOutput: `"test" err="whoops" | ||
`, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be nitpicking, but Would the above one make it more easier ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would, but Go doesn't support this: one can either append multiple values or provide those values through a slice, but not both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ! Sorry, never mind. my thought about reviewing something on python slipped into this thread as well. You are right. Thanks for clarifying.