gdb增加调试模式的自动调试信息输出,开发中

This commit is contained in:
John 2018-08-27 23:58:32 +08:00
parent a74c9c090c
commit a3aa5e7cd7
8 changed files with 94 additions and 21 deletions

4
TODO
View File

@ -11,7 +11,6 @@ Cookie&Session数据池化处理
ghttp.Client增加proxy特性
gtime增加对时区转换的封装并简化失去转换时对类似+80500时区的支持
orm增加sqlite对Save方法的支持(去掉触发器语句);
ghttp.Server的Cookie及Session锁机制优化(去掉map锁机制);
ghttp.Server增加Ip访问控制功能(DenyIps&AllowIps)
ghttp路由功能增加分组路由特性
解决glog串日志情况
@ -63,4 +62,5 @@ DONE:
36. gcache检查在i386下的int64->int转换问题
37. ghttp获取参数支持直接转struct功能
38. gfsnotify增加对于目录的监控
39. 检查windows下的平滑重启失效问题
39. 检查windows下的平滑重启失效问题
40. ghttp.Server的Cookie及Session锁机制优化(去掉map锁机制);

View File

@ -18,6 +18,7 @@ import (
"gitee.com/johng/gf/g/container/gring"
"gitee.com/johng/gf/g/os/gtime"
"time"
"gitee.com/johng/gf/g/os/glog"
)
const (
@ -64,6 +65,22 @@ func (db *Db) PrintQueriedSqls() {
}
}
// 打印SQL对象(仅在debug=true时有效)
func (db *Db) printSql(v *Sql) {
s := fmt.Sprintf("%s, %v, %s, %s, %d ms, %s", v.Sql, v.Args,
gtime.NewFromTimeStamp(v.Start).Format("Y-m-d H:i:s.u"),
gtime.NewFromTimeStamp(v.End).Format("Y-m-d H:i:s.u"),
v.End - v.Start, v.Func,
)
if v.Error != nil {
s += "\nError: " + v.Error.Error()
glog.Error(s)
} else {
glog.Debug(s)
}
}
// 关闭链接
func (db *Db) Close() error {
if db.master != nil {
@ -92,14 +109,16 @@ func (db *Db) Query(query string, args ...interface{}) (*sql.Rows, error) {
militime1 := gtime.Millisecond()
rows, err = db.slave.Query(*p, args ...)
militime2 := gtime.Millisecond()
db.sqls.Put(&Sql{
s := &Sql{
Sql : *p,
Args : args,
Error : err,
Start : militime1,
End : militime2,
Func : "DB:Query",
})
}
db.sqls.Put(s)
db.printSql(s)
} else {
rows, err = db.slave.Query(*p, args ...)
}
@ -120,14 +139,16 @@ func (db *Db) Exec(query string, args ...interface{}) (sql.Result, error) {
militime1 := gtime.Millisecond()
result, err = db.master.Exec(*p, args ...)
militime2 := gtime.Millisecond()
db.sqls.Put(&Sql{
s := &Sql{
Sql : *p,
Args : args,
Error : err,
Start : militime1,
End : militime2,
Func : "DB:Exec",
})
}
db.sqls.Put(s)
db.printSql(s)
} else {
result, err = db.master.Exec(*p, args ...)
}

View File

@ -42,14 +42,16 @@ func (tx *Tx) Query(query string, args ...interface{}) (*sql.Rows, error) {
militime1 := gtime.Millisecond()
rows, err = tx.tx.Query(*p, args ...)
militime2 := gtime.Millisecond()
tx.db.sqls.Put(&Sql{
s := &Sql{
Sql : *p,
Args : args,
Error : err,
Start : militime1,
End : militime2,
Func : "TX:Query",
})
}
tx.db.sqls.Put(s)
tx.db.printSql(s)
} else {
rows, err = tx.tx.Query(*p, args ...)
}
@ -70,14 +72,16 @@ func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error) {
militime1 := gtime.Millisecond()
result, err = tx.tx.Exec(*p, args ...)
militime2 := gtime.Millisecond()
tx.db.sqls.Put(&Sql{
s := &Sql{
Sql : *p,
Args : args,
Error : err,
Start : militime1,
End : militime2,
Func : "TX:Exec",
})
}
tx.db.sqls.Put(s)
tx.db.printSql(s)
} else {
result, err = tx.tx.Exec(*p, args ...)
}

View File

@ -204,8 +204,8 @@ func GetServer(name...interface{}) (*Server) {
nameToUriType : gtype.NewInt(),
gzipMimesMap : make(map[string]struct{}),
}
s.errorLogger.SetBacktraceSkip(4)
s.accessLogger.SetBacktraceSkip(4)
s.errorLogger.SetBacktraceSkip(1)
s.accessLogger.SetBacktraceSkip(1)
// 设置路由解析缓存上限使用LRU进行缓存淘汰
s.serveCache.SetCap(gSERVE_CACHE_LRU_SIZE)
s.hooksCache.SetCap(gHOOKS_CACHE_LRU_SIZE)

View File

@ -39,7 +39,7 @@ func New() *Logger {
io : nil,
path : gtype.NewString(),
debug : gtype.NewBool(true),
btSkip : gtype.NewInt(3),
btSkip : gtype.NewInt(),
stdprint : gtype.NewBool(true),
}
}
@ -64,6 +64,24 @@ func Cat(category string) *Logger {
return logger.Cat(category)
}
// 打印文件调用回溯信息
func PrintBacktrace(skip...int) {
customSkip := 1
if len(skip) > 0 {
customSkip += skip[0]
}
logger.PrintBacktrace(customSkip)
}
// 获取文件调用回溯信息
func GetBacktrace(skip...int) string {
customSkip := 1
if len(skip) > 0 {
customSkip += skip[0]
}
return logger.GetBacktrace(customSkip)
}
// 设置写日志的同时开启or关闭控制台打印默认是关闭的
// @author zseeker
// @date 2018-05-24

View File

@ -167,7 +167,7 @@ func (l *Logger) stdPrint(s string) {
// 核心打印数据方法(标准错误)
func (l *Logger) errPrint(s string) {
// 记录调用回溯信息
backtrace := l.backtrace()
backtrace := l.GetBacktrace(3)
if s[len(s) - 1] == byte('\n') {
s = s + backtrace + ln
} else {
@ -176,15 +176,28 @@ func (l *Logger) errPrint(s string) {
l.print(os.Stderr, s)
}
// 调用回溯字符串
func (l *Logger) backtrace() string {
backtrace := "Trace:" + ln
// 直接打印回溯信息参数skip表示调用端往上多少级开始回溯
func (l *Logger) PrintBacktrace(skip...int) {
customSkip := 1
if len(skip) > 0 {
customSkip += skip[0]
}
l.Println(l.GetBacktrace(customSkip))
}
// 获取文件调用回溯字符串参数skip表示调用端往上多少级开始回溯
func (l *Logger) GetBacktrace(skip...int) string {
customSkip := 0
if len(skip) > 0 {
customSkip += skip[0]
}
backtrace := ""
index := 1
for i := 1; i < 10000; i++ {
if _, cfile, cline, ok := runtime.Caller(i + l.btSkip.Val()); ok {
if _, cfile, cline, ok := runtime.Caller(customSkip + i + l.btSkip.Val()); ok {
// 不打印出go源码路径
if !gregex.IsMatchString("^" + gfile.GoRootOfBuild(), cfile) {
backtrace += strconv.Itoa(index) + ". " + cfile + ":" + strconv.Itoa(cline) + ln
backtrace += strconv.Itoa(index) + ".\t" + cfile + ":" + strconv.Itoa(cline) + ln
index++
}
} else {

View File

@ -10,7 +10,7 @@ func main() {
Host: "127.0.0.1",
Port: "3306",
User: "root",
Pass: "123456",
Pass: "8692651",
Name: "test",
Type: "mysql",
Role: "master",
@ -31,5 +31,5 @@ func main() {
db.Table("user").Data(g.Map{"name":"smith"}).Where("uid=?", 1).Save()
db.PrintQueriedSqls()
//db.PrintQueriedSqls()
}

View File

@ -0,0 +1,17 @@
package main
import (
"gitee.com/johng/gf/g/os/glog"
"fmt"
)
func main() {
glog.PrintBacktrace()
glog.New().PrintBacktrace()
fmt.Println(glog.GetBacktrace())
fmt.Println(glog.New().GetBacktrace())
}