Пример #1
0
func extractLogHeader(msg *logmessage.Message) (logHeader, coloredLogHeader string) {
	logMsg := msg.GetLogMessage()
	sourceType := msg.GetShortSourceTypeName()
	sourceId := logMsg.GetSourceId()
	t := time.Unix(0, logMsg.GetTimestamp())
	timeFormat := TIMESTAMP_FORMAT
	timeString := t.Format(timeFormat)

	logHeader = fmt.Sprintf("%s [%s]", timeString, sourceType)
	coloredLogHeader = terminal.LogSysHeaderColor(logHeader)

	if logMsg.GetSourceType() == logmessage.LogMessage_WARDEN_CONTAINER {
		logHeader = fmt.Sprintf("%s [%s/%s]", timeString, sourceType, sourceId)
		coloredLogHeader = terminal.LogAppHeaderColor(logHeader)
	}

	// Calculate padding
	longestHeader := fmt.Sprintf("%s  [App/0]  ", timeFormat)
	expectedHeaderLength := len(longestHeader)
	padding := strings.Repeat(" ", expectedHeaderLength-len(logHeader))

	logHeader = logHeader + padding
	coloredLogHeader = coloredLogHeader + padding

	return
}