Skip to content

Commit 90d4846

Browse files
authored
Print logr prefix if it exists (#1275)
1 parent 555f543 commit 90d4846

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

internal/writer.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ func (w *Writer) Println(a ...interface{}) {
135135

136136
func GinkgoLogrFunc(writer *Writer) logr.Logger {
137137
return funcr.New(func(prefix, args string) {
138-
writer.Printf("%s\n", args)
138+
if prefix == "" {
139+
writer.Printf("%s\n", args)
140+
} else {
141+
writer.Printf("%s %s\n", prefix, args)
142+
}
139143
}, funcr.Options{})
140144
}

internal/writer_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,11 @@ var _ = Describe("Writer", func() {
144144
log.Error(errors.New("cake"), "planned failure", "key", "banana")
145145
Ω(string(out.Contents())).Should(Equal(" \"level\"=0 \"msg\"=\"message\" \"key\"=5\n \"msg\"=\"planned failure\" \"error\"=\"cake\" \"key\"=\"banana\"\n"))
146146
})
147+
148+
It("can print the logr prefix", func() {
149+
log := internal.GinkgoLogrFunc(writer)
150+
log.WithName("berry").Info("message", "key", 5)
151+
Ω(string(out.Contents())).Should(Equal(" berry \"level\"=0 \"msg\"=\"message\" \"key\"=5\n"))
152+
})
147153
})
148154
})

0 commit comments

Comments
 (0)