mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 12:45:47 +00:00
chore: format server package
This commit is contained in:
@@ -29,7 +29,7 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func logPath(path string) bool{
|
func logPath(path string) bool {
|
||||||
for _, prefix := range loggerSkipPathsPrefix {
|
for _, prefix := range loggerSkipPathsPrefix {
|
||||||
if strings.HasPrefix(path, prefix) {
|
if strings.HasPrefix(path, prefix) {
|
||||||
return false
|
return false
|
||||||
@@ -102,22 +102,18 @@ func (s *Server) Start() error {
|
|||||||
// zerolog is a middleware for gin that logs requests using zerolog
|
// zerolog is a middleware for gin that logs requests using zerolog
|
||||||
func zerolog() gin.HandlerFunc {
|
func zerolog() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
// Get initial time
|
|
||||||
tStart := time.Now()
|
tStart := time.Now()
|
||||||
|
|
||||||
// Process request
|
|
||||||
c.Next()
|
c.Next()
|
||||||
|
|
||||||
// Get status code, address, method and path
|
|
||||||
code := c.Writer.Status()
|
code := c.Writer.Status()
|
||||||
address := c.Request.RemoteAddr
|
address := c.Request.RemoteAddr
|
||||||
method := c.Request.Method
|
method := c.Request.Method
|
||||||
path := c.Request.URL.Path
|
path := c.Request.URL.Path
|
||||||
|
|
||||||
// Get latency
|
|
||||||
latency := time.Since(tStart).String()
|
latency := time.Since(tStart).String()
|
||||||
|
|
||||||
// Log request
|
// logPath check if the path should be logged normally or with debug
|
||||||
if logPath(method + " " + path) {
|
if logPath(method + " " + path) {
|
||||||
switch {
|
switch {
|
||||||
case code >= 200 && code < 300:
|
case code >= 200 && code < 300:
|
||||||
@@ -127,7 +123,7 @@ func zerolog() gin.HandlerFunc {
|
|||||||
case code >= 400:
|
case code >= 400:
|
||||||
log.Error().Str("method", method).Str("path", path).Str("address", address).Int("status", code).Str("latency", latency).Msg("Request")
|
log.Error().Str("method", method).Str("path", path).Str("address", address).Int("status", code).Str("latency", latency).Msg("Request")
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
log.Debug().Str("method", method).Str("path", path).Str("address", address).Int("status", code).Str("latency", latency).Msg("Request")
|
log.Debug().Str("method", method).Str("path", path).Str("address", address).Int("status", code).Str("latency", latency).Msg("Request")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user