String returns a formatted log message.
()
| 277 | |
| 278 | // String returns a formatted log message. |
| 279 | func (q *QueryStatus) String() string { |
| 280 | lines := make([]string, 0, 8) |
| 281 | |
| 282 | if q.SessID > 0 { |
| 283 | lines = append(lines, fmt.Sprintf(fmtLogSessID, q.SessID)) |
| 284 | } |
| 285 | |
| 286 | if q.TxID > 0 { |
| 287 | lines = append(lines, fmt.Sprintf(fmtLogTxID, q.TxID)) |
| 288 | } |
| 289 | |
| 290 | if query := q.RawQuery; query != "" { |
| 291 | lines = append(lines, fmt.Sprintf(fmtLogQuery, q.Query())) |
| 292 | } |
| 293 | |
| 294 | if len(q.Args) > 0 { |
| 295 | lines = append(lines, fmt.Sprintf(fmtLogArgs, q.Args)) |
| 296 | } |
| 297 | |
| 298 | if stack := q.Stack(); len(stack) > 0 { |
| 299 | lines = append(lines, fmt.Sprintf(fmtLogStack, "\n\t"+strings.Join(stack, "\n\t"))) |
| 300 | } |
| 301 | |
| 302 | if q.RowsAffected != nil { |
| 303 | lines = append(lines, fmt.Sprintf(fmtLogRowsAffected, *q.RowsAffected)) |
| 304 | } |
| 305 | if q.LastInsertID != nil { |
| 306 | lines = append(lines, fmt.Sprintf(fmtLogLastInsertID, *q.LastInsertID)) |
| 307 | } |
| 308 | |
| 309 | if q.Err != nil { |
| 310 | lines = append(lines, fmt.Sprintf(fmtLogError, q.Err)) |
| 311 | } |
| 312 | |
| 313 | lines = append(lines, fmt.Sprintf(fmtLogTimeTaken, float64(q.End.UnixNano()-q.Start.UnixNano())/float64(1e9))) |
| 314 | |
| 315 | if q.Context != nil { |
| 316 | lines = append(lines, fmt.Sprintf(fmtLogContext, q.Context)) |
| 317 | } |
| 318 | |
| 319 | return "\t" + strings.Replace(strings.Join(lines, "\n"), "\n", "\n\t", -1) + "\n\n" |
| 320 | } |
| 321 | |
| 322 | // LC returns the logging collector. |
| 323 | func LC() LoggingCollector { |