go.ligato.io/vpp-agent/v3@v3.5.0/pkg/debug/section.go (about) 1 package debug 2 3 import ( 4 "os" 5 "strings" 6 ) 7 8 const envDebug = "DEBUG" 9 10 func init() { 11 if os.Getenv("DEBUG_ENABLED") != "" { 12 Enable() 13 } 14 } 15 16 // IsEnabled checks whether the debug flag is set or not. 17 func IsEnabled() bool { 18 return os.Getenv(envDebug) != "" 19 } 20 21 // Enable sets the DEBUG env var to true. 22 func Enable() { 23 if IsEnabled() { 24 return 25 } 26 os.Setenv(envDebug, "1") 27 } 28 29 // Disable sets the DEBUG env var to false. 30 func Disable() { 31 os.Setenv(envDebug, "") 32 } 33 34 // IsEnabledFor returns true if DEBUG env var contains all sections. 35 func IsEnabledFor(sections ...string) bool { 36 env := os.Getenv(envDebug) 37 if env == "" { 38 return false 39 } 40 for _, s := range sections { 41 if !strings.Contains(env, s) { 42 return false 43 } 44 } 45 return true 46 }