Пример #1
0
// Appending logs to stdout.
func (s *Stdout) Append(log Log) {
	msg := fmt.Sprintf(" {cyan}%s {default}%s {%s}%s[%s] ▶ %s",
		log.Logger.Name,
		log.Time.Format(s.dateformat),
		log.Level.color,
		log.Level.icon,
		log.Level.Name[:4],
		log.Message)

	color.Print(msg).InFormat()
}
Пример #2
0
func TestPrintInFormat(t *testing.T) {
	ch = make(chan string, 1)
	cli.Out = WriterFunc(Write)
	cli.Print("{red}Some text in red. {white}Some text in white. {default}Some text in default color.").InFormat()
	str := <-ch

	expected := "\033[31mSome text in red. \033[0m\033[37mSome text in white. \033[0m\033[39mSome text in default color.\033[0m\n"
	if str != expected {
		t.Error("Expected", expected, "Got", str)
	}

	close(ch)
}
Пример #3
0
func TestPrintIn(t *testing.T) {
	ch = make(chan string, 1)
	cli.Out = WriterFunc(Write)
	cli.Print("this is green text").In("green")
	str := <-ch

	expected := "\033[32mthis is green text\033[0m\n"
	if str != expected {
		t.Error("Expected", expected)
	}

	close(ch)
}
Пример #4
0
func ExamplePrint_inFormat() {
	cli.Print("{red}Some text in red. {white}Some text in white. {default}Some text in default color.").InFormat()
	// prints: Some text in red. Some text in white. Some text in default color.
}
Пример #5
0
func ExamplePrint_in() {
	cli.Print("this is green text").In("green")
	// prints: this is green text
}
Пример #6
0
// Error messages
func Error(msg ...interface{}) {
	cli.Print("ERROR: " + fmt.Sprint(msg...)).In("red")
}
Пример #7
0
// Bullshit that you usually don't want to hear
func Bullshit(msg ...interface{}) {
	if debug && verbose {
		cli.Print(fmt.Sprint(msg...)).In("magenta")
	}
}
Пример #8
0
// Debug messages
func Debug(msg ...interface{}) {
	if debug {
		cli.Print(fmt.Sprint(msg...)).In("blue")
	}
}
Пример #9
0
// Info is usually good
func Info(msg ...interface{}) {
	cli.Print(fmt.Sprint(msg...)).In("green")
}
Пример #10
0
// Warning messages
func Warning(msg ...interface{}) {
	cli.Print("Warning: " + fmt.Sprint(msg...)).In("yellow")
}