2021-02-04 00:10:13 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
|
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2021-10-11 21:41:56 +08:00
|
|
|
"github.com/gogf/gf/v2/internal/command"
|
2021-02-04 00:10:13 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-10-12 17:25:45 +08:00
|
|
|
// Debug key for checking if in debug mode.
|
|
|
|
commandEnvKeyForDebugKey = "gf.debug"
|
2021-02-04 00:10:13 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// isDebugEnabled marks whether GoFrame debug mode is enabled.
|
|
|
|
isDebugEnabled = false
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// Debugging configured.
|
2021-06-26 12:08:18 +08:00
|
|
|
value := command.GetOptWithEnv(commandEnvKeyForDebugKey)
|
2021-02-04 00:10:13 +08:00
|
|
|
if value == "" || value == "0" || value == "false" {
|
|
|
|
isDebugEnabled = false
|
|
|
|
} else {
|
|
|
|
isDebugEnabled = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsDebugEnabled checks and returns whether debug mode is enabled.
|
|
|
|
// The debug mode is enabled when command argument "gf.debug" or environment "GF_DEBUG" is passed.
|
|
|
|
func IsDebugEnabled() bool {
|
|
|
|
return isDebugEnabled
|
|
|
|
}
|
2022-07-04 21:18:20 +08:00
|
|
|
|
|
|
|
// SetDebugEnabled enables/disables the internal debug info.
|
|
|
|
func SetDebugEnabled(enabled bool) {
|
|
|
|
isDebugEnabled = enabled
|
|
|
|
}
|