github.com/RajatVaryani/mattermost-server@v5.11.1+incompatible/mlog/human/entry.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package human 5 6 import ( 7 "fmt" 8 "strings" 9 "time" 10 11 "github.com/mattermost/mattermost-server/mlog" 12 ) 13 14 type LogEntry struct { 15 Time time.Time 16 Level string 17 Message string 18 Caller string 19 Fields []mlog.Field 20 } 21 22 // Provide default string representation. Used by SimpleWriter 23 func (f LogEntry) String() string { 24 var sb strings.Builder 25 if !f.Time.IsZero() { 26 sb.WriteString(f.Time.Format(time.RFC3339Nano)) 27 sb.WriteRune(' ') 28 } 29 if f.Level != "" { 30 sb.WriteString(f.Level) 31 sb.WriteRune(' ') 32 } 33 if f.Caller != "" { 34 sb.WriteString(f.Caller) 35 sb.WriteRune(' ') 36 } 37 for _, field := range f.Fields { 38 sb.WriteString(field.Key) 39 sb.WriteRune('=') 40 sb.WriteString(fmt.Sprint(field.Interface)) 41 sb.WriteRune(' ') 42 } 43 if f.Message != "" { 44 // If the message is multiple lines, start the whole message on a new line 45 if strings.ContainsRune(f.Message, '\n') { 46 sb.WriteRune('\n') 47 } 48 sb.WriteString(f.Message) 49 } 50 51 return sb.String() 52 }