Change logging to be json comaptible

This commit is contained in:
2026-05-03 22:42:43 +02:00
parent d1f6782c96
commit 1a82f21202
14 changed files with 501 additions and 35 deletions

View File

@@ -1,6 +1,7 @@
package web
import (
"ResendIt/internal/api/middleware"
"ResendIt/internal/buildinfo"
"ResendIt/internal/config"
"ResendIt/internal/file"
@@ -51,16 +52,23 @@ func (h *Handler) LoginPage(c *gin.Context) {
}
func (h *Handler) FileView(c *gin.Context) {
log := middleware.StructuredLog(c).With().
Str("event", "file_view_page").
Logger()
id := c.Param("id")
fileRecord, err := h.fileService.GetFileByViewID(id)
if err != nil {
log.Warn().Str("view_id", id).Err(err).Msg("File view failed - not found")
c.HTML(404, "error.html", gin.H{
"MODT": h.configService.GetStringDefault(config.KeyModtext, config.DefaultModt),
})
return
}
log.Info().Str("view_id", id).Str("filename", fileRecord.Filename).Msg("File view page rendered")
downloadKey := fileRecord.ID
deleteKey := fileRecord.DeletionID
@@ -73,6 +81,10 @@ func (h *Handler) FileView(c *gin.Context) {
}
func (h *Handler) AdminPage(c *gin.Context) {
log := middleware.StructuredLog(c).With().
Str("event", "admin_page_view").
Logger()
pageStr := c.Query("page")
page, err := strconv.Atoi(pageStr)
if err != nil || page < 1 {
@@ -84,6 +96,7 @@ func (h *Handler) AdminPage(c *gin.Context) {
files, totalCount, err := h.fileService.GetPaginatedFiles(limit, offset)
if err != nil {
log.Error().Err(err).Msg("Failed to load files for admin page")
c.HTML(500, "admin.html", gin.H{
"error": err.Error(),
})
@@ -117,6 +130,8 @@ func (h *Handler) AdminPage(c *gin.Context) {
totalPages := (totalCount + limit - 1) / limit
log.Debug().Int("page", page).Int("total_files", totalCount).Msg("Admin page viewed")
c.HTML(200, "admin.html", gin.H{
"Files": adminFiles,
"Page": page,
@@ -126,10 +141,16 @@ func (h *Handler) AdminPage(c *gin.Context) {
}
func (h *Handler) Logout(c *gin.Context) {
log := middleware.StructuredLog(c).With().
Str("event", "logout").
Logger()
log.Info().Msg("User logged out")
c.SetCookie("auth_token", "", -1, "/", "", false, true)
c.Redirect(302, "/")
}
func (h *Handler) ChangePasswordPage(c *gin.Context) {
c.HTML(200, "changePassword.html", nil)
}
}