Add comprehensive logging and debug endpoints for production troubleshooting

- Add request logging middleware to main.go
- Add debug handler with health, config, stats, and test-dns endpoints
- Add detailed logging to DynDNS handler
- Add logging to Technitium DNS client
- Add database Ping() and GetStats() methods
- New endpoints:
  - /health - detailed health status with database and DNS checks
  - /debug/config - sanitized configuration
  - /debug/stats - database statistics
  - /debug/test-dns - live DNS test endpoint

This will help diagnose production issues with DNS updates.
This commit is contained in:
2026-02-02 22:14:24 -05:00
parent ad494fa623
commit 01694f66a8
5 changed files with 266 additions and 0 deletions

View File

@@ -45,6 +45,25 @@ func main() {
gin.SetMode(gin.ReleaseMode)
router := gin.New()
router.Use(gin.Recovery())
// Add request logging middleware
router.Use(func(c *gin.Context) {
start := time.Now()
path := c.Request.URL.Path
raw := c.Request.URL.RawQuery
c.Next()
latency := time.Since(start)
clientIP := c.ClientIP()
method := c.Request.Method
statusCode := c.Writer.Status()
if raw != "" {
path = path + "?" + raw
}
log.Printf("[%s] %s %s %d %v", clientIP, method, path, statusCode, latency)
})
if len(cfg.TrustedProxies) > 0 {
router.SetTrustedProxies(cfg.TrustedProxies)
@@ -55,9 +74,16 @@ func main() {
webHandler := handlers.NewWebHandler(db, cfg)
dynHandler := handlers.NewDynDNSHandler(db, dnsClient, cfg)
debugHandler := handlers.NewDebugHandler(db, dnsClient, cfg)
router.GET("/", webHandler.Index)
// Debug/health endpoints (no rate limiting)
router.GET("/health", debugHandler.Health)
router.GET("/debug/config", debugHandler.ConfigDebug)
router.GET("/debug/stats", debugHandler.Stats)
router.GET("/debug/test-dns", debugHandler.TestDNS)
api := router.Group("/api")
api.Use(rateLimiter.RateLimitByIP())
{