Skip to content

Commit

Permalink
feat: zerologging from error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Aug 20, 2024
1 parent 9fc9b65 commit 5b9d9a1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions node/pkg/api/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"log"
"os"
"runtime/debug"
"strconv"
Expand All @@ -22,6 +21,7 @@ import (
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/rs/zerolog/log"
)

type AppConfig struct {
Expand Down Expand Up @@ -275,7 +275,7 @@ func CustomErrorHandler(c *fiber.Ctx, err error) error {

// Return status code with error message
// | ${status} | ${ip} | ${method} | ${path} | ${error}",
log.Printf("| %d | %s | %s | %s | %s\n", code, c.IP(), c.Method(), c.Path(), err.Error())
log.Error().Err(err).Str("call info", fmt.Sprintf("| %d | %s | %s | %s | %s\n", code, c.IP(), c.Method(), c.Path(), err.Error()))
return c.Status(code).SendString(err.Error())
}

Expand All @@ -292,6 +292,6 @@ func CustomStackTraceHandler(_ *fiber.Ctx, e interface{}) {
break
}
}
log.Printf("| (%s) panic: %v \n", failPoint, e)
log.Debug().Any("stacktrace", stackTrace).Str("failPoint", failPoint).Msgf("panic: %v", e)
_, _ = os.Stderr.WriteString(fmt.Sprintf("%s\n", debug.Stack())) //nolint:errcheck // This will never fail
}

0 comments on commit 5b9d9a1

Please sign in to comment.