example&comment update

This commit is contained in:
John Guo
2021-11-01 19:46:39 +08:00
parent c0c68d1e46
commit 79a233eb78
14 changed files with 43 additions and 36 deletions

View File

@ -1,6 +1,7 @@
package main
import (
"context"
"time"
"github.com/gogf/gf/v2/os/gfsnotify"
@ -9,8 +10,11 @@ import (
)
func main() {
var (
ctx = context.Background()
)
callback, err := gfsnotify.Add("/home/john/temp", func(event *gfsnotify.Event) {
glog.Print("callback")
glog.Print(ctx, "callback")
})
if err != nil {
panic(err)
@ -19,9 +23,9 @@ func main() {
// 在此期间创建文件、目录、修改文件、删除文件
// 20秒后移除回调函数注册所有的回调都移除不再有任何打印信息输出
gtimer.SetTimeout(20*time.Second, func() {
gtimer.SetTimeout(ctx, 20*time.Second, func(ctx context.Context) {
gfsnotify.RemoveCallback(callback.Id)
glog.Print("remove callback")
glog.Print(ctx, "remove callback")
})
select {}

View File

@ -1,27 +1,32 @@
package main
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gfile"
)
// 设置日志等级
func main() {
path := "/tmp/glog"
var (
ctx = context.TODO()
path = "/tmp/glog"
)
g.Log().SetPath(path)
g.Log().SetStdoutPrint(false)
// 使用默认文件名称格式
g.Log().Print("标准文件名称格式,使用当前时间时期")
g.Log().Print(ctx, "标准文件名称格式,使用当前时间时期")
// 通过SetFile设置文件名称格式
g.Log().SetFile("stdout.log")
g.Log().Print("设置日志输出文件名称格式为同一个文件")
g.Log().Print(ctx, "设置日志输出文件名称格式为同一个文件")
// 链式操作设置文件名称格式
g.Log().File("stderr.log").Print("支持链式操作")
g.Log().File("error-{Ymd}.log").Print("文件名称支持带gtime日期格式")
g.Log().File("access-{Ymd}.log").Print("文件名称支持带gtime日期格式")
g.Log().File("stderr.log").Print(ctx, "支持链式操作")
g.Log().File("error-{Ymd}.log").Print(ctx, "文件名称支持带gtime日期格式")
g.Log().File("access-{Ymd}.log").Print(ctx, "文件名称支持带gtime日期格式")
list, err := gfile.ScanDir(path, "*")
g.Dump(err)

View File

@ -1,6 +1,7 @@
package main
import (
"context"
"fmt"
"time"
@ -38,7 +39,7 @@ func main() {
fmt.Println(t.UTC().String())
fmt.Println(t.In(cstLocal).String())
} else {
glog.Error(s, err)
glog.Error(context.Background(), s, err)
}
fmt.Println()
}