From 3329a56e38236540b5feb7b24c7d880bc676be11 Mon Sep 17 00:00:00 2001 From: Nilo Roberto da Cruz Paim Date: Sun, 13 Aug 2023 08:26:15 -0300 Subject: [PATCH] trying to log requests --- main.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index f5f0da0..7da3704 100644 --- a/main.go +++ b/main.go @@ -25,18 +25,6 @@ func main() { log.Println("Starting API", globals.API_VERSION) log.Println("OS:", os.Getenv("OS")) - app := fiber.New(fiber.Config{ - StrictRouting: false, - DisableStartupMessage: true, - }) - - app.Use(cors.New(cors.Config{ - AllowCredentials: true, - AllowOrigins: "http://*, https://*", - AllowHeaders: "Origin, Content-Type, User-Agent, Connection, User-Agent, Accept, Authorization, Access-Control-Allow-Origin", - AllowMethods: "GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS", - })) - file, err := os.OpenFile("./api-homolog.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) if err != nil { @@ -45,8 +33,21 @@ func main() { defer file.Close() + app := fiber.New(fiber.Config{ + StrictRouting: false, + DisableStartupMessage: true, + }) + app.Use(logger.New(logger.Config{ - Output: file, + // Output: file, + Format: "[${ip}]:${port} ${status} - ${method} ${path}\n", + })) + + app.Use(cors.New(cors.Config{ + AllowCredentials: true, + AllowOrigins: "http://*, https://*", + AllowHeaders: "Origin, Content-Type, Accept, Authorization, Access-Control-Allow-Origin", + AllowMethods: "GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS", })) if err := database.ConnectDB(); err != nil {