Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Debug/Debugf是非常有用的几个方法,用于调试信息的记录,常用于开发/测试环境中,当应用上线之后可以方便地使用SetDebug或者配置文件进行开启/关闭。

Code Block
languagego
package main

import (

...

	"github.com/gogf/gf/os/glog"
	"github.com/gogf/gf/os/

...

gtime"

...

	"github.com/gogf/gf/os/

...

gtimer"
	"time"
)

func main() {

...

	gtimer.SetTimeout(3*time.Second, func() {

...

		glog.SetDebug(false)

...

	})

...

	for {

...

		glog.Debug(gtime.Datetime())

...

		time.Sleep(time.Second)

...

	}
}

...

该示例中使用glog.Debug方法输出调试信息,3秒后关闭调试信息的输出。执行后,输出结果如下,可以看到只输出了3条日志信息,后续的调试日志信息由于通过SetDebug方法关闭后,便不再输出。

...