fix: fix log output (#2424)

master
chen quan 2 years ago committed by GitHub
parent 1b344a8851
commit 68e15360c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,12 +1,12 @@
package logx package logx
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"log" "log"
"path" "path"
"strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -329,7 +329,7 @@ func writePlainAny(writer io.Writer, level string, val interface{}, fields ...st
} }
func writePlainText(writer io.Writer, level, msg string, fields ...string) { func writePlainText(writer io.Writer, level, msg string, fields ...string) {
var buf strings.Builder var buf bytes.Buffer
buf.WriteString(getTimestamp()) buf.WriteString(getTimestamp())
buf.WriteByte(plainEncodingSep) buf.WriteByte(plainEncodingSep)
buf.WriteString(level) buf.WriteString(level)
@ -345,13 +345,14 @@ func writePlainText(writer io.Writer, level, msg string, fields ...string) {
return return
} }
if _, err := fmt.Fprint(writer, buf.String()); err != nil { if _, err := writer.Write(buf.Bytes()); err != nil {
log.Println(err.Error()) log.Println(err.Error())
} }
} }
func writePlainValue(writer io.Writer, level string, val interface{}, fields ...string) { func writePlainValue(writer io.Writer, level string, val interface{}, fields ...string) {
var buf strings.Builder var buf bytes.Buffer
buf.WriteString(getTimestamp()) buf.WriteString(getTimestamp())
buf.WriteByte(plainEncodingSep) buf.WriteByte(plainEncodingSep)
buf.WriteString(level) buf.WriteString(level)
@ -371,7 +372,7 @@ func writePlainValue(writer io.Writer, level string, val interface{}, fields ...
return return
} }
if _, err := fmt.Fprint(writer, buf.String()); err != nil { if _, err := writer.Write(buf.Bytes()); err != nil {
log.Println(err.Error()) log.Println(err.Error())
} }
} }

Loading…
Cancel
Save