Esempio n. 1
0
func main() {
	fmt.Println("# Consistently assigning unique colors to strings:")
	for _, ape := range getScientificApes() {
		fmt.Println(golor.Colorize(ape, golor.AssignColor(ape), -1))
	}
}
Esempio n. 2
0
func handleSystail(record map[string]interface{}, options MessagePrinterOptions) bool {
	text := record["text"].(string)
	process := record["name"].(string)
	node := record["node_id"].(string)
	severity := ""

	if len(options.NodeID) > 0 && node != options.NodeID {
		return false
	}

	if !options.LogyardVerbose && process == "logyard" && strings.Contains(text, "INFO") {
		return false
	}

	// TODO: hide ip addr in micro cloud.

	if strings.Contains(process, "nginx") {
		// FIXME: nginx logs reflect requests to not only vcap
		// processes (eg: cc and services), but also deployed
		// apps. the purpose of `kato tail` is to tail the log of
		// vcap and other core processes only, not the deployed
		// apps. perhaps we could redirect app requests to a
		// different log file?
		switch {
		case strings.Contains(text, "[error]"):
			severity = "ERROR"
		case strings.Contains(text, "No such file or directory"):
			fallthrough
		case strings.Contains(text, "404"):
			severity = "WARN"
		default:
		}
	} else {
		switch {
		case strings.Contains(text, "ERROR"):
			severity = "ERROR"
		case strings.Contains(text, "WARN"):
			severity = "WARN"
		default:
		}
	}

	// Strip non-essential data
	if !options.Raw {
		for _, re := range datetimePatterns {
			res := re.FindStringSubmatch(text)
			if len(res) > 1 {
				text = res[1]
				break
			}
		}
	}

	if !options.NoColor {
		record["node_id"] = golor.Colorize(node, golor.GRAY, -1)
		switch severity {
		case "ERROR":
			record["text"] = golor.Colorize(text, golor.RED, -1)
		case "WARN":
			// yellow
			record["text"] = golor.Colorize(text, golor.YELLOW, -1)
		default:
			record["text"] = text
		}

		// Assign an unique color to the process name
		record["name"] = golor.Colorize(process, golor.AssignColor(process), -1)
	}
	return true
}