refactoring and introduction of logrus logging

This commit is contained in:
2025-09-14 16:10:29 -06:00
parent ae3c9ca748
commit cc8c12e24d
5 changed files with 66 additions and 2 deletions
+39
View File
@@ -0,0 +1,39 @@
/*
* Amsterdam Web Communities System
* Copyright (c) 2025 Erbosoft Metaverse Design Solutions, All Rights Reserved
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package main
import (
"time"
"github.com/labstack/echo/v4"
log "github.com/sirupsen/logrus"
)
// Custom Logrus middleware
func LogrusMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
start := time.Now()
err := next(c)
stop := time.Now()
req := c.Request()
res := c.Response()
log.WithFields(log.Fields{
"remote_ip": c.RealIP(),
"host": req.Host,
"method": req.Method,
"uri": req.RequestURI,
"status": res.Status,
"latency_ms": stop.Sub(start).Milliseconds(),
"user_agent": req.UserAgent(),
}).Info("handled request")
return err
}
}