Skip to content

Commit

Permalink
Print logr prefix if it exists (#1275)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuckal777 authored Sep 19, 2023
1 parent 555f543 commit 90d4846
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ func (w *Writer) Println(a ...interface{}) {

func GinkgoLogrFunc(writer *Writer) logr.Logger {
return funcr.New(func(prefix, args string) {
writer.Printf("%s\n", args)
if prefix == "" {
writer.Printf("%s\n", args)
} else {
writer.Printf("%s %s\n", prefix, args)
}
}, funcr.Options{})
}
6 changes: 6 additions & 0 deletions internal/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,11 @@ var _ = Describe("Writer", func() {
log.Error(errors.New("cake"), "planned failure", "key", "banana")
Ω(string(out.Contents())).Should(Equal(" \"level\"=0 \"msg\"=\"message\" \"key\"=5\n \"msg\"=\"planned failure\" \"error\"=\"cake\" \"key\"=\"banana\"\n"))
})

It("can print the logr prefix", func() {
log := internal.GinkgoLogrFunc(writer)
log.WithName("berry").Info("message", "key", 5)
Ω(string(out.Contents())).Should(Equal(" berry \"level\"=0 \"msg\"=\"message\" \"key\"=5\n"))
})
})
})

0 comments on commit 90d4846

Please sign in to comment.