// Copyright (c) The EfficientGo Authors.// Licensed under the Apache License 2.0.// Initially copied from Thanos//// Copyright (c) The Thanos Authors.// Licensed under the Apache License 2.0.package logerrcaptureimport ()// Logger interface compatible with go-kit/logger.typeLoggerinterface {Log(keyvals ...interface{}) error}type doFunc func() error// Do is making sure we log every error, even those from best effort tiny functions.func ( Logger, doFunc, string, ...interface{}) { := ()if == nil {return }// For os closers, it's a common case to double close. From reliability purpose this is not a problem it may only indicate // surprising execution path.iferrors.Is(, os.ErrClosed) {return } _ = .Log("msg", "detected do error", "err", errors.Wrap(, fmt.Sprintf(, ...)))}// ExhaustClose closes the io.ReadCloser with a log message on error but exhausts the reader before.func ( Logger, io.ReadCloser, string, ...interface{}) { , := io.Copy(io.Discard, )if != nil { _ = .Log("msg", "failed to exhaust reader, performance may be impeded", "err", ) }Do(, .Close, , ...)}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.