MCPcopy Index your code
hub / github.com/cloudfoundry/cli / ToLog

Method ToLog

cf/api/logs/log_cache_message.go:39–89  ·  view source on GitHub ↗
(loc *time.Location)

Source from the content-addressed store, hash-verified

37}
38
39func (m *LogCacheMessage) ToLog(loc *time.Location) string {
40 logMsg := m.msg
41
42 sourceName := logMsg.SourceType()
43 sourceID := logMsg.SourceInstance()
44 t := logMsg.Timestamp()
45 timeFormat := "2006-01-02T15:04:05.00-0700"
46 timeString := t.In(loc).Format(timeFormat)
47
48 var logHeader string
49
50 if sourceID == "" {
51 logHeader = fmt.Sprintf("%s [%s]", timeString, sourceName)
52 } else {
53 logHeader = fmt.Sprintf("%s [%s/%s]", timeString, sourceName, sourceID)
54 }
55
56 coloredLogHeader := m.colorLogger.LogSysHeaderColor(logHeader)
57
58 // Calculate padding
59 longestHeader := fmt.Sprintf("%s [HEALTH/10] ", timeFormat)
60 expectedHeaderLength := utf8.RuneCountInString(longestHeader)
61 headerPadding := strings.Repeat(" ", max(0, expectedHeaderLength-utf8.RuneCountInString(logHeader)))
62
63 logHeader += headerPadding
64 coloredLogHeader += headerPadding
65
66 msgText := logMsg.Message()
67 msgText = strings.TrimRight(msgText, "\r\n")
68
69 msgLines := strings.Split(msgText, "\n")
70 contentPadding := strings.Repeat(" ", utf8.RuneCountInString(logHeader))
71
72 logType := logMsg.Type()
73 if logType != "ERR" {
74 logType = "OUT"
75 }
76
77 logContent := fmt.Sprintf("%s %s", logType, msgLines[0])
78 for _, msgLine := range msgLines[1:] {
79 logContent = fmt.Sprintf("%s\n%s%s", logContent, contentPadding, msgLine)
80 }
81
82 if logType == "ERR" {
83 logContent = m.colorLogger.LogStderrColor(logContent)
84 } else {
85 logContent = m.colorLogger.LogStdoutColor(logContent)
86 }
87
88 return fmt.Sprintf("%s%s", coloredLogHeader, logContent)
89}

Callers

nothing calls this directly

Calls 9

maxFunction · 0.85
SourceTypeMethod · 0.65
SourceInstanceMethod · 0.65
TimestampMethod · 0.65
LogSysHeaderColorMethod · 0.65
MessageMethod · 0.65
TypeMethod · 0.65
LogStderrColorMethod · 0.65
LogStdoutColorMethod · 0.65

Tested by

no test coverage detected