add configration group name for logging content for package gdb

This commit is contained in:
Jack
2020-07-30 23:00:20 +08:00
parent d279566114
commit 0a5c6d832f
2 changed files with 22 additions and 22 deletions

View File

@ -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.

View File

@ -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)