@@ -4,33 +4,63 @@ import (
44 "fmt"
55 "io"
66 "os"
7+ "strings"
78
89 "github.com/motemen/go-colorine"
910)
1011
11- var logger = colorine .NewLogger (
12- colorine.Prefixes {
13- "git" : colorine .Verbose ,
14- "hg" : colorine .Verbose ,
15- "svn" : colorine .Verbose ,
16- "darcs" : colorine .Verbose ,
17- "pijul" : colorine .Verbose ,
18- "bzr" : colorine .Verbose ,
19- "fossil" : colorine .Verbose ,
20- "skip" : colorine .Verbose ,
21- "cd" : colorine .Verbose ,
22- "resolved" : colorine .Verbose ,
23-
24- "open" : colorine .Warn ,
25- "exists" : colorine .Warn ,
26- "warning" : colorine .Warn ,
12+ var (
13+ NoColor = colorine.TextStyle {Foreground : colorine .None , Background : colorine .None }
14+ VerboseColor = colorine .Verbose // white
15+ InfoColor = colorine .Info // green
16+ NoticeColor = colorine .Notice // blue
17+ WarnColor = colorine .Warn // yellow
18+ ErrorColor = colorine .Error // red
19+ )
2720
28- "authorized" : colorine .Notice ,
21+ var (
22+ logger = colorine .NewLogger ( // default logger with color
23+ colorine.Prefixes {
24+ // verbose
25+ "git" : VerboseColor ,
26+ "hg" : VerboseColor ,
27+ "svn" : VerboseColor ,
28+ "darcs" : VerboseColor ,
29+ "pijul" : VerboseColor ,
30+ "bzr" : VerboseColor ,
31+ "fossil" : VerboseColor ,
32+ "skip" : VerboseColor ,
33+ "cd" : VerboseColor ,
34+ "resolved" : VerboseColor ,
35+ // notice
36+ "authorized" : NoticeColor ,
37+ // warn
38+ "open" : WarnColor ,
39+ "exists" : WarnColor ,
40+ "warning" : WarnColor ,
41+ // error
42+ "error" : ErrorColor ,
43+ },
44+ InfoColor , // default is info
45+ )
2946
30- "error" : colorine .Error ,
31- }, colorine .Info )
47+ loggerWithoutColor = colorine .NewLogger (
48+ colorine.Prefixes {},
49+ NoColor ,
50+ )
51+ )
3252
3353func init () {
54+ SelectLogger ()
55+ }
56+
57+ func SelectLogger () {
58+ v := os .Getenv ("NO_COLOR" )
59+
60+ if strings .ToLower (v ) == "true" {
61+ logger = loggerWithoutColor
62+ }
63+
3464 SetOutput (os .Stderr )
3565}
3666
@@ -39,12 +69,12 @@ func SetOutput(w io.Writer) {
3969 logger .SetOutput (w )
4070}
4171
42- // Log output
72+ // Log outputs log
4373func Log (prefix , message string ) {
4474 logger .Log (prefix , message )
4575}
4676
47- // Logf output log with format
77+ // Logf outputs log with format
4878func Logf (prefix , msg string , args ... interface {}) {
4979 Log (prefix , fmt .Sprintf (msg , args ... ))
5080}
0 commit comments