github.com/elek/golangci-lint@v1.42.2-0.20211208090441-c05b7fcb3a9a/pkg/logutils/logutils.go (about)

     1  package logutils
     2  
     3  import (
     4  	"os"
     5  	"strings"
     6  )
     7  
     8  func getEnabledDebugs() map[string]bool {
     9  	ret := map[string]bool{}
    10  	debugVar := os.Getenv("GL_DEBUG")
    11  	if debugVar == "" {
    12  		return ret
    13  	}
    14  
    15  	for _, tag := range strings.Split(debugVar, ",") {
    16  		ret[tag] = true
    17  	}
    18  
    19  	return ret
    20  }
    21  
    22  var enabledDebugs = getEnabledDebugs()
    23  
    24  type DebugFunc func(format string, args ...interface{})
    25  
    26  func nopDebugf(format string, args ...interface{}) {}
    27  
    28  func Debug(tag string) DebugFunc {
    29  	if !enabledDebugs[tag] {
    30  		return nopDebugf
    31  	}
    32  
    33  	logger := NewStderrLog(tag)
    34  	logger.SetLevel(LogLevelDebug)
    35  
    36  	return func(format string, args ...interface{}) {
    37  		logger.Debugf(format, args...)
    38  	}
    39  }
    40  
    41  func HaveDebugTag(tag string) bool {
    42  	return enabledDebugs[tag]
    43  }
    44  
    45  func SetupVerboseLog(log Log, isVerbose bool) {
    46  	if isVerbose {
    47  		log.SetLevel(LogLevelInfo)
    48  	}
    49  }