Example #1
0
func (s *stenographer) PrettyPrintLog(log chug.LogEntry) {
	components := []string{}

	color, ok := colorLookup[strings.Split(log.Source, ":")[0]]
	if !ok {
		color = say.DefaultStyle
	}

	level := ""
	switch log.LogLevel {
	case lager.INFO:
		level = say.Colorize(color, "%-7s", "[INFO]")
	case lager.DEBUG:
		level = say.Gray("%-7s", "[DEBUG]")
	case lager.ERROR:
		level = say.Red("%-7s", "[ERROR]")
	case lager.FATAL:
		level = say.Red("%-7s", "[FATAL]")
	}

	var timestamp string
	if s.Absolute {
		timestamp = log.Timestamp.Format("01/02 15:04:05.00")
	} else {
		timestamp = log.Timestamp.Sub(s.RelativeTime).String()
		timestamp = fmt.Sprintf("%17s", timestamp)
	}

	components = append(components, say.Colorize(color, "%-16s", log.Source))
	components = append(components, level)
	components = append(components, say.Colorize(color, timestamp))
	components = append(components, say.Gray("%-10s", log.Session))
	components = append(components, say.Colorize(color, log.Message))

	say.Println(0, strings.Join(components, " "))

	if log.Error != nil {
		say.Println(27, say.Red("Error: %s", log.Error.Error()))
	}

	if log.Trace != "" {
		say.Println(27, say.Red(log.Trace))
	}

	if len(log.Data) > 0 && s.Data == "short" {
		dataJSON, _ := json.Marshal(log.Data)
		say.Println(27, string(dataJSON))
	}

	if len(log.Data) > 0 && s.Data == "long" {
		dataJSON, _ := json.MarshalIndent(log.Data, "", "  ")
		say.Println(27, string(dataJSON))
	}
}
Example #2
0
func (s *stenographer) PrettyPrintRaw(raw []byte) {
	say.Println(0, say.Gray(string(raw)))
}