Skip to content

Commit

Permalink
add newlines to GinkgoLogr (onsi#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
erdnas committed Mar 27, 2023
1 parent 9b5078f commit 6dc258e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,6 @@ func (w *Writer) Println(a ...interface{}) {

func GinkgoLogrFunc(writer *Writer) logr.Logger {
return funcr.New(func(prefix, args string) {
writer.Printf("%s", args)
writer.Printf("%s\n", args)
}, funcr.Options{})
}
12 changes: 9 additions & 3 deletions internal/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,24 @@ var _ = Describe("Writer", func() {
Ω(string(out.Contents())).Should(Equal(" foo17 - bar\n"))
})
})

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

It("can print Error logs", func() {
log := internal.GinkgoLogrFunc(writer)
log.Error(errors.New("cake"), "planned failure", "key", "banana")
Ω(string(out.Contents())).Should(Equal(" \"msg\"=\"planned failure\" \"error\"=\"cake\" \"key\"=\"banana\""))
Ω(string(out.Contents())).Should(Equal(" \"msg\"=\"planned failure\" \"error\"=\"cake\" \"key\"=\"banana\"\n"))
})

It("can print multiple logs", func() {
log := internal.GinkgoLogrFunc(writer)
log.Info("message", "key", 5)
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"))
})
})
})

0 comments on commit 6dc258e

Please sign in to comment.