From e4846852824a4488714a88567baf1bdf77f041c8 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 15 Jul 2019 19:54:13 +0800 Subject: [PATCH] improve debug feature for gdb; add skip support for file line print for glog --- g/database/gdb/gdb.go | 7 ++----- g/database/gdb/gdb_config.go | 2 +- g/database/gdb/gdb_model.go | 3 +++ g/frame/gins/gins.go | 6 +----- g/os/glog/glog_logger.go | 4 ++-- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/g/database/gdb/gdb.go b/g/database/gdb/gdb.go index 0054f8633..4931e6580 100644 --- a/g/database/gdb/gdb.go +++ b/g/database/gdb/gdb.go @@ -340,11 +340,8 @@ func (bs *dbBase) getSqlDb(master bool) (sqlDb *sql.DB, err error) { sqlDb = v.(*sql.DB) } // 是否开启调试模式 - switch node.Debug { - case 1: - bs.db.SetDebug(false) - case 2: - bs.db.SetDebug(true) + if node.Debug { + bs.db.SetDebug(node.Debug) } // 是否手动选择数据库 if v := bs.schema.Val(); v != "" { diff --git a/g/database/gdb/gdb_config.go b/g/database/gdb/gdb_config.go index 4acd2872b..859db2e37 100644 --- a/g/database/gdb/gdb_config.go +++ b/g/database/gdb/gdb_config.go @@ -32,7 +32,7 @@ type ConfigNode struct { Name string // 数据库名称 Type string // 数据库类型:mysql, sqlite, mssql, pgsql, oracle Role string // (可选,默认为master)数据库的角色,用于主从操作分离,至少需要有一个master,参数值:master, slave - Debug int // (可选)开启调试模式(0:未设置,1:关闭,2:开启) + Debug bool // (可选)开启调试模式 Weight int // (可选)用于负载均衡的权重计算,当集群中只有一个节点时,权重没有任何意义 Charset string // (可选,默认为 utf8)编码,默认为 utf8 LinkInfo string // (可选)自定义链接信息,当该字段被设置值时,以上链接字段(Host,Port,User,Pass,Name)将失效(该字段是一个扩展功能) diff --git a/g/database/gdb/gdb_model.go b/g/database/gdb/gdb_model.go index 9e026df62..1874cb7b9 100644 --- a/g/database/gdb/gdb_model.go +++ b/g/database/gdb/gdb_model.go @@ -63,6 +63,9 @@ func (tx *TX) Table(tables string) *Model { tx: tx, tablesInit: tables, tables: tables, + fields: "*", + start: -1, + offset: -1, safe: false, } } diff --git a/g/frame/gins/gins.go b/g/frame/gins/gins.go index c3ece61ac..1acbf8c14 100644 --- a/g/frame/gins/gins.go +++ b/g/frame/gins/gins.go @@ -161,11 +161,7 @@ func parseDBConfigNode(value interface{}) *gdb.ConfigNode { node.Role = gconv.String(value) } if value, ok := nodeMap["debug"]; ok { - if gconv.Bool(value) { - node.Debug = 2 - } else { - node.Debug = 1 - } + node.Debug = gconv.Bool(value) } if value, ok := nodeMap["charset"]; ok { node.Charset = gconv.String(value) diff --git a/g/os/glog/glog_logger.go b/g/os/glog/glog_logger.go index a8ea66ee4..df9886046 100644 --- a/g/os/glog/glog_logger.go +++ b/g/os/glog/glog_logger.go @@ -244,10 +244,10 @@ func (l *Logger) print(std io.Writer, lead string, value ...interface{}) { // Caller path. callerPath := "" if l.flags&F_FILE_LONG > 0 { - callerPath = debug.CallerWithFilter(gPATH_FILTER_KEY) + ": " + callerPath = debug.CallerWithFilter(gPATH_FILTER_KEY, l.stSkip) + ": " } if l.flags&F_FILE_SHORT > 0 { - callerPath = gfile.Basename(debug.CallerWithFilter(gPATH_FILTER_KEY)) + ": " + callerPath = gfile.Basename(debug.CallerWithFilter(gPATH_FILTER_KEY, l.stSkip)) + ": " } if len(callerPath) > 0 { buffer.WriteString(callerPath)