utils_debug.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package utils
  7. import (
  8. "github.com/gogf/gf/internal/command"
  9. )
  10. const (
  11. commandEnvKeyForDebugKey = "gf.debug" // Debug key for checking if in debug mode.
  12. StackFilterKeyForGoFrame = "github.com/gogf/gf@" // Stack filtering key for all GoFrame module paths.
  13. )
  14. var (
  15. // isDebugEnabled marks whether GoFrame debug mode is enabled.
  16. isDebugEnabled = false
  17. )
  18. func init() {
  19. // Debugging configured.
  20. value := command.GetOptWithEnv(commandEnvKeyForDebugKey)
  21. if value == "" || value == "0" || value == "false" {
  22. isDebugEnabled = false
  23. } else {
  24. isDebugEnabled = true
  25. }
  26. }
  27. // IsDebugEnabled checks and returns whether debug mode is enabled.
  28. // The debug mode is enabled when command argument "gf.debug" or environment "GF_DEBUG" is passed.
  29. func IsDebugEnabled() bool {
  30. return isDebugEnabled
  31. }