github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/utils/debug.go (about)

     1  package utils
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/Sirupsen/logrus"
     7  )
     8  
     9  // EnableDebug sets the DEBUG env var to true
    10  // and makes the logger to log at debug level.
    11  func EnableDebug() {
    12  	os.Setenv("DEBUG", "1")
    13  	logrus.SetLevel(logrus.DebugLevel)
    14  }
    15  
    16  // DisableDebug sets the DEBUG env var to false
    17  // and makes the logger to log at info level.
    18  func DisableDebug() {
    19  	os.Setenv("DEBUG", "")
    20  	logrus.SetLevel(logrus.InfoLevel)
    21  }
    22  
    23  // IsDebugEnabled checks whether the debug flag is set or not.
    24  func IsDebugEnabled() bool {
    25  	return os.Getenv("DEBUG") != ""
    26  }