예제 #1
0
파일: glog.go 프로젝트: rshmelev/glog
func (l *loggingT) getColorByte(s severity, b []byte) []byte {
	var c gocolorize.Colorize
	switch s {
	case warningLog:
		c = gocolorize.NewColor("yellow")
	case errorLog:
		c = gocolorize.NewColor("red")
	case fatalLog:
		c = gocolorize.NewColor("magenta")
	default:
		c = gocolorize.NewColor("green")
	}
	return []byte(c.Paint(string(b)))
}
예제 #2
0
func main() {
	// one way to define a stateful colorizer
	var green gocolorize.Colorize
	green.SetColor(gocolorize.Green)
	g := green.Paint

	// Another way to do it
	red := gocolorize.Colorize{Fg: gocolorize.Red}
	r := red.Paint

	// now with string construction
	green_black := gocolorize.Colorize{Fg: gocolorize.Blue}
	// toggle attributes
	green_black.ToggleUnderline()
	b := green_black.Paint

	//all in 1 line
	c := gocolorize.NewColor("yellow:black").Paint

	//r := gocolorize.COLOR_RED

	fmt.Println(b("On the twelfth day of Christmas"))
	fmt.Println(b("my true love sent to me:"))
	fmt.Println(g("Twelve"), c("Drummers"), r("Drumming"))
	fmt.Println(g("Eleven"), c("Pipers"), r("Piping"))
	fmt.Println(g("Ten"), c("Lords"), r("a Leaping"))
	fmt.Println(g("Nine"), c("Ladies"), r("Dancing"))
	fmt.Println(g("Eight"), c("Maids"), r("a Milking"))
	fmt.Println(g("Seven"), c("Swans"), r("a Swimming"))
	fmt.Println(g("Six"), c("Geese"), r("a Laying"))
	fmt.Println(g("Five"), c("Golden"), r("Rings"))
	fmt.Println(g("Four"), c("Calling"), r("Birds"))
	fmt.Println(g("Three"), c("French"), r("Hens"))
	fmt.Println(g("Two"), c("Turtle"), r("Doves"))
	fmt.Println(b("and a Partridge in a Pear Tree"))

}
예제 #3
0
func ColorSuccess(message string) string {
	success := gocolorize.Colorize{Fg: gocolorize.Green}
	return success.Paint(message)
}
예제 #4
0
func ColorError(message string) string {
	err := gocolorize.Colorize{Fg: gocolorize.Red}
	err.ToggleBold()
	return err.Paint(message)
}
예제 #5
0
func ColorWarning(message string) string {
	warning := gocolorize.Colorize{Fg: gocolorize.Yellow}
	return warning.Paint(message)
}
예제 #6
0
func ColorInfo(message string) string {
	info := gocolorize.Colorize{Fg: gocolorize.Magenta}
	return info.Paint(message)
}
예제 #7
0
func newColorLogger(out io.Writer, severity string, color gocolorize.Color) *log.Logger {
	c := gocolorize.Colorize{Fg: color}
	return log.New(out, c.Paint("severity:"+severity)+"\t", log.Ldate|log.Ltime|log.Lshortfile)
}