From d8ef8a1f5dbec61bb6f52da3529192e91eb97b0d Mon Sep 17 00:00:00 2001 From: John Date: Sat, 22 Feb 2020 14:51:44 +0800 Subject: [PATCH] add gf.debug options and GF_DEBUG env control params for internal logging feature --- errors/gerror/gerror_error.go | 2 +- internal/intlog/intlog.go | 22 +++++++++++----------- net/ghttp/ghttp_server.go | 2 +- os/gview/gview_config.go | 2 ++ 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/errors/gerror/gerror_error.go b/errors/gerror/gerror_error.go index 6b0927872..462b85662 100644 --- a/errors/gerror/gerror_error.go +++ b/errors/gerror/gerror_error.go @@ -132,7 +132,7 @@ func formatSubStack(st stack, buffer *bytes.Buffer) { continue } // Avoid GF stacks if not in GF development. - if !intlog.IsInGFDevelop() { + if !intlog.IsGFDebug() { if strings.Contains(file, "github.com/gogf/gf/") { continue } diff --git a/internal/intlog/intlog.go b/internal/intlog/intlog.go index c0fa61042..221084dd9 100644 --- a/internal/intlog/intlog.go +++ b/internal/intlog/intlog.go @@ -20,26 +20,26 @@ const ( ) var ( - // isInGFDevelop marks whether current environment is in GF development. - isInGFDevelop = false + // isGFDebug marks whether printing GoFrame debug information. + isGFDebug = false ) func init() { - if !cmdenv.Get("GF_DEV").IsEmpty() { - isInGFDevelop = true + if !cmdenv.Get("GF_DEBUG").IsEmpty() { + isGFDebug = true return } } -// IsInGFDevelop checks and returns whether current process is in GF development. -func IsInGFDevelop() bool { - return isInGFDevelop +// IsGFDebug checks and returns whether current process is in GF development. +func IsGFDebug() bool { + return isGFDebug } // Print prints with newline using fmt.Println. // The parameter can be multiple variables. func Print(v ...interface{}) { - if !isInGFDevelop { + if !isGFDebug { return } fmt.Println(append([]interface{}{now(), "[INTE]", file()}, v...)...) @@ -48,7 +48,7 @@ func Print(v ...interface{}) { // Printf prints with format using fmt.Printf. // The parameter can be multiple variables. func Printf(format string, v ...interface{}) { - if !isInGFDevelop { + if !isGFDebug { return } fmt.Printf(now()+" [INTE] "+file()+" "+format+"\n", v...) @@ -57,7 +57,7 @@ func Printf(format string, v ...interface{}) { // Error prints with newline using fmt.Println. // The parameter can be multiple variables. func Error(v ...interface{}) { - if !isInGFDevelop { + if !isGFDebug { return } array := append([]interface{}{now(), "[INTE]", file()}, v...) @@ -67,7 +67,7 @@ func Error(v ...interface{}) { // Errorf prints with format using fmt.Printf. func Errorf(format string, v ...interface{}) { - if !isInGFDevelop { + if !isGFDebug { return } fmt.Printf( diff --git a/net/ghttp/ghttp_server.go b/net/ghttp/ghttp_server.go index 1a55342db..c89f29698 100644 --- a/net/ghttp/ghttp_server.go +++ b/net/ghttp/ghttp_server.go @@ -340,7 +340,7 @@ func (s *Server) Start() error { } }) } - if intlog.IsInGFDevelop() { + if intlog.IsGFDebug() { intlog.Print("server configuration:") gutil.Dump(s.config) } diff --git a/os/gview/gview_config.go b/os/gview/gview_config.go index 678556705..629cae82d 100644 --- a/os/gview/gview_config.go +++ b/os/gview/gview_config.go @@ -10,6 +10,7 @@ import ( "errors" "fmt" "github.com/gogf/gf/i18n/gi18n" + "github.com/gogf/gf/internal/intlog" "github.com/gogf/gf/os/gfile" "github.com/gogf/gf/os/glog" "github.com/gogf/gf/os/gres" @@ -29,6 +30,7 @@ type Config struct { // SetConfig sets the configuration for view. func (view *View) SetConfig(config Config) error { + intlog.Printf("%+v", config) var err error if len(config.Paths) > 0 { for _, v := range config.Paths {