trying to log requests

pull/1/head
Nilo Roberto C Paim 2023-08-13 08:26:15 -03:00
parent 0948f2c5f5
commit 3329a56e38
1 changed files with 14 additions and 13 deletions

27
main.go
View File

@ -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 {