fixed visibility of structs.
This commit is contained in:
parent
f084eddd68
commit
5a53998942
9 changed files with 61 additions and 61 deletions
36
logging/elektronFormatter.go
Normal file
36
logging/elektronFormatter.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package logging
|
||||
|
||||
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
|
||||
}
|
Reference in a new issue