feat: Add JSON logging
Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
18cbc70495
commit
e72feaf0f6
8 changed files with 77 additions and 13 deletions
|
|
@ -1,20 +1,21 @@
|
|||
package base
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Session represents a PostgreSQL backend
|
||||
type Session struct {
|
||||
Pid int64
|
||||
User string
|
||||
Db string
|
||||
Client string
|
||||
State string
|
||||
Query string
|
||||
StateDuration float64
|
||||
ApplicationName string
|
||||
Pid int64 `json:"pid"`
|
||||
User string `json:"user"`
|
||||
Db string `json:"database"`
|
||||
Client string `json:"client"`
|
||||
State string `json:"state"`
|
||||
Query string `json:"query"`
|
||||
StateDuration float64 `json:"state_duration"`
|
||||
ApplicationName string `json:"application_name"`
|
||||
}
|
||||
|
||||
// NewSession instanciates a Session
|
||||
|
|
@ -53,6 +54,12 @@ func (s *Session) Format(format string) string {
|
|||
return output
|
||||
}
|
||||
|
||||
// JSON returns a Session marshaled as a JSON string
|
||||
func (s *Session) JSON() string {
|
||||
b, _ := json.Marshal(s)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// IsIdle returns true when a session is doing nothing
|
||||
func (s *Session) IsIdle() bool {
|
||||
if s.State == "idle" || s.State == "idle in transaction" || s.State == "idle in transaction (aborted)" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue