Separate structured logs from human-readable output

Move SetupLogger() to a standalone function called before config.Load()
so the logger is available from the very start. Replace all fmt.Printf
calls in config.go with slog calls. Redirect banner and endpoint info
to stderr, keeping stdout clean for structured log output (JSON/text).

Fixes #5
This commit is contained in:
eduard256
2026-03-22 17:44:16 +00:00
parent 4fe5ae9447
commit 3fafdbc6ce
2 changed files with 53 additions and 28 deletions
+14 -14
View File
@@ -36,18 +36,18 @@ Version: %s
`
func main() {
// Print banner
fmt.Printf(Banner, Version)
fmt.Println()
// Print banner to stderr so it doesn't mix with structured log output on stdout
fmt.Fprintf(os.Stderr, Banner, Version)
fmt.Fprintln(os.Stderr)
// Load configuration
cfg := config.Load()
cfg.Version = Version
// Setup logger
slogger, secrets := cfg.SetupLogger()
// Setup logger first, before anything else, so all messages use consistent format
slogger, secrets := config.SetupLogger()
slog.SetDefault(slogger)
// Load configuration (uses the logger for startup messages)
cfg := config.Load(slogger)
cfg.Version = Version
// Create adapter for our interface
log := logger.NewAdapter(slogger, secrets)
@@ -193,10 +193,10 @@ func printEndpoints(listen string) {
// ANSI escape codes for clickable link (OSC 8 hyperlink)
clickableURL := fmt.Sprintf("\033]8;;%s\033\\%s\033]8;;\033\\", url, url)
fmt.Println("\n🌐 Web Interface:")
fmt.Println("────────────────────────────────────────────────")
fmt.Printf(" Open in browser: %s\n", clickableURL)
fmt.Println("────────────────────────────────────────────────")
fmt.Fprintln(os.Stderr, "\nWeb Interface:")
fmt.Fprintln(os.Stderr, "────────────────────────────────────────────────")
fmt.Fprintf(os.Stderr, " Open in browser: %s\n", clickableURL)
fmt.Fprintln(os.Stderr, "────────────────────────────────────────────────")
fmt.Println("\n📚 Documentation: https://github.com/eduard256/Strix")
fmt.Fprintln(os.Stderr, "\nDocumentation: https://github.com/eduard256/Strix")
}