diff --git a/logger.go b/logger.go index 8a24224e..98dbe18f 100644 --- a/logger.go +++ b/logger.go @@ -50,30 +50,32 @@ var txlog = func(lvl logging.Level, anon interface{}, s string, args ...interfac } else { s = fmt.Sprintf("%s - %s", lvl, s) } - } else { - s = fmt.Sprintf(s, args...) - s = fmt.Sprintf("%s - %s", lvl, s) - } - connID := "" - txID := 0 - switch typed := anon.(type) { - case *Connection: - connID = typed.ID - if typed.TX != nil { - txID = typed.TX.ID - } - case *Tx: - txID = typed.ID - case store: - tx, err := typed.Transaction() - if err == nil { - txID = tx.ID + connID := "" + txID := 0 + extra := "" + switch typed := anon.(type) { + case *Connection: + connID = typed.ID + if typed.TX != nil { + txID = typed.TX.ID + } + + extra = printStats(&typed.Store) + case *Tx: + txID = typed.ID + case store: + if t, ok := typed.(*Tx); ok { + txID = t.ID + } + + extra = printStats(&typed) } - } - if connID != "" || txID != 0 { - s = fmt.Sprintf("%s (conn=%v, tx=%v)", s, connID, txID) + s = fmt.Sprintf("%s (conn=%v, tx=%v%v)", s, connID, txID, extra) + } else { + s = fmt.Sprintf(s, args...) + s = fmt.Sprintf("%s - %s", lvl, s) } if Color { @@ -82,3 +84,14 @@ var txlog = func(lvl logging.Level, anon interface{}, s string, args ...interfac defaultStdLogger.Println(s) } + +// printStats returns a string represent connection pool information from +// the given store. +func printStats(s *store) string { + if db, ok := (*s).(*dB); ok { + s := db.Stats() + return fmt.Sprintf(", maxconn: %d, openconn: %d, in-use: %d, idle: %d", s.MaxOpenConnections, s.OpenConnections, s.InUse, s.Idle) + } + + return "" +}