Code formatting
This commit is contained in:
parent
ef8bd6ac1f
commit
4d15e59d4c
41 changed files with 472 additions and 475 deletions
|
@ -3,9 +3,9 @@ package elektronLogging
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/fatih/color"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strings"
|
||||
"github.com/fatih/color"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type ElektronFormatter struct {
|
||||
|
@ -13,18 +13,18 @@ type ElektronFormatter struct {
|
|||
}
|
||||
|
||||
func (f ElektronFormatter) getColor(entry *log.Entry) *color.Color {
|
||||
switch entry.Level {
|
||||
case log.InfoLevel:
|
||||
return color.New(color.FgGreen, color.Bold)
|
||||
case log.WarnLevel:
|
||||
return color.New(color.FgYellow, color.Bold)
|
||||
case log.ErrorLevel:
|
||||
return color.New(color.FgRed, color.Bold)
|
||||
case log.FatalLevel:
|
||||
return color.New(color.FgRed, color.Bold)
|
||||
default:
|
||||
return color.New(color.FgWhite, color.Bold)
|
||||
}
|
||||
switch entry.Level {
|
||||
case log.InfoLevel:
|
||||
return color.New(color.FgGreen, color.Bold)
|
||||
case log.WarnLevel:
|
||||
return color.New(color.FgYellow, color.Bold)
|
||||
case log.ErrorLevel:
|
||||
return color.New(color.FgRed, color.Bold)
|
||||
case log.FatalLevel:
|
||||
return color.New(color.FgRed, color.Bold)
|
||||
default:
|
||||
return color.New(color.FgWhite, color.Bold)
|
||||
}
|
||||
}
|
||||
func (f ElektronFormatter) Format(entry *log.Entry) ([]byte, error) {
|
||||
var b *bytes.Buffer
|
||||
|
@ -35,19 +35,18 @@ func (f ElektronFormatter) Format(entry *log.Entry) ([]byte, error) {
|
|||
b = &bytes.Buffer{}
|
||||
}
|
||||
|
||||
levelColor := f.getColor(entry)
|
||||
level := levelColor.Sprintf("[%s]:",strings.ToUpper(entry.Level.String()))
|
||||
message := fmt.Sprintf("%s %s ",level,entry.Time.Format(f.TimestampFormat))
|
||||
if entry.Message != "" {
|
||||
message = fmt.Sprintf("%s %s %s ",level,entry.Time.Format(f.TimestampFormat), entry.Message)
|
||||
}
|
||||
levelColor := f.getColor(entry)
|
||||
level := levelColor.Sprintf("[%s]:", strings.ToUpper(entry.Level.String()))
|
||||
message := fmt.Sprintf("%s %s ", level, entry.Time.Format(f.TimestampFormat))
|
||||
if entry.Message != "" {
|
||||
message = fmt.Sprintf("%s %s %s ", level, entry.Time.Format(f.TimestampFormat), entry.Message)
|
||||
}
|
||||
var formattedFields []string
|
||||
for key, value := range entry.Data {
|
||||
formattedFields = append(formattedFields,
|
||||
strings.Join([]string{key, fmt.Sprintf("%s", value)}, "="))
|
||||
formattedFields = append(formattedFields,
|
||||
strings.Join([]string{key, fmt.Sprintf("%s", value)}, "="))
|
||||
}
|
||||
|
||||
|
||||
|
||||
b.WriteString(message)
|
||||
b.WriteString(strings.Join(formattedFields, ", "))
|
||||
b.WriteByte('\n')
|
||||
|
|
Reference in a new issue