Add Zap logging framework with structured logging for Echo and Grafana

This commit is contained in:
2026-05-20 22:29:45 +02:00
parent 82252ce1ff
commit 37909139de
7 changed files with 64 additions and 37 deletions
+9 -8
View File
@@ -1,8 +1,8 @@
package server
import (
"log"
"music-server/internal/backend"
"music-server/internal/logging"
"net/http"
"github.com/labstack/echo/v5"
@@ -25,11 +25,11 @@ func NewSyncHandler() *SyncHandler {
// @Router /sync/progress [get]
func (s *SyncHandler) SyncProgress(ctx *echo.Context) error {
if backend.Syncing {
log.Println("Getting progress")
logging.GetLogger().Info("Getting sync progress")
response := backend.SyncProgress()
return ctx.JSON(http.StatusOK, response)
}
log.Println("Getting result")
logging.GetLogger().Info("Getting sync result")
response := backend.SyncResult()
return ctx.JSON(http.StatusOK, response)
}
@@ -45,10 +45,10 @@ func (s *SyncHandler) SyncProgress(ctx *echo.Context) error {
// @Router /sync [get]
func (s *SyncHandler) SyncGamesNewOnlyChanges(ctx *echo.Context) error {
if backend.Syncing {
log.Println("Syncing is in progress")
logging.GetLogger().Warn("Syncing is already in progress")
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
}
log.Println("Start syncing games")
logging.GetLogger().Info("Starting sync with only changes")
go backend.SyncGamesNewOnlyChanges()
return ctx.JSON(http.StatusOK, "Start syncing games")
}
@@ -64,10 +64,10 @@ func (s *SyncHandler) SyncGamesNewOnlyChanges(ctx *echo.Context) error {
// @Router /sync/full [get]
func (s *SyncHandler) SyncGamesNewFull(ctx *echo.Context) error {
if backend.Syncing {
log.Println("Syncing is in progress")
logging.GetLogger().Warn("Syncing is already in progress")
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
}
log.Println("Start syncing games full")
logging.GetLogger().Info("Starting full sync")
go backend.SyncGamesNewFull()
return ctx.JSON(http.StatusOK, "Start syncing games full")
}
@@ -83,9 +83,10 @@ func (s *SyncHandler) SyncGamesNewFull(ctx *echo.Context) error {
// @Router /sync/reset [get]
func (s *SyncHandler) ResetGames(ctx *echo.Context) error {
if backend.Syncing {
log.Println("Syncing is in progress")
logging.GetLogger().Warn("Cannot reset - syncing is in progress")
return ctx.JSON(http.StatusLocked, "Syncing is in progress")
}
logging.GetLogger().Info("Resetting games database")
backend.ResetDB()
return ctx.JSON(http.StatusOK, "Games and songs are deleted from the database")
}