Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit 578aa5e

Browse files
authored
Merge pull request #2 from jessedearing/add-ln-loggers
Add log methods with `ln` at the end
2 parents 1628044 + 351c290 commit 578aa5e

File tree

5 files changed

+138
-0
lines changed

5 files changed

+138
-0
lines changed

log.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ type Logger interface {
2020
Warn(msg ...interface{})
2121
Error(msg ...interface{})
2222

23+
Debugln(msg ...interface{})
24+
Infoln(msg ...interface{})
25+
Warnln(msg ...interface{})
26+
Errorln(msg ...interface{})
27+
2328
Debugf(format string, args ...interface{})
2429
Infof(format string, args ...interface{})
2530
Warnf(format string, args ...interface{})
@@ -86,6 +91,30 @@ func (b *simple) Error(msg ...interface{}) {
8691
stdlog.Printf("[ERROR] %s %s", fmt.Sprint(msg...), pretty(b.fields))
8792
}
8893

94+
// Debugln log line message
95+
func (b *simple) Debugln(msg ...interface{}) {
96+
a := fmt.Sprintln(msg...)
97+
stdlog.Println("[DEBUG]", a[:len(a)-1], pretty(b.fields))
98+
}
99+
100+
// Infoln log line message
101+
func (b *simple) Infoln(msg ...interface{}) {
102+
a := fmt.Sprintln(msg...)
103+
stdlog.Println("[INFO]", a[:len(a)-1], pretty(b.fields))
104+
}
105+
106+
// Warnln log line message
107+
func (b *simple) Warnln(msg ...interface{}) {
108+
a := fmt.Sprintln(msg...)
109+
stdlog.Println("[WARN]", a[:len(a)-1], pretty(b.fields))
110+
}
111+
112+
// Errorln log line message
113+
func (b *simple) Errorln(msg ...interface{}) {
114+
a := fmt.Sprintln(msg...)
115+
stdlog.Println("[ERROR]", a[:len(a)-1], pretty(b.fields))
116+
}
117+
89118
// Debugf log message with formatting
90119
func (b *simple) Debugf(format string, args ...interface{}) {
91120
stdlog.Print(fmt.Sprintf("[DEBUG] "+format, args...), " ", pretty(b.fields))
@@ -144,6 +173,18 @@ func (n *noop) Warn(msg ...interface{}) {}
144173
// Error log message no-op
145174
func (n *noop) Error(msg ...interface{}) {}
146175

176+
// Debugln line log message no-op
177+
func (n *noop) Debugln(msg ...interface{}) {}
178+
179+
// Infoln line log message no-op
180+
func (n *noop) Infoln(msg ...interface{}) {}
181+
182+
// Warnln line log message no-op
183+
func (n *noop) Warnln(msg ...interface{}) {}
184+
185+
// Errorln line log message no-op
186+
func (n *noop) Errorln(msg ...interface{}) {}
187+
147188
// Debugf log message with formatting no-op
148189
func (n *noop) Debugf(format string, args ...interface{}) {}
149190

log_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ var _ = Describe("simple logger", func() {
4545
}
4646
})
4747

48+
It("prints all log line levels", func() {
49+
logFuncs := map[string]func(...interface{}){
50+
"DEBUG": l.Debugln,
51+
"INFO": l.Infoln,
52+
"WARN": l.Warnln,
53+
"ERROR": l.Errorln,
54+
}
55+
56+
for level, logFunc := range logFuncs {
57+
logFunc("hi", "there")
58+
59+
b := newOut.Bytes()
60+
newOut.Reset()
61+
Expect(string(b)).To(SatisfyAll(
62+
ContainSubstring("hi there"),
63+
ContainSubstring(level),
64+
))
65+
}
66+
})
67+
4868
It("prints all log levels on formatted", func() {
4969
logFuncs := map[string]func(string, ...interface{}){
5070
"DEBUG": l.Debugf,
@@ -152,6 +172,19 @@ var _ = Describe("noop logger", func() {
152172
})
153173

154174
Context("happy path", func() {
175+
It("does nothing", func() {
176+
logFuncs := map[string]func(...interface{}){
177+
"DEBUG": l.Debugln,
178+
"INFO": l.Infoln,
179+
"WARN": l.Warnln,
180+
"ERROR": l.Errorln,
181+
}
182+
183+
for _, logFunc := range logFuncs {
184+
logFunc("hi there")
185+
}
186+
})
187+
155188
It("does nothing", func() {
156189
logFuncs := map[string]func(...interface{}){
157190
"DEBUG": l.Debug,

shims/logrus/logrus_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@ var _ = Describe("logrus logger", func() {
4747
}
4848
})
4949

50+
It("prints all log levels", func() {
51+
logFuncs := map[string]func(...interface{}){
52+
"debug": l.Debugln,
53+
"info": l.Infoln,
54+
"warn": l.Warnln,
55+
"error": l.Errorln,
56+
}
57+
58+
for level, logFunc := range logFuncs {
59+
logFunc("hi", "there")
60+
61+
b := newOut.Bytes()
62+
newOut.Reset()
63+
Expect(string(b)).To(SatisfyAll(
64+
ContainSubstring("hi there"),
65+
ContainSubstring("level="+level),
66+
))
67+
}
68+
})
69+
5070
It("prints all log levels on formatted", func() {
5171
logFuncs := map[string]func(string, ...interface{}){
5272
"debug": l.Debugf,

shims/testlog/testlog.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,30 @@ func (t *TestLogger) write(level, msg string) {
4949
t.count.inc()
5050
}
5151

52+
//Debugln log line message
53+
func (t *TestLogger) Debugln(msg ...interface{}) {
54+
a := fmt.Sprintln(msg...)
55+
t.write("DEBUG", a[:len(a)-1])
56+
}
57+
58+
//Infoln log line message
59+
func (t *TestLogger) Infoln(msg ...interface{}) {
60+
a := fmt.Sprintln(msg...)
61+
t.write("INFO", a[:len(a)-1])
62+
}
63+
64+
//Warnln log line message
65+
func (t *TestLogger) Warnln(msg ...interface{}) {
66+
a := fmt.Sprintln(msg...)
67+
t.write("WARN", a[:len(a)-1])
68+
}
69+
70+
//Errorln log line message
71+
func (t *TestLogger) Errorln(msg ...interface{}) {
72+
a := fmt.Sprintln(msg...)
73+
t.write("ERROR", a[:len(a)-1])
74+
}
75+
5276
// Debug log message
5377
func (t *TestLogger) Debug(msg ...interface{}) {
5478
t.write("DEBUG", fmt.Sprint(msg...))

shims/testlog/testlog_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@ var _ = Describe("test logger", func() {
4242
}
4343
})
4444

45+
It("prints all log line levels", func() {
46+
logFuncs := map[string]func(...interface{}){
47+
"DEBUG": l.Debugln,
48+
"INFO": l.Infoln,
49+
"WARN": l.Warnln,
50+
"ERROR": l.Errorln,
51+
}
52+
53+
for level, logFunc := range logFuncs {
54+
logFunc("hi", "there")
55+
56+
b := testOut.Bytes()
57+
testOut.Reset()
58+
Expect(string(b)).To(SatisfyAll(
59+
ContainSubstring("hi there"),
60+
ContainSubstring(level),
61+
))
62+
}
63+
})
64+
4565
It("prints all log levels on formatted", func() {
4666
logFuncs := map[string]func(string, ...interface{}){
4767
"DEBUG": l.Debugf,

0 commit comments

Comments
 (0)