输出对应err

This commit is contained in:
wanna
2021-07-14 21:28:23 +08:00
parent 9b2497bc57
commit 30dbccf99e
2 changed files with 18 additions and 5 deletions

View File

@ -228,7 +228,9 @@ func (l *Logger) printToWriter(ctx context.Context, input *HandlerInput) {
}
// Allow output to stdout?
if l.config.StdoutPrint {
input.Stdout()
if err := input.Stdout(); err != nil {
intlog.Error(ctx, err)
}
}
} else {
if _, err := l.config.Writer.Write(input.Buffer().Bytes()); err != nil {

View File

@ -10,6 +10,7 @@ import (
"bytes"
"context"
"github.com/fatih/color"
"github.com/gogf/gf/internal/intlog"
"os"
"time"
)
@ -59,12 +60,22 @@ func (i *HandlerInput) Buffer() *bytes.Buffer {
}
// Stdout print log to console
func (i *HandlerInput) Stdout() {
_, _ = os.Stdout.Write([]byte(i.TimeFormat))
func (i *HandlerInput) Stdout() error {
if _, err := os.Stdout.Write([]byte(i.TimeFormat)); err != nil {
intlog.Error(i.Ctx, err)
return err
}
fg := i.getLevelFormatColor()
_, _ = color.New(fg).Print(" " + i.LevelFormat + " ")
if _, err := color.New(fg).Print(" " + i.LevelFormat + " "); err != nil {
intlog.Error(i.Ctx, err)
return err
}
msg := i.GetContent()
_, _ = os.Stdout.Write(msg.Bytes())
if _, err := os.Stdout.Write(msg.Bytes()); err != nil {
intlog.Error(i.Ctx, err)
return err
}
return nil
}
// GetContent returns the primary content.