-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite.go
43 lines (37 loc) · 1.04 KB
/
write.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
package debugo
import (
"fmt"
"time"
)
func (l *Debugger) Debug(message ...any) {
l.write(message...)
}
func (l *Debugger) Debugf(format string, message ...any) {
l.write(fmt.Sprintf(format, message...))
}
func (l *Debugger) write(message ...any) {
if l.matchNamespace() {
msg := fmt.Sprint(message...)
timestamp := ""
if globalTimestamp != nil {
timestamp = time.Now().Format(globalTimestamp.Format) + " "
} else if l.timestamp != nil {
timestamp = time.Now().Format(l.timestamp.Format) + " "
}
var log string
if !noColors {
log = fmt.Sprintf("%s %s %s\n", l.color.Sprintf("%s%s", timestamp, l.namespace), noColor.Sprint(msg), l.color.Sprintf("+%s", prettyPrintDuration(l.elapsed())))
} else {
log = fmt.Sprintf("%s %s %s\n", fmt.Sprintf("%s%s", timestamp, l.namespace), fmt.Sprint(msg), fmt.Sprintf("+%s", prettyPrintDuration(l.elapsed())))
}
if l.channel != nil {
l.channel <- log
} else {
if l.output == nil {
fmt.Fprintf(output, "%s", log)
} else {
fmt.Fprintf(l.output, "%s", log)
}
}
}
}