Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions logs/encoders/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}

Expand Down