Versions Compared

Key

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

...

Code Block
languagego
package main

import (
	"context"
	"time"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"
	"github.com/gogf/gf/v2/os/gtimer"
	"time"
)

func main() {
	ctx := context.TODO()
	gtimer.SetTimeout(ctx, 3*time.Second, func(ctx context.Context) {
		g.Log().SetDebug(false)
	})
	for {
		g.Log().Debug(ctx, gtime.Datetime())
		g.Log().Info(ctx, gtime.Datetime())
		time.Sleep(time.Second)
	}
}

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

2018-07-22 12:20:11.100 [DEBU] 2018-07-22 12:20:11
2018-07-22 12:20:12.101 [DEBU] 2018-07-22 12:20:12
2018-07-22 12:20:13.101 [DEBU] 2018-07-22 12:20:13

Code Block
languagexml
2022-01-05 15:59:05.674 [DEBU] 2022-01-05 15:59:05 
2022-01-05 15:59:05.675 [INFO] 2022-01-05 15:59:05 
2022-01-05 15:59:06.684 [DEBU] 2022-01-05 15:59:06 
2022-01-05 15:59:06.684 [INFO] 2022-01-05 15:59:06 
2022-01-05 15:59:07.692 [DEBU] 2022-01-05 15:59:07 
2022-01-05 15:59:07.692 [INFO] 2022-01-05 15:59:07 
2022-01-05 15:59:08.708 [INFO] 2022-01-05 15:59:08 
2022-01-05 15:59:09.717 [INFO] 2022-01-05 15:59:09 
2022-01-05 15:59:10.728 [INFO] 2022-01-05 15:59:10 
2022-01-05 15:59:11.733 [INFO] 2022-01-05 15:59:11


我们还可以通过命令行参数或者系统环境变量参数的方式关闭掉调试信息。

我们还可以通过命令行参数或者系统环境变量参数的方式关闭掉调试信息。 1.
  1. 修改命令行启动参数 - gf.glog.debug=false
1.
  1. 修改指定的环境变量 - GF_GLOG_DEBUG=false