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

Commit 084a63b

Browse files
committed
✨ Add log methods with ln at the end
1 parent 1628044 commit 084a63b

File tree

5 files changed

+117
-0
lines changed

5 files changed

+117
-0
lines changed

log.go

Lines changed: 37 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,26 @@ 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+
stdlog.Println("[DEBUG]", fmt.Sprintln(msg...), pretty(b.fields))
97+
}
98+
99+
// Infoln log line message
100+
func (b *simple) Infoln(msg ...interface{}) {
101+
stdlog.Println("[INFO]", fmt.Sprintln(msg...), pretty(b.fields))
102+
}
103+
104+
// Warnln log line message
105+
func (b *simple) Warnln(msg ...interface{}) {
106+
stdlog.Println("[WARN]", fmt.Sprintln(msg...), pretty(b.fields))
107+
}
108+
109+
// Errorln log line message
110+
func (b *simple) Errorln(msg ...interface{}) {
111+
stdlog.Println("[ERROR]", fmt.Sprintln(msg...), pretty(b.fields))
112+
}
113+
89114
// Debugf log message with formatting
90115
func (b *simple) Debugf(format string, args ...interface{}) {
91116
stdlog.Print(fmt.Sprintf("[DEBUG] "+format, args...), " ", pretty(b.fields))
@@ -144,6 +169,18 @@ func (n *noop) Warn(msg ...interface{}) {}
144169
// Error log message no-op
145170
func (n *noop) Error(msg ...interface{}) {}
146171

172+
// Debugln line log message no-op
173+
func (n *noop) Debugln(msg ...interface{}) {}
174+
175+
// Infoln line log message no-op
176+
func (n *noop) Infoln(msg ...interface{}) {}
177+
178+
// Warnln line log message no-op
179+
func (n *noop) Warnln(msg ...interface{}) {}
180+
181+
// Errorln line log message no-op
182+
func (n *noop) Errorln(msg ...interface{}) {}
183+
147184
// Debugf log message with formatting no-op
148185
func (n *noop) Debugf(format string, args ...interface{}) {}
149186

log_test.go

Lines changed: 20 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,

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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@ 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+
t.write("DEBUG", fmt.Sprintln(msg...))
55+
}
56+
57+
//Infoln log line message
58+
func (t *TestLogger) Infoln(msg ...interface{}) {
59+
t.write("INFO", fmt.Sprintln(msg...))
60+
}
61+
62+
//Warnln log line message
63+
func (t *TestLogger) Warnln(msg ...interface{}) {
64+
t.write("WARN", fmt.Sprintln(msg...))
65+
}
66+
67+
//Errorln log line message
68+
func (t *TestLogger) Errorln(msg ...interface{}) {
69+
t.write("ERROR", fmt.Sprintln(msg...))
70+
}
71+
5272
// Debug log message
5373
func (t *TestLogger) Debug(msg ...interface{}) {
5474
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)