github.com/firelizzard18/golangci-lint@v1.10.1/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  	return func(format string, args ...interface{}) {
    34  		logger := NewStderrLog(tag)
    35  		logger.SetLevel(LogLevelDebug)
    36  		logger.Debugf(format, args...)
    37  	}
    38  }
    39  
    40  func HaveDebugTag(tag string) bool {
    41  	return enabledDebugs[tag]
    42  }
    43  
    44  func SetupVerboseLog(log Log, isVerbose bool) {
    45  	if isVerbose {
    46  		log.SetLevel(LogLevelInfo)
    47  	}
    48  }