remove function Println from package glog

This commit is contained in:
John Guo
2021-10-30 19:44:22 +08:00
parent 42e27dd14c
commit e22e1d0e4a
34 changed files with 61 additions and 73 deletions

View File

@ -14,7 +14,7 @@ func main() {
p := gpool.New(3000*time.Millisecond, func() (interface{}, error) {
return gtcp.NewConn("www.baidu.com:80")
}, func(i interface{}) {
glog.Println("expired")
glog.Print("expired")
i.(*gtcp.Conn).Close()
})
conn, err := p.Get()

View File

@ -17,6 +17,6 @@ func Error2() error {
}
func main() {
glog.Println(Error1())
glog.Println(Error2())
glog.Print(Error1())
glog.Print(Error2())
}

View File

@ -12,7 +12,7 @@ func MiddlewareCORS(r *ghttp.Request) {
}
func Order(r *ghttp.Request) {
glog.Println("order")
glog.Print("order")
r.Response.Write("GET")
}

View File

@ -11,10 +11,10 @@ func main() {
p := "/:name/info/{uid}"
s := g.Server()
s.BindHookHandlerByMap(p, map[string]ghttp.HandlerFunc{
ghttp.HookBeforeServe: func(r *ghttp.Request) { glog.Println(ghttp.HookBeforeServe) },
ghttp.HookAfterServe: func(r *ghttp.Request) { glog.Println(ghttp.HookAfterServe) },
ghttp.HookBeforeOutput: func(r *ghttp.Request) { glog.Println(ghttp.HookBeforeOutput) },
ghttp.HookAfterOutput: func(r *ghttp.Request) { glog.Println(ghttp.HookAfterOutput) },
ghttp.HookBeforeServe: func(r *ghttp.Request) { glog.Print(ghttp.HookBeforeServe) },
ghttp.HookAfterServe: func(r *ghttp.Request) { glog.Print(ghttp.HookAfterServe) },
ghttp.HookBeforeOutput: func(r *ghttp.Request) { glog.Print(ghttp.HookBeforeOutput) },
ghttp.HookAfterOutput: func(r *ghttp.Request) { glog.Print(ghttp.HookAfterOutput) },
})
s.BindHandler(p, func(r *ghttp.Request) {
r.Response.Write("用户:", r.Get("name"), ", uid:", r.Get("uid"))

View File

@ -10,7 +10,7 @@ func main() {
s1 := ghttp.GetServer("s1")
s1.SetPort(8882)
s1.BindHandler("/", func(r *ghttp.Request) {
glog.Println("s1")
glog.Print("s1")
r.Response.Writeln("s1")
})
s1.Start()
@ -18,7 +18,7 @@ func main() {
s2 := ghttp.GetServer("s2")
s2.SetPort(8882)
s2.BindHandler("/", func(r *ghttp.Request) {
glog.Println("s2")
glog.Print("s2")
r.Response.Writeln("s2")
})
s2.Start()

View File

@ -32,7 +32,7 @@ func main() {
msg, err := funcs.RecvPkg(conn)
if err != nil {
if err.Error() == "EOF" {
glog.Println("server closed")
glog.Print("server closed")
}
break
}

View File

@ -21,7 +21,7 @@ func main() {
msg, err := funcs.RecvPkg(conn)
if err != nil {
if err.Error() == "EOF" {
glog.Println("client closed")
glog.Print("client closed")
}
break
}

View File

@ -35,9 +35,9 @@ func main() {
// 使用 SendRecvPkg 发送消息包并接受返回
if result, err := conn.SendRecvPkg(info); err != nil {
if err.Error() == "EOF" {
glog.Println("server closed")
glog.Print("server closed")
}
} else {
glog.Println(string(result))
glog.Print(string(result))
}
}

View File

@ -16,7 +16,7 @@ func main() {
data, err := conn.RecvPkg()
if err != nil {
if err.Error() == "EOF" {
glog.Println("client closed")
glog.Print("client closed")
}
break
}
@ -24,7 +24,7 @@ func main() {
if err := json.Unmarshal(data, info); err != nil {
glog.Errorf("invalid package structure: %s", err.Error())
} else {
glog.Println(info)
glog.Print(info)
conn.SendPkg([]byte("ok"))
}
}

View File

@ -10,7 +10,7 @@ import (
func main() {
gcron.SetLogLevel(glog.LEVEL_ALL)
gcron.Add("* * * * * ?", func() {
glog.Println("test")
glog.Print("test")
})
time.Sleep(3 * time.Second)
}

View File

@ -8,14 +8,14 @@ import (
)
func main() {
gcron.Add("0 30 * * * *", func() { glog.Println("Every hour on the half hour") })
gcron.Add("* * * * * *", func() { glog.Println("Every second, pattern") }, "second-cron")
gcron.Add("*/5 * * * * *", func() { glog.Println("Every 5 seconds, pattern") })
gcron.Add("0 30 * * * *", func() { glog.Print("Every hour on the half hour") })
gcron.Add("* * * * * *", func() { glog.Print("Every second, pattern") }, "second-cron")
gcron.Add("*/5 * * * * *", func() { glog.Print("Every 5 seconds, pattern") })
gcron.Add("@hourly", func() { glog.Println("Every hour") })
gcron.Add("@every 1h30m", func() { glog.Println("Every hour thirty") })
gcron.Add("@every 1s", func() { glog.Println("Every 1 second") })
gcron.Add("@every 5s", func() { glog.Println("Every 5 seconds") })
gcron.Add("@hourly", func() { glog.Print("Every hour") })
gcron.Add("@every 1h30m", func() { glog.Print("Every hour thirty") })
gcron.Add("@every 1s", func() { glog.Print("Every 1 second") })
gcron.Add("@every 5s", func() { glog.Print("Every 5 seconds") })
time.Sleep(3 * time.Second)

View File

@ -8,7 +8,7 @@ import (
)
func test() {
glog.Println(111)
glog.Print(111)
}
func main() {

View File

@ -1,6 +1,7 @@
package main
import (
"context"
"log"
"github.com/fsnotify/fsnotify"
@ -25,7 +26,7 @@ func main() {
for {
select {
case ev := <-watch.Events:
glog.Println(ev)
glog.Print(context.Background(), ev)
case err := <-watch.Errors:
log.Println("error : ", err)

View File

@ -9,7 +9,7 @@ func main() {
//path := `D:\temp`
path := "/Users/john/Temp"
_, err := gfsnotify.Add(path, func(event *gfsnotify.Event) {
glog.Println(event)
glog.Print(event)
})
if err != nil {
glog.Fatal(err)

View File

@ -10,13 +10,13 @@ import (
func main() {
c1, err := gfsnotify.Add("/home/john/temp/log", func(event *gfsnotify.Event) {
glog.Println("callback1")
glog.Print("callback1")
})
if err != nil {
panic(err)
}
c2, err := gfsnotify.Add("/home/john/temp/log", func(event *gfsnotify.Event) {
glog.Println("callback2")
glog.Print("callback2")
})
if err != nil {
panic(err)
@ -24,12 +24,12 @@ func main() {
// 5秒后移除c1的回调函数注册仅剩c2
gtimer.SetTimeout(5*time.Second, func() {
gfsnotify.RemoveCallback(c1.Id)
glog.Println("remove callback c1")
glog.Print("remove callback c1")
})
// 10秒后移除c2的回调函数注册所有的回调都移除不再有任何打印信息输出
gtimer.SetTimeout(10*time.Second, func() {
gfsnotify.RemoveCallback(c2.Id)
glog.Println("remove callback c2")
glog.Print("remove callback c2")
})
select {}

View File

@ -10,7 +10,7 @@ import (
func main() {
callback, err := gfsnotify.Add("/home/john/temp", func(event *gfsnotify.Event) {
glog.Println("callback")
glog.Print("callback")
})
if err != nil {
panic(err)
@ -21,7 +21,7 @@ func main() {
// 20秒后移除回调函数注册所有的回调都移除不再有任何打印信息输出
gtimer.SetTimeout(20*time.Second, func() {
gfsnotify.RemoveCallback(callback.Id)
glog.Println("remove callback")
glog.Print("remove callback")
})
select {}

View File

@ -10,7 +10,7 @@ func main() {
path := "/Users/john/temp/log"
for i := 0; i < 9999999; i++ {
_, err := gfsnotify.Add(path, func(event *gfsnotify.Event) {
glog.Println(event)
glog.Print(event)
})
if err != nil {
glog.Fatal(err)

View File

@ -26,5 +26,5 @@ package main
// MaxChunkSizeLan : 1337,
// }),
// })
// glog.Println("test log")
// glog.Print("test log")
//}

View File

@ -27,5 +27,5 @@ package main
// g.Log().Debug("Debugging...")
// g.Log().Warning("It is warning info")
// g.Log().Error("Error occurs, please have a check")
// glog.Println("test log")
// glog.Print("test log")
//}

View File

@ -18,7 +18,7 @@ func main() {
wg.Add(1)
go func(i int) {
gmlock.Lock(key)
glog.Println(i)
glog.Print(i)
time.Sleep(time.Second)
gmlock.Unlock(key)
wg.Done()

View File

@ -16,11 +16,11 @@ func main() {
wg.Add(1)
go func(i int) {
if gmlock.TryLock(key) {
glog.Println(i)
glog.Print(i)
time.Sleep(time.Second)
gmlock.Unlock(key)
} else {
glog.Println(false)
glog.Print(false)
}
wg.Done()
}(i)

View File

@ -14,26 +14,26 @@ func main() {
// 第一次锁带时间
gmlock.Lock(key)
glog.Println("lock1")
glog.Print("lock1")
// 这个时候上一次的计时解锁已失效
gmlock.Unlock(key)
glog.Println("unlock1")
glog.Print("unlock1")
fmt.Println()
// 第二次锁不带时间且在执行过程中钱一个Lock的定时解锁生效
gmlock.Lock(key)
glog.Println("lock2")
glog.Print("lock2")
go func() {
// 正常情况下3秒后才能执行这句
gmlock.Lock(key)
glog.Println("lock by goroutine")
glog.Print("lock by goroutine")
}()
time.Sleep(3 * time.Second)
// 这时再解锁
gmlock.Unlock(key)
// 注意3秒之后才会执行这一句
glog.Println("unlock2")
glog.Print("unlock2")
select {}
}

View File

@ -13,7 +13,7 @@ func main() {
go func(n int) {
mu.Lock()
defer mu.Unlock()
glog.Println("Lock:", n)
glog.Print("Lock:", n)
time.Sleep(time.Second)
}(i)
}
@ -21,7 +21,7 @@ func main() {
go func(n int) {
mu.RLock()
defer mu.RUnlock()
glog.Println("RLock:", n)
glog.Print("RLock:", n)
time.Sleep(time.Second)
}(i)
}

View File

@ -11,12 +11,12 @@ import (
func main() {
mu := gmutex.New()
go mu.LockFunc(func() {
glog.Println("lock func1")
glog.Print("lock func1")
time.Sleep(1 * time.Second)
})
time.Sleep(time.Millisecond)
go mu.LockFunc(func() {
glog.Println("lock func2")
glog.Print("lock func2")
})
time.Sleep(2 * time.Second)
}

View File

@ -10,7 +10,7 @@ import (
func main() {
interval := time.Second
gtimer.AddSingleton(interval, func() {
glog.Println("doing")
glog.Print("doing")
time.Sleep(5 * time.Second)
})

View File

@ -10,10 +10,10 @@ import (
func main() {
interval := time.Second
gtimer.AddTimes(interval, 2, func() {
glog.Println("doing1")
glog.Print("doing1")
})
gtimer.AddTimes(interval, 2, func() {
glog.Println("doing2")
glog.Print("doing2")
})
select {}

View File

@ -8,7 +8,7 @@
//
// Eg:
// s := smtp.New("smtp.exmail.qq.com:25", "notify@a.com", "password")
// glog.Println(s.SendMail("notify@a.com", "ulric@b.com;rain@c.com", "subject", "body, <font color=red>red</font>"))
// glog.Print(s.SendMail("notify@a.com", "ulric@b.com;rain@c.com", "subject", "body, <font color=red>red</font>"))
package gsmtp
import (

View File

@ -16,7 +16,7 @@ import (
func Example_cronAddSingleton() {
gcron.AddSingleton(ctx, "* * * * * *", func(ctx context.Context) {
glog.Println(context.TODO(), "doing")
glog.Print(context.TODO(), "doing")
time.Sleep(2 * time.Second)
})
select {}

View File

@ -20,12 +20,6 @@ func Printf(ctx context.Context, format string, v ...interface{}) {
logger.Printf(ctx, format, v...)
}
// Println is alias of Print.
// See Print.
func Println(ctx context.Context, v ...interface{}) {
logger.Println(ctx, v...)
}
// Fatal prints the logging content with [FATA] header and newline, then exit the current process.
func Fatal(ctx context.Context, v ...interface{}) {
logger.Fatal(ctx, v...)

View File

@ -355,9 +355,9 @@ func (l *Logger) format(format string, value ...interface{}) string {
// the optional parameter `skip` specify the skipped stack offset from the end point.
func (l *Logger) PrintStack(ctx context.Context, skip ...int) {
if s := l.GetStack(skip...); s != "" {
l.Println(ctx, "Stack:\n"+s)
l.Print(ctx, "Stack:\n"+s)
} else {
l.Println(ctx)
l.Print(ctx)
}
}

View File

@ -24,12 +24,6 @@ func (l *Logger) Printf(ctx context.Context, format string, v ...interface{}) {
l.printStd(ctx, LEVEL_NONE, l.format(format, v...))
}
// Println is alias of Print.
// See Print.
func (l *Logger) Println(ctx context.Context, v ...interface{}) {
l.Print(ctx, v...)
}
// Fatal prints the logging content with [FATA] header and newline, then exit the current process.
func (l *Logger) Fatal(ctx context.Context, v ...interface{}) {
l.printErr(ctx, LEVEL_FATA, v...)

View File

@ -23,10 +23,9 @@ func Test_Print(t *testing.T) {
w := bytes.NewBuffer(nil)
l := NewWithWriter(w)
l.Print(ctx, 1, 2, 3)
l.Println(ctx, 1, 2, 3)
l.Printf(ctx, "%d %d %d", 1, 2, 3)
t.Assert(gstr.Count(w.String(), "["), 0)
t.Assert(gstr.Count(w.String(), "1 2 3"), 3)
t.Assert(gstr.Count(w.String(), "1 2 3"), 2)
})
}

View File

@ -249,7 +249,7 @@ func Test_Mutex_TryRLockFunc(t *testing.T) {
go func() {
mu.LockFunc(func() {
array.Append(1)
glog.Println(context.TODO(), "lock1 done")
glog.Print(context.TODO(), "lock1 done")
time.Sleep(2000 * time.Millisecond)
})
}()

View File

@ -248,15 +248,15 @@ func TestTimer_AddLeveledJob1(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
timer := New()
array := garray.New(true)
//glog.Println("start")
//glog.Print("start")
timer.DelayAdd(ctx, 1000*time.Millisecond, 1000*time.Millisecond, func(ctx context.Context) {
//glog.Println("add")
//glog.Print("add")
array.Append(1)
})
time.Sleep(1500 * time.Millisecond)
t.Assert(array.Len(), 0)
time.Sleep(1300 * time.Millisecond)
//glog.Println("check")
//glog.Print("check")
t.Assert(array.Len(), 1)
})
}