this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: better logging options in dev mode

Previously in dev mode, logs went to stdout even if you had specified a file to
log to. Now if you specify a file, we'll not send them to stdout as well.

+31 -1
+16
cmd/tumble/main.go
··· 4 4 "context" 5 5 "io" 6 6 "io/fs" 7 + "log" 7 8 "log/slog" 8 9 "net/http" 9 10 "os" ··· 80 81 defer f.Close() 81 82 output = f 82 83 } 84 + } 85 + 86 + // Redirect standard log library to the same output 87 + // This captures logs from libraries or legacy code (like irclink.go) 88 + // preventing them from leaking to stdout/stderr if a file is configured. 89 + // We only do this if we aren't writing to stdout/stderr to match expected behavior 90 + // of "if log file is specified, do not output to stdout" 91 + if cfg.Mode == "development" || cfg.Mode == "dev" { 92 + // If we are in dev mode and have a specific file output, we force standard log to that file too 93 + // If output is already stdout/stderr, this is a no-op effectively 94 + log.SetOutput(output) 95 + } else { 96 + // In production/other modes, we also likely want to capture standard logs into our structured log stream 97 + // or at least to the same destination. 98 + log.SetOutput(output) 83 99 } 84 100 85 101 var level slog.Level
+15 -1
internal/data/factory.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 + "log" 5 6 "strings" 7 + "time" 6 8 7 9 "tumble/internal/config" 8 10 ··· 31 33 logLevel = logger.Info 32 34 } 33 35 36 + // Use the global log writer which main.go has configured 37 + // regardless of whether it's stdout or a file. 38 + newLogger := logger.New( 39 + log.New(log.Writer(), "\r\n", log.LstdFlags), 40 + logger.Config{ 41 + SlowThreshold: 200 * time.Millisecond, 42 + LogLevel: logLevel, 43 + IgnoreRecordNotFoundError: false, 44 + Colorful: false, 45 + }, 46 + ) 47 + 34 48 db, err := gorm.Open(dialector, &gorm.Config{ 35 - Logger: logger.Default.LogMode(logLevel), 49 + Logger: newLogger, 36 50 }) 37 51 if err != nil { 38 52 return nil, err