Skip to content

Commit

Permalink
refactor: use early return pattern (#10591)
Browse files Browse the repository at this point in the history
(cherry picked from commit 94348df)
  • Loading branch information
amertner authored and powersj committed Feb 16, 2022
1 parent 85456da commit 8ee5d01
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ func (t *telegrafLog) Write(b []byte) (n int, err error) {
func (t *telegrafLog) Close() error {
stdErrWriter := os.Stderr
// avoid closing stderr
if t.internalWriter != stdErrWriter {
closer, isCloser := t.internalWriter.(io.Closer)
if !isCloser {
return errors.New("the underlying writer cannot be closed")
}
return closer.Close()
if t.internalWriter == stdErrWriter {
return nil
}

closer, isCloser := t.internalWriter.(io.Closer)
if !isCloser {
return errors.New("the underlying writer cannot be closed")
}
return nil
return closer.Close()
}

// newTelegrafWriter returns a logging-wrapped writer.
Expand Down

0 comments on commit 8ee5d01

Please sign in to comment.