Stack特性
错误日志信息支持stack
特性,该特性可以自动打印出当前调用日志组件方法的堆栈信息,该堆栈信息可以通过Notice*/Warning*/Error*/Critical*/Panic*/Fatal*
等错误日志输出方法触发,也可以通过GetStack/PrintStack
获取/打印。错误信息的stack
信息对于调试来说相当有用。
示例1,通过错误方法触发
package main
import "github.com/gogf/gf/os/glog"
func Test() {
glog.Error("This is error!")
}
func main() {
Test()
}
...
2019-07-12 22:19:23.421 [ERRO] This is error!
Stack:
1. main.Test
/home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/geg/os/glog/glog_error.go:6
2. main.main
/home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/geg/os/glog/glog_error.go:10
示例2,通过Stack
方法打印
package main
import (
"fmt"
"github.com/gogf/gf/os/glog"
)
func main() {
glog.PrintStack()
glog.New().PrintStack()
fmt.Println(glog.GetStack())
fmt.Println(glog.New().GetStack())
}
...
2019-07-12 22:20:28.070 Stack:
1. main.main
/home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/geg/os/glog/glog_stack.go:11
2019-07-12 22:20:28.070 Stack:
1. main.main
/home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/geg/os/glog/glog_stack.go:12
1. main.main
/home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/geg/os/glog/glog_stack.go:14
1. main.main
/home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/geg/os/glog/glog_stack.go:15
示例3,打印gerror.Error
glog
日志模块支持对标准错误以及gerror
错误的堆栈打印支持。
...