-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger.go
63 lines (53 loc) · 892 Bytes
/
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
63
package main
import (
"fmt"
"time"
)
type logger struct {
pipe chan interface{}
logLevel string
}
func newLogger(logLevel string) *logger {
l := &logger{
pipe: make(chan interface{}),
logLevel: logLevel,
}
go func() {
for s := range l.pipe {
switch s.(type) {
case error:
fmt.Println(s)
default:
if l.logLevel != "" {
fmt.Println(s)
}
}
}
}()
return l
}
func (l *logger) Close() {
close(l.pipe)
}
func (l *logger) log(s interface{}) {
l.pipe <- s
}
type colorFunc func(string) string
var colors = []string{
"green",
"yellow",
"blue",
"magenta",
"cyan",
"red+h",
"green+h",
"yellow+h",
"blue+h",
"magenta+h",
"cyan+h",
}
func logForJob(j *job) func(string) string {
return func(s string) string {
return j.color(fmt.Sprintf("%s %s :\n - %s", time.Now().Format("15:04:05"), j.settings.source+j.fileName, s))
}
}