forked from paketo-buildpacks/packit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
62 lines (51 loc) · 1.33 KB
/
logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package scribe
import (
"fmt"
"io"
"strings"
)
type Logger struct {
title io.Writer
process io.Writer
subprocess io.Writer
action io.Writer
detail io.Writer
subdetail io.Writer
}
func NewLogger(writer io.Writer) Logger {
return Logger{
title: NewWriter(writer),
process: NewWriter(writer, WithIndent(1)),
subprocess: NewWriter(writer, WithIndent(2)),
action: NewWriter(writer, WithIndent(3)),
detail: NewWriter(writer, WithIndent(4)),
subdetail: NewWriter(writer, WithIndent(5)),
}
}
func (l Logger) Title(format string, v ...interface{}) {
l.printf(l.title, format, v...)
}
func (l Logger) Process(format string, v ...interface{}) {
l.printf(l.process, format, v...)
}
func (l Logger) Subprocess(format string, v ...interface{}) {
l.printf(l.subprocess, format, v...)
}
func (l Logger) Action(format string, v ...interface{}) {
l.printf(l.action, format, v...)
}
func (l Logger) Detail(format string, v ...interface{}) {
l.printf(l.detail, format, v...)
}
func (l Logger) Subdetail(format string, v ...interface{}) {
l.printf(l.subdetail, format, v...)
}
func (l Logger) Break() {
l.printf(l.title, "\n")
}
func (l Logger) printf(writer io.Writer, format string, v ...interface{}) {
if !strings.HasSuffix(format, "\n") {
format = format + "\n"
}
fmt.Fprintf(writer, format, v...)
}