Skip to content

Commit

Permalink
Add error returning to writeln
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Cruz committed Jul 6, 2020
1 parent fc56c56 commit d8724cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion logs/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ func (c *connWriter) WriteMsg(when time.Time, msg string, level int) error {
defer c.innerWriter.Close()
}

c.lg.writeln(when, msg)
_, err := c.lg.writeln(when, msg)
if err != nil {
return err
}
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions logs/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ func newLogWriter(wr io.Writer) *logWriter {
return &logWriter{writer: wr}
}

func (lg *logWriter) writeln(when time.Time, msg string) {
func (lg *logWriter) writeln(when time.Time, msg string) (int, error) {
lg.Lock()
h, _, _ := formatTimeHeader(when)
lg.writer.Write(append(append(h, msg...), '\n'))
n, err := lg.writer.Write(append(append(h, msg...), '\n'))
lg.Unlock()
return n, err
}

const (
Expand Down

0 comments on commit d8724cb

Please sign in to comment.