feat(main): add early logging initialization and asset embedding
- commit
- ed52bf73eec290788fa7f4065d2b5c4bb26494a4
- author
- bamen · · 2025-09-13 13:01 UTC
- committer
- bamen · · 2025-09-13 19:42 UTC
- parent
- adbcd0f
- signature
- unsigned
1 file · +20 -1
M main.go +20 -1
| @@ -2,16 +2,18 @@ package main | |||
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | 4 | "embed" | |
| 5 | + | "log" | |
| 5 | 6 | "os" | |
| 6 | 7 | "runtime" | |
| 7 | 8 | ||
| 8 | 9 | "github.com/bnema/dumber/internal/app/browser" | |
| 9 | 10 | "github.com/bnema/dumber/internal/app/cli" | |
| 11 | + | "github.com/bnema/dumber/internal/config" | |
| 10 | 12 | "github.com/bnema/dumber/internal/logging" | |
| 11 | 13 | "github.com/bnema/dumber/pkg/webkit" | |
| 12 | 14 | ) | |
| 13 | 15 | ||
| 14 | - | //go:embed frontend/dist | |
| 16 | + | //go:embed frontend/dist assets | |
| 15 | 17 | var assets embed.FS | |
| 16 | 18 | ||
| 17 | 19 | // Build information set via ldflags | |
| @@ -31,6 +33,23 @@ func main() { | |||
| 31 | 33 | return | |
| 32 | 34 | } | |
| 33 | 35 | ||
| 36 | + | // Initialize logging early for GUI mode using default config | |
| 37 | + | cfg := config.New() | |
| 38 | + | if err := logging.Init( | |
| 39 | + | cfg.Logging.LogDir, | |
| 40 | + | cfg.Logging.Level, | |
| 41 | + | cfg.Logging.Format, | |
| 42 | + | cfg.Logging.EnableFileLog, | |
| 43 | + | cfg.Logging.MaxSize, | |
| 44 | + | cfg.Logging.MaxBackups, | |
| 45 | + | cfg.Logging.MaxAge, | |
| 46 | + | cfg.Logging.Compress, | |
| 47 | + | ); err != nil { | |
| 48 | + | log.Printf("Warning: failed to initialize logging: %v", err) | |
| 49 | + | } | |
| 50 | + | ||
| 51 | + | log.Printf("Starting dumber browser v%s (commit: %s, built: %s)", version, commit, buildDate) | |
| 52 | + | ||
| 34 | 53 | // GTK requires all UI calls to run on the main OS thread | |
| 35 | 54 | if webkit.IsNativeAvailable() { | |
| 36 | 55 | runtime.LockOSThread() | |
| @@ -2,16 +2,18 @@ package main | |||||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | "embed" | 4 | "embed" | ||
| 5 | + | "log" | |||
| 5 | "os" | 6 | "os" | ||
| 6 | "runtime" | 7 | "runtime" | ||
| 7 | 8 | ||||
| 8 | "github.com/bnema/dumber/internal/app/browser" | 9 | "github.com/bnema/dumber/internal/app/browser" | ||
| 9 | "github.com/bnema/dumber/internal/app/cli" | 10 | "github.com/bnema/dumber/internal/app/cli" | ||
| 11 | + | "github.com/bnema/dumber/internal/config" | |||
| 10 | "github.com/bnema/dumber/internal/logging" | 12 | "github.com/bnema/dumber/internal/logging" | ||
| 11 | "github.com/bnema/dumber/pkg/webkit" | 13 | "github.com/bnema/dumber/pkg/webkit" | ||
| 12 | ) | 14 | ) | ||
| 13 | 15 | ||||
| 14 | - | //go:embed frontend/dist | 16 | + | //go:embed frontend/dist assets |
| 15 | var assets embed.FS | 17 | var assets embed.FS | ||
| 16 | 18 | ||||
| 17 | // Build information set via ldflags | 19 | // Build information set via ldflags | ||
| @@ -31,6 +33,23 @@ func main() { | |||||
| 31 | return | 33 | return | ||
| 32 | } | 34 | } | ||
| 33 | 35 | ||||
| 36 | + | // Initialize logging early for GUI mode using default config | |||
| 37 | + | cfg := config.New() | |||
| 38 | + | if err := logging.Init( | |||
| 39 | + | cfg.Logging.LogDir, | |||
| 40 | + | cfg.Logging.Level, | |||
| 41 | + | cfg.Logging.Format, | |||
| 42 | + | cfg.Logging.EnableFileLog, | |||
| 43 | + | cfg.Logging.MaxSize, | |||
| 44 | + | cfg.Logging.MaxBackups, | |||
| 45 | + | cfg.Logging.MaxAge, | |||
| 46 | + | cfg.Logging.Compress, | |||
| 47 | + | ); err != nil { | |||
| 48 | + | log.Printf("Warning: failed to initialize logging: %v", err) | |||
| 49 | + | } | |||
| 50 | + | ||||
| 51 | + | log.Printf("Starting dumber browser v%s (commit: %s, built: %s)", version, commit, buildDate) | |||
| 52 | + | ||||
| 34 | // GTK requires all UI calls to run on the main OS thread | 53 | // GTK requires all UI calls to run on the main OS thread | ||
| 35 | if webkit.IsNativeAvailable() { | 54 | if webkit.IsNativeAvailable() { | ||
| 36 | runtime.LockOSThread() | 55 | runtime.LockOSThread() | ||