package log import ( "fmt" "strconv" "text/template" "kumoly.io/core/log/color" ) func (l *Logger) M(s interface{}, attrs ...color.Attribute) string { if !l.color { return fmt.Sprint(s) } style := "" for i, v := range attrs { if i >= 3 { break } if i > 0 { style += ";" } style = style + strconv.Itoa(int(v)) } return fmt.Sprintf("\033[%sm%s\033[0m", style, s) } func setColorMap(funcMap template.FuncMap, color bool) { if color { funcMap["red"] = func() string { return "\033[91m" } funcMap["redl"] = func() string { return "\033[31m" } funcMap["green"] = func() string { return "\033[92m" } funcMap["yellow"] = func() string { return "\033[93m" } funcMap["blue"] = func() string { return "\033[94m" } funcMap["magenta"] = func() string { return "\033[95m" } funcMap["cyan"] = func() string { return "\033[96m" } funcMap["white"] = func() string { return "\033[97m" } funcMap["reset"] = func() string { return "\033[0m" } return } funcMap["red"] = func() string { return "" } funcMap["redl"] = func() string { return "" } funcMap["green"] = func() string { return "" } funcMap["yellow"] = func() string { return "" } funcMap["blue"] = func() string { return "" } funcMap["magenta"] = func() string { return "" } funcMap["cyan"] = func() string { return "" } funcMap["white"] = func() string { return "" } funcMap["reset"] = func() string { return "" } } // func