formatter: drop internalFormatter
This commit is contained in:
+1
-4
@@ -18,9 +18,6 @@ type Formatter interface {
|
|||||||
Format(*Entry) ([]byte, error)
|
Format(*Entry) ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type internalFormatter struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is to not silently overwrite `time`, `msg` and `level` fields when
|
// This is to not silently overwrite `time`, `msg` and `level` fields when
|
||||||
// dumping it. If this code wasn't there doing:
|
// dumping it. If this code wasn't there doing:
|
||||||
//
|
//
|
||||||
@@ -33,7 +30,7 @@ type internalFormatter struct {
|
|||||||
//
|
//
|
||||||
// It's not exported because it's still using Data in an opionated way. It's to
|
// It's not exported because it's still using Data in an opionated way. It's to
|
||||||
// avoid code duplication between the two default formatters.
|
// avoid code duplication between the two default formatters.
|
||||||
func (f *internalFormatter) prefixFieldClashes(entry *Entry) {
|
func prefixFieldClashes(entry *Entry) {
|
||||||
_, ok := entry.Data["time"]
|
_, ok := entry.Data["time"]
|
||||||
if ok {
|
if ok {
|
||||||
entry.Data["fields.time"] = entry.Data["time"]
|
entry.Data["fields.time"] = entry.Data["time"]
|
||||||
|
|||||||
+1
-2
@@ -6,11 +6,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type JSONFormatter struct {
|
type JSONFormatter struct {
|
||||||
*internalFormatter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
|
func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
|
||||||
f.prefixFieldClashes(entry)
|
prefixFieldClashes(entry)
|
||||||
|
|
||||||
serialized, err := json.Marshal(entry.Data)
|
serialized, err := json.Marshal(entry.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+1
-3
@@ -27,14 +27,12 @@ func miniTS() int {
|
|||||||
type TextFormatter struct {
|
type TextFormatter struct {
|
||||||
// Set to true to bypass checking for a TTY before outputting colors.
|
// Set to true to bypass checking for a TTY before outputting colors.
|
||||||
ForceColors bool
|
ForceColors bool
|
||||||
|
|
||||||
*internalFormatter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *TextFormatter) Format(entry *Entry) ([]byte, error) {
|
func (f *TextFormatter) Format(entry *Entry) ([]byte, error) {
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
|
|
||||||
f.prefixFieldClashes(entry)
|
prefixFieldClashes(entry)
|
||||||
|
|
||||||
if f.ForceColors || IsTerminal() {
|
if f.ForceColors || IsTerminal() {
|
||||||
levelText := strings.ToUpper(entry.Data["level"].(string))[0:4]
|
levelText := strings.ToUpper(entry.Data["level"].(string))[0:4]
|
||||||
|
|||||||
Reference in New Issue
Block a user