fix
This commit is contained in:
parent
f380226321
commit
660e96877b
|
@ -378,7 +378,7 @@ func TestConsoleWriterConfiguration(t *testing.T) {
|
||||||
|
|
||||||
t.Run("Sets FormatExtra", func(t *testing.T) {
|
t.Run("Sets FormatExtra", func(t *testing.T) {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
w := zerolog.ConsoleWriter{
|
w := zlog.ConsoleWriter{
|
||||||
Out: buf, NoColor: true, PartsOrder: []string{"level", "message"},
|
Out: buf, NoColor: true, PartsOrder: []string{"level", "message"},
|
||||||
FormatExtra: func(evt map[string]interface{}, buf *bytes.Buffer) error {
|
FormatExtra: func(evt map[string]interface{}, buf *bytes.Buffer) error {
|
||||||
buf.WriteString("\nAdditional stacktrace")
|
buf.WriteString("\nAdditional stacktrace")
|
||||||
|
@ -406,14 +406,14 @@ func TestConsoleWriterConfiguration(t *testing.T) {
|
||||||
expectedOutput := "2022-10-20 20:24:50 INF Foobar\n"
|
expectedOutput := "2022-10-20 20:24:50 INF Foobar\n"
|
||||||
evt := `{"time": "2022-10-20 20:24:50", "level": "info", "message": "Foobar"}`
|
evt := `{"time": "2022-10-20 20:24:50", "level": "info", "message": "Foobar"}`
|
||||||
|
|
||||||
of := zerolog.TimeFieldFormat
|
of := zlog.TimeFieldFormat
|
||||||
defer func() {
|
defer func() {
|
||||||
zerolog.TimeFieldFormat = of
|
zlog.TimeFieldFormat = of
|
||||||
}()
|
}()
|
||||||
zerolog.TimeFieldFormat = timeFormat
|
zlog.TimeFieldFormat = timeFormat
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
w := zerolog.ConsoleWriter{Out: buf, NoColor: true, TimeFormat: timeFormat}
|
w := zlog.ConsoleWriter{Out: buf, NoColor: true, TimeFormat: timeFormat}
|
||||||
_, err := w.Write([]byte(evt))
|
_, err := w.Write([]byte(evt))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error when writing output: %s", err)
|
t.Errorf("Unexpected error when writing output: %s", err)
|
||||||
|
|
|
@ -33,7 +33,7 @@ func TestNewWriter(t *testing.T) {
|
||||||
func TestClose(t *testing.T) {
|
func TestClose(t *testing.T) {
|
||||||
buf := bytes.Buffer{}
|
buf := bytes.Buffer{}
|
||||||
w := diode.NewWriter(&buf, 1000, 0, func(missed int) {})
|
w := diode.NewWriter(&buf, 1000, 0, func(missed int) {})
|
||||||
log := zerolog.New(w)
|
log := zlog.New(w)
|
||||||
log.Print("test")
|
log.Print("test")
|
||||||
w.Close()
|
w.Close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,8 +126,8 @@ func RefererHandler(fieldKey string) func(next http.Handler) http.Handler {
|
||||||
func ProtoHandler(fieldKey string) func(next http.Handler) http.Handler {
|
func ProtoHandler(fieldKey string) func(next http.Handler) http.Handler {
|
||||||
return func(next http.Handler) http.Handler {
|
return func(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
log := zerolog.Ctx(r.Context())
|
log := zlog.Ctx(r.Context())
|
||||||
log.UpdateContext(func(c zerolog.Context) zerolog.Context {
|
log.UpdateContext(func(c zlog.Context) zlog.Context {
|
||||||
return c.Str(fieldKey, r.Proto)
|
return c.Str(fieldKey, r.Proto)
|
||||||
})
|
})
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
|
|
|
@ -210,7 +210,7 @@ func TestProtoHandler(t *testing.T) {
|
||||||
l := FromRequest(r)
|
l := FromRequest(r)
|
||||||
l.Log().Msg("")
|
l.Log().Msg("")
|
||||||
}))
|
}))
|
||||||
h = NewHandler(zerolog.New(out))(h)
|
h = NewHandler(zlog.New(out))(h)
|
||||||
h.ServeHTTP(nil, r)
|
h.ServeHTTP(nil, r)
|
||||||
if want, got := `{"proto":"test"}`+"\n", decodeIfBinary(out); want != got {
|
if want, got := `{"proto":"test"}`+"\n", decodeIfBinary(out); want != got {
|
||||||
t.Errorf("Invalid log output, got: %s, want: %s", got, want)
|
t.Errorf("Invalid log output, got: %s, want: %s", got, want)
|
||||||
|
|
|
@ -102,7 +102,7 @@ func (w journalWriter) Write(p []byte) (n int, err error) {
|
||||||
case json.Number:
|
case json.Number:
|
||||||
args[jKey] = fmt.Sprint(value)
|
args[jKey] = fmt.Sprint(value)
|
||||||
default:
|
default:
|
||||||
b, err := zerolog.InterfaceMarshalFunc(value)
|
b, err := zlog.InterfaceMarshalFunc(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
args[jKey] = fmt.Sprintf("[error: %v]", err)
|
args[jKey] = fmt.Sprintf("[error: %v]", err)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue