1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-25 09:18:55 +00:00

Merge pull request #2931 from MichaelEischer/reduce-debug-overhead

Reduce debug log overhead
This commit is contained in:
Alexander Neumann 2020-10-09 21:35:11 +02:00 committed by GitHub
commit 35655a481b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View file

@ -17,6 +17,7 @@ import (
)
var opts struct {
isEnabled bool
logger *log.Logger
funcs map[string]bool
files map[string]bool
@ -30,6 +31,12 @@ func initDebug() bool {
initDebugLogger()
initDebugTags()
if opts.logger == nil && len(opts.funcs) == 0 && len(opts.files) == 0 {
opts.isEnabled = false
return false
}
opts.isEnabled = true
fmt.Fprintf(os.Stderr, "debug enabled\n")
return true
@ -173,6 +180,10 @@ func checkFilter(filter map[string]bool, key string) bool {
// Log prints a message to the debug log (if debug is enabled).
func Log(f string, args ...interface{}) {
if !opts.isEnabled {
return
}
fn, dir, file, line := getPosition()
goroutine := goroutineNum()

View file

@ -66,7 +66,12 @@ type loggingRoundTripper struct {
// RoundTripper returns a new http.RoundTripper which logs all requests (if
// debug is enabled). When debug is not enabled, upstream is returned.
func RoundTripper(upstream http.RoundTripper) http.RoundTripper {
return loggingRoundTripper{eofDetectRoundTripper{upstream}}
eofRoundTripper := eofDetectRoundTripper{upstream}
if opts.isEnabled {
// only use loggingRoundTripper if the debug log is configured
return loggingRoundTripper{eofRoundTripper}
}
return eofRoundTripper
}
func (tr loggingRoundTripper) RoundTrip(req *http.Request) (res *http.Response, err error) {