mirror of
https://github.com/octoleo/restic.git
synced 2024-11-29 08:14:03 +00:00
Reduce overhead of debug calls if no log is enabled
In case no debug log is configured, then calls to debug.Log only incur the costs to check a single boolean flag making the call really cheap.
This commit is contained in:
parent
1823b8195c
commit
9ad8250a78
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user