This repository has been archived on 2024-04-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
elektron/elektronLogging/ElektronFormatter.go
balandi1 b9592ed31c Removed Log Color Codes
Since the color codes were displayed in an inappropriate manner,
removed them from all logs
.
2019-11-26 18:12:55 -05:00

36 lines
793 B
Go

package elektronLogging
import (
"bytes"
"fmt"
"strings"
log "github.com/sirupsen/logrus"
)
type ElektronFormatter struct {
TimestampFormat string
}
func (f ElektronFormatter) Format(entry *log.Entry) ([]byte, error) {
var b *bytes.Buffer
if entry.Buffer != nil {
b = entry.Buffer
} else {
b = &bytes.Buffer{}
}
level := fmt.Sprintf("[%s]:", strings.ToUpper(entry.Level.String()))
message := strings.Join([]string{level, entry.Time.Format(f.TimestampFormat), entry.Message, " "}, " ")
var formattedFields []string
for key, value := range entry.Data {
formattedFields = append(formattedFields, strings.Join([]string{key, value.(string)}, "="))
}
b.WriteString(message)
b.WriteString(strings.Join(formattedFields, ", "))
b.WriteByte('\n')
return b.Bytes(), nil
}