Skip to content

Commit

Permalink
fix(shipping): use log.NewSyncWriter in example
Browse files Browse the repository at this point in the history
Replace the use of `serializedLogger` with `log.NewSyncWriter` which
provides similar functionality.

`SyncWriter` is chosen over `SyncLogger` to reduce the amount of work
contained within a lock.
  • Loading branch information
terinjokes committed May 6, 2017
1 parent fac7515 commit 342faa0
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions shipping/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"os"
"os/signal"
"sync"
"syscall"
"time"

Expand Down Expand Up @@ -46,8 +45,7 @@ func main() {
flag.Parse()

var logger log.Logger
logger = log.NewLogfmtLogger(os.Stderr)
logger = &serializedLogger{Logger: logger}
logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr))
logger = log.With(logger, "ts", log.DefaultTimestampUTC)

var (
Expand Down Expand Up @@ -200,14 +198,3 @@ func storeTestData(r cargo.Repository) {
panic(err)
}
}

type serializedLogger struct {
mtx sync.Mutex
log.Logger
}

func (l *serializedLogger) Log(keyvals ...interface{}) error {
l.mtx.Lock()
defer l.mtx.Unlock()
return l.Logger.Log(keyvals...)
}

0 comments on commit 342faa0

Please sign in to comment.