fix: refine logging
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 44s
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 48s

This commit was merged in pull request #293.
This commit is contained in:
2024-12-04 21:49:44 +01:00
parent 5198487feb
commit 521119fc02
14 changed files with 93 additions and 70 deletions

View File

@@ -1,10 +1,11 @@
package utils
import (
"me-fit/log"
"me-fit/types"
"database/sql"
"errors"
"log/slog"
"me-fit/types"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/sqlite3"
@@ -14,7 +15,7 @@ import (
func RunMigrations(db *sql.DB, pathPrefix string) error {
driver, err := sqlite3.WithInstance(db, &sqlite3.Config{})
if err != nil {
slog.Error("Could not create Migration instance: " + err.Error())
log.Error("Could not create Migration instance: %v", err)
return types.ErrInternal
}
@@ -23,14 +24,14 @@ func RunMigrations(db *sql.DB, pathPrefix string) error {
"",
driver)
if err != nil {
slog.Error("Could not create migrations instance: " + err.Error())
log.Error("Could not create migrations instance: %v", err)
return types.ErrInternal
}
err = m.Up()
if err != nil {
if !errors.Is(err, migrate.ErrNoChange) {
slog.Error("Could not run migrations: " + err.Error())
log.Error("Could not run migrations: %v", err)
return types.ErrInternal
}
}

View File

@@ -12,7 +12,7 @@ func TriggerToast(w http.ResponseWriter, r *http.Request, class string, message
if isHtmx(r) {
w.Header().Set("HX-Trigger", fmt.Sprintf(`{"toast": "%v|%v"}`, class, message))
} else {
log.ErrorMsg("Trying to trigger toast in non-HTMX request")
log.Error("Trying to trigger toast in non-HTMX request")
}
}