MCPcopy Create free account
hub / github.com/ddev/ddev / Format

Method Format

pkg/output/text_formatter.go:83–127  ·  view source on GitHub ↗

Format renders a single log entry. A key named "raw" is discarded here as it's for json consumption.

(entry *log.Entry)

Source from the content-addressed store, hash-verified

81
82// Format renders a single log entry. A key named "raw" is discarded here as it's for json consumption.
83func (f *TextFormatter) Format(entry *log.Entry) ([]byte, error) {
84 var b *bytes.Buffer
85 keys := make([]string, 0, len(entry.Data))
86 for k := range entry.Data {
87 // Discard key named "raw" as it's for json consumption only.
88 if k != "raw" {
89 keys = append(keys, k)
90 }
91 }
92
93 if !f.DisableSorting {
94 sort.Strings(keys)
95 }
96 if entry.Buffer != nil {
97 b = entry.Buffer
98 } else {
99 b = &bytes.Buffer{}
100 }
101
102 prefixFieldClashes(entry.Data)
103
104 f.Do(func() { f.init(entry) })
105
106 isColored := (f.ForceColors || f.isTerminal) && !f.DisableColors
107
108 timestampFormat := f.TimestampFormat
109 if timestampFormat == "" {
110 timestampFormat = defaultTimestampFormat
111 }
112 if isColored {
113 f.printColored(b, entry, keys, timestampFormat)
114 } else {
115 if !f.DisableTimestamp {
116 f.appendKeyValue(b, "time", entry.Time.Format(timestampFormat))
117 }
118 if entry.Message != "" {
119 f.appendValue(b, entry.Message)
120 }
121 for _, key := range keys {
122 f.appendKeyValue(b, key, entry.Data[key])
123 }
124 }
125 b.WriteByte('\n')
126 return b.Bytes(), nil
127}
128
129func (f *TextFormatter) printColored(b *bytes.Buffer, entry *log.Entry, keys []string, _ string) {
130 var levelColor int

Callers 10

createAddonManifestFunction · 0.80
SnapshotMethod · 0.80
StopMethod · 0.80
timeTrackFunction · 0.80
DebugFunction · 0.80
VerboseFunction · 0.80
TestDebugGobDecodeCmdFunction · 0.80
createManifestFileFunction · 0.80
checkCertFileFunction · 0.80
listSnapshotsFunction · 0.80

Calls 5

initMethod · 0.95
printColoredMethod · 0.95
appendKeyValueMethod · 0.95
appendValueMethod · 0.95
prefixFieldClashesFunction · 0.85

Tested by 1

TestDebugGobDecodeCmdFunction · 0.64