github.com/wangyougui/gf/v2@v2.6.5/internal/utils/utils_debug.go (about) 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/wangyougui/gf. 6 7 package utils 8 9 import ( 10 "github.com/wangyougui/gf/v2/internal/command" 11 ) 12 13 const ( 14 // Debug key for checking if in debug mode. 15 commandEnvKeyForDebugKey = "gf.debug" 16 ) 17 18 var ( 19 // isDebugEnabled marks whether GoFrame debug mode is enabled. 20 isDebugEnabled = false 21 ) 22 23 func init() { 24 // Debugging configured. 25 value := command.GetOptWithEnv(commandEnvKeyForDebugKey) 26 if value == "" || value == "0" || value == "false" { 27 isDebugEnabled = false 28 } else { 29 isDebugEnabled = true 30 } 31 } 32 33 // IsDebugEnabled checks and returns whether debug mode is enabled. 34 // The debug mode is enabled when command argument "gf.debug" or environment "GF_DEBUG" is passed. 35 func IsDebugEnabled() bool { 36 return isDebugEnabled 37 } 38 39 // SetDebugEnabled enables/disables the internal debug info. 40 func SetDebugEnabled(enabled bool) { 41 isDebugEnabled = enabled 42 }