Add custom logger with source location tracking and remove verbose database logs

- Create internal/logger package with Logger wrapper around slog
- Logger automatically adds source file, line number, and function name to all log entries
- Use golang.org/x/term to properly detect if stdout is a terminal
- Replace all slog.Logger usage with logger.Logger throughout the codebase
- Remove verbose logging from database GetStats() method
- Update all constructors and dependencies to use the new logger
This commit is contained in:
2025-07-28 01:14:51 +02:00
parent 3f06955214
commit 67f6b78aaa
22 changed files with 212 additions and 97 deletions

View File

@@ -5,7 +5,6 @@ import (
"compress/gzip"
"encoding/json"
"fmt"
"log/slog"
"os"
"path/filepath"
"strings"
@@ -14,6 +13,7 @@ import (
"time"
"git.eeqj.de/sneak/routewatch/internal/config"
"git.eeqj.de/sneak/routewatch/internal/logger"
"github.com/google/uuid"
)
@@ -68,7 +68,7 @@ type RoutingTable struct {
}
// New creates a new routing table, loading from snapshot if available
func New(cfg *config.Config, logger *slog.Logger) *RoutingTable {
func New(cfg *config.Config, logger *logger.Logger) *RoutingTable {
rt := &RoutingTable{
routes: make(map[RouteKey]*Route),
byPrefix: make(map[uuid.UUID]map[RouteKey]*Route),
@@ -452,7 +452,7 @@ func isIPv6(prefix string) bool {
}
// loadFromSnapshot attempts to load the routing table from a snapshot file
func (rt *RoutingTable) loadFromSnapshot(logger *slog.Logger) error {
func (rt *RoutingTable) loadFromSnapshot(logger *logger.Logger) error {
// If no snapshot directory specified, nothing to load
if rt.snapshotDir == "" {
return nil

View File

@@ -1,18 +1,18 @@
package routingtable
import (
"log/slog"
"sync"
"testing"
"time"
"git.eeqj.de/sneak/routewatch/internal/config"
"git.eeqj.de/sneak/routewatch/internal/logger"
"github.com/google/uuid"
)
func TestRoutingTable(t *testing.T) {
// Create a test logger
logger := slog.Default()
logger := logger.New()
// Create test config with empty state dir (no snapshot loading)
cfg := &config.Config{
@@ -129,7 +129,7 @@ func TestRoutingTable(t *testing.T) {
func TestRoutingTableConcurrency(t *testing.T) {
// Create a test logger
logger := slog.Default()
logger := logger.New()
// Create test config with empty state dir (no snapshot loading)
cfg := &config.Config{
@@ -189,7 +189,7 @@ func TestRoutingTableConcurrency(t *testing.T) {
func TestRouteUpdate(t *testing.T) {
// Create a test logger
logger := slog.Default()
logger := logger.New()
// Create test config with empty state dir (no snapshot loading)
cfg := &config.Config{