Source File
logging.go
Belonging Package
golang.org/x/pkgsite/internal/database
package database
import (
)
var QueryLoggingDisabled bool
var queryCounter int64 // atomic: per-process counter for unique query IDs
type queryEndLogEntry struct {
ID string
Query string
Args string
DurationSeconds float64
Error string `json:",omitempty"`
}
func ( context.Context, string, []interface{}, string, bool) func(*error) {
if QueryLoggingDisabled {
return func(*error) {}
}
const = 300 // maximum length of displayed query
const (
= 20
= 50
)
var []string
for := 0; < len() && < ; ++ {
:= fmt.Sprint([])
if len() > {
= [:] + "..."
}
= append(, )
}
if len() > {
= append(, "...")
}
:= strings.Join(, ", ")
log.Debugf(, "%s %s args=%s", , , )
:= time.Now()
return func( *error) {
:= time.Since()
if == nil { // happens with queryRow
log.Debugf(, "%s done", )
} else {
derrors.Wrap(, "DB running query %s", )
:= queryEndLogEntry{
ID: ,
Query: ,
Args: ,
DurationSeconds: .Seconds(),
}
if * == nil {
log.Debug(, )
} else {
if && isSerializationFailure(*) {
= log.Warning
}
(, )
}
}
}
}
func ( *DB) ( context.Context) func(*error) {
if QueryLoggingDisabled {
return func(*error) {}
}
:= generateLoggingID(.instanceID)
log.Debugf(, "%s transaction (isolation %s) started", , .opts.Isolation)
:= time.Now()
return func( *error) {
log.Debugf(, "%s transaction (isolation %s) finished in %s with error %v",
, .opts.Isolation, time.Since(), *)
}
}
func ( string) string {
if == "" {
= "local"
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |