Esempio n. 1
0
func main() {
	fmt.Println("# Printing 16 colors ...")
	fmt.Println(golor.Colorize("GRAY", golor.GRAY, -1))
	fmt.Println(golor.Colorize("RED", golor.R, -1))
	fmt.Println(golor.Colorize("GREEN", golor.G, -1))
	fmt.Println(golor.Colorize("BLUE", golor.BLUE, -1))
	fmt.Println(golor.Colorize("MAGENTA", golor.M, -1))
	fmt.Println(golor.Colorize("YELLOW", golor.Y, -1))
	fmt.Println(golor.Colorize("CYAN", golor.C, -1))
	fmt.Println(golor.Colorize("BLACK", golor.BLACK, golor.WHITE))
	fmt.Println(golor.Colorize("WHITE", golor.WHITE, -1))
	fmt.Println(golor.Colorize("LOWEST", golor.RGB(0, 0, 0), golor.WHITE))
	fmt.Println(golor.Colorize("HIGHEST", golor.RGB(5, 5, 5), -1))
	// fmt.Println(golor.Colorize("TEST", 16, -1))
	fmt.Println("# Now printing 256 colors ...")
	time.Sleep(time.Second)
	for i := 255; i >= 0; i-- {
		fmt.Println(golor.Colorize("Foreground", i, -1))
		fmt.Println(golor.Colorize("Background", -1, i))
	}
}
Esempio n. 2
0
func printStatus(name, nodeip string, info statecache.StateInfo) error {
	rev, err := strconv.Atoi(info["rev"])
	if err != nil {
		return fmt.Errorf("Corrupt drain status: %v", err)
	}
	state := info["name"]

	fmt.Printf("%-20s\t%s\t%s[%d]", name, nodeip, state, rev)
	if error, ok := info["error"]; ok {
		fmt.Printf("\t%s", golor.Colorize(error, golor.RGB(5, 0, 0), -1))
	}
	fmt.Println()
	return nil
}
Esempio n. 3
0
// Print a message from logyard streams
func (p MessagePrinter) Print(msg zmqpubsub.Message) error {
	if p.options.JSON {
		key, value := msg.Key, msg.Value
		if !p.options.NoColor {
			key = golor.Colorize(msg.Key, golor.RGB(0, 4, 4), -1)
		}
		fmt.Printf("%s %s\n", key, value)
		return nil
	}

	// TODO: somehow use {apptail,systail}.Message and {sieve}.Event here.
	var record map[string]interface{}

	if err := json.Unmarshal([]byte(msg.Value), &record); err != nil {
		p.PrintInternalError(fmt.Sprintf(
			"ERROR decoding json from message (key '%v'): %v",
			msg.Key, msg.Value))
		return nil
	}

	key := msg.Key
	if strings.Contains(key, ".") {
		key = strings.SplitN(key, ".", 2)[0]
	}

	if tmpl, ok := p.templates[key]; ok {
		var buf bytes.Buffer

		if p.filterFn(key, record, p.options) {
			if err := tmpl.Execute(&buf, record); err != nil {
				return err
			}
			s := string(buf.Bytes())
			if p.options.ShowTime {
				s = fmt.Sprintf("%s %s", time.Now(), s)
			}
			fmt.Println(s)
		}
		return nil
	}
	return fmt.Errorf("no format added for key: %s", key)
}