diff options
| author | Bobby <[email protected]> | 2026-03-07 15:10:41 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-03-07 15:10:41 +0530 |
| commit | 92556e7619524182f024b6422e1c29b6a4cb03e7 (patch) | |
| tree | 0802125940fb1dc26866ab58f83ba411c4b012bc | |
| parent | 8f8d41413ff775b6d721059783a0e2de4f90f50c (diff) | |
| download | dove-92556e7619524182f024b6422e1c29b6a4cb03e7.tar.xz dove-92556e7619524182f024b6422e1c29b6a4cb03e7.zip | |
refactor: simplify httpLogger function structure
| -rw-r--r-- | middleware/logging.go | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/middleware/logging.go b/middleware/logging.go index 15c82b6..a8c3bd6 100644 --- a/middleware/logging.go +++ b/middleware/logging.go @@ -11,32 +11,30 @@ import ( "github.com/gofiber/fiber/v2" ) -func httpLogger() fiber.Handler { - return func(context *fiber.Ctx) error { - startTime := time.Now() +func httpLogger(context *fiber.Ctx) error { + startTime := time.Now() - responseError := context.Next() + responseError := context.Next() - duration := time.Since(startTime) - statusCode := context.Response().StatusCode() - method := context.Method() - path := context.Path() - ipAddress := context.IP() + duration := time.Since(startTime) + statusCode := context.Response().StatusCode() + method := context.Method() + path := context.Path() + ipAddress := context.IP() - paddedMethod := method - if len(method) < 7 { - paddedMethod = method + strings.Repeat(" ", 7-len(method)) - } + paddedMethod := method + if len(method) < 7 { + paddedMethod = method + strings.Repeat(" ", 7-len(method)) + } - message := fmt.Sprintf( - "%s %-3d %-15s %-10s %s", - paddedMethod, statusCode, "IP: "+ipAddress, "TTR: "+formatDuration(duration), "Path: "+path, - ) + message := fmt.Sprintf( + "%s %-3d %-15s %-10s %s", + paddedMethod, statusCode, "IP: "+ipAddress, "TTR: "+formatDuration(duration), "Path: "+path, + ) - logByStatus(statusCode, LOG_PREFIX, message) + logByStatus(statusCode, LOG_PREFIX, message) - return responseError - } + return responseError } func logByStatus(statusCode int, prefix string, message string) { |
