-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolorizers_misc.go
62 lines (56 loc) · 1.38 KB
/
colorizers_misc.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 glog
import (
"os"
"strings"
)
// Password colors `password` according to the config. It does not redact it!
//
// Related config setting(s):
//
// - `LoggerConfig.ColorPassword`
func Password(password string) string {
return Wrap(password, LoggerConfig.ColorPassword)
}
// Error colors `err.Error()` according to the config, or returns "nil" if no error was present.
//
// Related config setting(s):
//
// - `LoggerConfig.ColorError`
// - `LoggerConfig.ColorNil`
func Error(err error) string {
if err == nil {
return Wrap("nil", LoggerConfig.ColorNil)
}
return Wrap(err.Error(), LoggerConfig.ColorError)
}
// Reason colors `reason` according to the config.
//
// Related config setting(s):
//
// - `LoggerConfig.ColorReason`
func Reason(reason string) string {
return Wrap(reason, LoggerConfig.ColorReason)
}
// File colors `file` according to the config using the `os.PathSeparator`.
//
// Related config setting(s):
//
// - `LoggerConfig.ColorPathSeparator`
// - `LoggerConfig.ColorPath``
func File(file string) string {
ops := string(os.PathSeparator)
res := ""
for i, pe := range strings.Split(file, ops) {
if pe == "" {
continue
}
if i > 0 {
res += Wrap(ops, LoggerConfig.ColorPathSeparator)
}
res += Wrap(pe, LoggerConfig.ColorPath)
}
if len(file) > 0 && string(file[len(file)-1]) == ops {
res += Wrap(ops, LoggerConfig.ColorPathSeparator)
}
return res
}