forked from gravityblast/fresh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
38 lines (28 loc) · 791 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
package runner
import (
"fmt"
logPkg "log"
colorable "github.com/mattn/go-colorable"
)
type logFunc func(string, ...interface{})
var logger = logPkg.New(colorable.NewColorableStderr(), "", 0)
func newLogFunc(prefix string) func(string, ...interface{}) {
color, clear := "", ""
if settings["colors"] == "1" {
color = fmt.Sprintf("\033[%sm", logColor(prefix))
clear = fmt.Sprintf("\033[%sm", colors["reset"])
}
prefix = fmt.Sprintf("%-6s", prefix)
return func(format string, v ...interface{}) {
format = fmt.Sprintf("%s %s |%s %s", color, prefix, clear, format)
logger.Printf(format, v...)
}
}
func fatal(err error) {
logger.Fatal(err)
}
type appLogWriter struct{}
func (a appLogWriter) Write(p []byte) (n int, err error) {
appLog(string(p))
return len(p), nil
}