1
0
Fork 0

replaced phuslu/log with zerolog

Dieser Commit ist enthalten in:
Sebastian Tobie 2022-11-05 08:29:17 +01:00
Ursprung 4ce395c6c1
Commit 9c6feec4ea
11 geänderte Dateien mit 36 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -5,15 +5,16 @@ import (
"net"
"github.com/jackc/pgx/v4"
"github.com/phuslu/log"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
//PGXLogger is an struct to intergrate the Logger Interface of pgx
// PGXLogger is an struct to intergrate the Logger Interface of pgx
type PGXLogger struct{}
// Log sends the logging data to phuslu/log
func (PGXLogger) Log(ctx context.Context, level pgx.LogLevel, msg string, data map[string]interface{}) {
var entry *log.Entry
var entry *zerolog.Event
switch level {
case pgx.LogLevelDebug:
entry = log.Debug()

Datei anzeigen

@ -9,7 +9,7 @@ import (
"time"
"github.com/gin-gonic/gin"
"github.com/phuslu/log"
"github.com/rs/zerolog/log"
)
func headheader(f fs.File, c *gin.Context) (nocontent bool) {

3
go.mod
Datei anzeigen

@ -17,7 +17,8 @@ require (
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/phuslu/log v1.0.83
github.com/rs/xid v1.4.0
github.com/rs/zerolog v1.28.0
golang.org/x/crypto v0.1.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
)

9
go.sum
Datei anzeigen

@ -25,6 +25,7 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
@ -63,6 +64,7 @@ github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM=
github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
@ -201,6 +203,8 @@ github.com/mattermost/xml-roundtrip-validator v0.1.0/go.mod h1:qccnGMcpgwcNaBnxq
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
@ -254,8 +258,12 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc=
github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY=
github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
github.com/russellhaering/goxmldsig v1.1.1 h1:vI0r2osGF1A9PLvsGdPUAGwEIrKa4Pj5sesSBsebIxM=
github.com/russellhaering/goxmldsig v1.1.1/go.mod h1:gM4MDENBQf7M+V824SGfyIUVFWydB7n0KkEubVJl+Tw=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
@ -375,6 +383,7 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

10
http.go
Datei anzeigen

@ -7,9 +7,11 @@ import (
"net/http"
"sync"
intlog "log"
"github.com/flosch/pongo2/v4"
"github.com/gin-gonic/gin"
"github.com/phuslu/log"
"github.com/rs/zerolog/log"
"go.sebtobie.de/httpserver/auth"
"go.sebtobie.de/httpserver/constants"
"go.sebtobie.de/httpserver/funcs"
@ -69,8 +71,8 @@ type Server struct {
// CreateServer creates an server that can be run in a coroutine.
func CreateServer() *Server {
log.Info().Msg("Redirect logging output to phuslu/log")
gin.DefaultErrorWriter = log.DefaultLogger.Std("GIN", 0).Writer()
gin.DefaultWriter = log.DefaultLogger.Std("GIN", 0).Writer()
gin.DefaultErrorWriter = log.Logger.With().Str("source", "GIN").Logger()
gin.DefaultWriter = log.Logger.With().Str("source", "GIN").Logger()
log.Info().Msg("Creating HTTP-Server")
var server = &Server{
Conf: &Config{
@ -86,7 +88,7 @@ func CreateServer() *Server {
template: pongo2.NewSet("templates", &templates.EmptyLoader{}),
}
server.http = &http.Server{
ErrorLog: log.DefaultLogger.Std("", 0),
ErrorLog: intlog.New(log.Logger, "", 0),
Handler: http.HandlerFunc(server.DomainRouter),
}
return server

Datei anzeigen

@ -10,7 +10,7 @@ import (
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/pgxpool"
"github.com/jackc/tern/migrate"
"github.com/phuslu/log"
"github.com/rs/zerolog/log"
"go.sebtobie.de/httpserver/funcs"
"go.sebtobie.de/httpserver/middleware"
)

Datei anzeigen

@ -2,10 +2,11 @@ package middleware
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
"github.com/phuslu/log"
"github.com/rs/xid"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"go.sebtobie.de/httpserver/auth"
"go.sebtobie.de/httpserver/constants"
)
@ -16,14 +17,14 @@ func LogMiddleware(c *gin.Context) {
if _, exists := c.Get("xid"); exists {
return
}
var xid = log.NewXIDWithTime(time.Now().UnixNano())
c.Set("xid", xid)
id := xid.New()
c.Set("xid", id)
defer func() {
var entry *log.Entry
var entry *zerolog.Event
interrupt := recover()
if interrupt != nil {
err := interrupt.(error)
c.Header("requestid", xid.String())
c.Header("requestid", id.String())
c.AbortWithStatus(http.StatusInternalServerError)
entry = log.Error().Err(err).Int("statuscode", 500)
entry.Stack()
@ -39,7 +40,7 @@ func LogMiddleware(c *gin.Context) {
}
entry.Int("statuscode", statuscode)
}
entry.Int64("goroutine", log.Goid()).Xid("ID", xid).Msg("Request")
entry.Bytes("xid", id.Bytes()).Msg("Request")
}()
c.Next()
}

Datei anzeigen

@ -44,13 +44,13 @@ func (s *SAML) Account(c *gin.Context) auth.Account {
log.Debug().Err(err).Msg("Error while parsing token")
}
if claim, ok = token.Claims.(*jwt.MapClaims); ok && token.Valid {
log.Debug().KeysAndValues(claim).Msg("Got valid token")
log.Debug().Interface("claim", claim).Msg("Got valid token")
for key, value := range *claim {
acc.data[auth.AccountConstant(key)] = value
}
return acc
}
log.Debug().Bool("valid", token.Valid).KeysAndValues(maptoarray(*claim)...).Msg("problem vith token")
log.Debug().Bool("valid", token.Valid).Interface("claim", claim).Msg("problem vith token")
return acc
}

Datei anzeigen

@ -10,7 +10,7 @@ import (
"github.com/crewjam/saml"
"github.com/golang-jwt/jwt/v4"
"github.com/phuslu/log"
"github.com/rs/zerolog/log"
)
func initcert(file string, verify func(interface{}) bool) (key interface{}, err error) {

Datei anzeigen

@ -15,7 +15,7 @@ import (
"github.com/crewjam/saml/samlsp"
"github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt/v4"
"github.com/phuslu/log"
"github.com/rs/zerolog/log"
"go.sebtobie.de/httpserver"
"go.sebtobie.de/httpserver/auth"
)

Datei anzeigen

@ -10,7 +10,7 @@ import (
"github.com/flosch/pongo2/v4"
"github.com/gin-gonic/gin/render"
"github.com/phuslu/log"
"github.com/rs/zerolog/log"
)
var (