Package list golang-github-go-kit-kit / 5098c66
fix(shipping): use `log.NewSyncWriter` in example 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. Terin Stock 4 years ago
1 changed file(s) with 1 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
66 "net/http"
77 "os"
88 "os/signal"
9 "sync"
109 "syscall"
1110 "time"
1211
4544 flag.Parse()
4645
4746 var logger log.Logger
48 logger = log.NewLogfmtLogger(os.Stderr)
49 logger = &serializedLogger{Logger: logger}
47 logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr))
5048 logger = log.With(logger, "ts", log.DefaultTimestampUTC)
5149
5250 var (
199197 panic(err)
200198 }
201199 }
202
203 type serializedLogger struct {
204 mtx sync.Mutex
205 log.Logger
206 }
207
208 func (l *serializedLogger) Log(keyvals ...interface{}) error {
209 l.mtx.Lock()
210 defer l.mtx.Unlock()
211 return l.Logger.Log(keyvals...)
212 }