From 0a5c6d832f1cde39f78727a513fda7d3e8f8a2a0 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 30 Jul 2020 23:00:20 +0800 Subject: [PATCH] add configration group name for logging content for package gdb --- database/gdb/gdb.go | 14 +++++++------- database/gdb/gdb_core.go | 30 +++++++++++++++--------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/database/gdb/gdb.go b/database/gdb/gdb.go index 3ceeddba2..01279f6bb 100644 --- a/database/gdb/gdb.go +++ b/database/gdb/gdb.go @@ -183,13 +183,13 @@ type Driver interface { // Sql is the sql recording struct. type Sql struct { - Sql string // SQL string(may contain reserved char '?'). - Args []interface{} // Arguments for this sql. - Format string // Formatted sql which contains arguments in the sql. - Error error // Execution result. - Start int64 // Start execution timestamp in milliseconds. - End int64 // End execution timestamp in milliseconds. - DBGroupName string // DBGroupName is which database call the sql. + Sql string // SQL string(may contain reserved char '?'). + Args []interface{} // Arguments for this sql. + Format string // Formatted sql which contains arguments in the sql. + Error error // Execution result. + Start int64 // Start execution timestamp in milliseconds. + End int64 // End execution timestamp in milliseconds. + Group string // Group is the group name of the configuration that the sql is executed from. } // TableField is the struct for table field. diff --git a/database/gdb/gdb_core.go b/database/gdb/gdb_core.go index 6a56fe5ae..afac00aee 100644 --- a/database/gdb/gdb_core.go +++ b/database/gdb/gdb_core.go @@ -54,13 +54,13 @@ func (c *Core) DoQuery(link Link, sql string, args ...interface{}) (rows *sql.Ro rows, err = link.Query(sql, args...) mTime2 := gtime.TimestampMilli() s := &Sql{ - Sql: sql, - Args: args, - Format: FormatSqlWithArgs(sql, args), - Error: err, - Start: mTime1, - End: mTime2, - DBGroupName: c.group, + Sql: sql, + Args: args, + Format: FormatSqlWithArgs(sql, args), + Error: err, + Start: mTime1, + End: mTime2, + Group: c.DB.GetGroup(), } c.writeSqlToLogger(s) } else { @@ -98,13 +98,13 @@ func (c *Core) DoExec(link Link, sql string, args ...interface{}) (result sql.Re } mTime2 := gtime.TimestampMilli() s := &Sql{ - Sql: sql, - Args: args, - Format: FormatSqlWithArgs(sql, args), - Error: err, - Start: mTime1, - End: mTime2, - DBGroupName: c.group, + Sql: sql, + Args: args, + Format: FormatSqlWithArgs(sql, args), + Error: err, + Start: mTime1, + End: mTime2, + Group: c.DB.GetGroup(), } c.writeSqlToLogger(s) } else { @@ -779,7 +779,7 @@ func (c *Core) MarshalJSON() ([]byte, error) { // writeSqlToLogger outputs the sql object to logger. // It is enabled when configuration "debug" is true. func (c *Core) writeSqlToLogger(v *Sql) { - s := fmt.Sprintf("[%s] [%3d ms] %s", v.DBGroupName, v.End-v.Start, v.Format) + s := fmt.Sprintf("[%s] [%3d ms] %s", v.Group, v.End-v.Start, v.Format) if v.Error != nil { s += "\nError: " + v.Error.Error() c.logger.Error(s)