diff --git a/logs/encoders/base.go b/logs/encoders/base.go index 0173994..eb77e37 100644 --- a/logs/encoders/base.go +++ b/logs/encoders/base.go @@ -82,18 +82,24 @@ func (b *baseEncoder) castToString(arg any) string { // printLog prints the given msgBuffer to the given outputType (stdout or stderr). // If 'file' is not nil, the message is written to the file. func (b *baseEncoder) printLog(outType s.OutputType, msgBuffer *bytes.Buffer, file *os.File) { + var err error + switch outType { case s.StdOutput: - _, _ = os.Stdout.Write(msgBuffer.Bytes()) + _, err = os.Stdout.Write(msgBuffer.Bytes()) case s.StdErrOutput: - _, _ = os.Stderr.Write(msgBuffer.Bytes()) + _, err = os.Stderr.Write(msgBuffer.Bytes()) case s.FileOutput: if file == nil { - _, _ = os.Stderr.Write([]byte("error: file is nil")) + _, _ = os.Stderr.Write([]byte("tiny-logger-err: given out file is nil")) return } - _, _ = file.Write(msgBuffer.Bytes()) + _, err = file.Write(msgBuffer.Bytes()) + } + + if err != nil { + _, _ = os.Stderr.Write([]byte("tiny-logger-err: " + err.Error() + "\n")) } }