From c2d0d64c7d70582466e309bbc3bb36fce86fe26c Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 8 Jul 2025 15:55:36 -0400 Subject: [PATCH] refactor(log): rename log initialization function for clarity --- internal/config/load.go | 8 ++------ internal/fsext/fileutil.go | 4 ++-- internal/log/log.go | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/internal/config/load.go b/internal/config/load.go index d472c2a9632dd704a998bb7d427974b5b338cd76..84585d05d56dddbac36d2d147cc5c4cada781c7e 100644 --- a/internal/config/load.go +++ b/internal/config/load.go @@ -52,16 +52,12 @@ func Load(workingDir string, debug bool) (*Config, error) { cfg.Options.Debug = true } - // Init logs - log.Init( + // Setup logs + log.Setup( filepath.Join(cfg.Options.DataDirectory, "logs", fmt.Sprintf("%s.log", appName)), cfg.Options.Debug, ) - if err != nil { - return nil, fmt.Errorf("failed to load config: %w", err) - } - // Load known providers, this loads the config from fur providers, err := LoadProviders(client.New()) if err != nil || len(providers) == 0 { diff --git a/internal/fsext/fileutil.go b/internal/fsext/fileutil.go index 677613ffc047919c7cf888a888da8ccbce7ea585..c3678041de4239cf66247ebbd9cb084cb8eb6b8a 100644 --- a/internal/fsext/fileutil.go +++ b/internal/fsext/fileutil.go @@ -26,13 +26,13 @@ func init() { var err error rgPath, err = exec.LookPath("rg") if err != nil { - if log.IsInitialized() { + if log.Initialized() { slog.Warn("Ripgrep (rg) not found in $PATH. Some features might be limited or slower.") } } fzfPath, err = exec.LookPath("fzf") if err != nil { - if log.IsInitialized() { + if log.Initialized() { slog.Warn("FZF not found in $PATH. Some features might be limited or slower.") } } diff --git a/internal/log/log.go b/internal/log/log.go index 8d2583cdabb0a6d4184137e25e36bf253d86d858..bf99fe60fa9a5015029af171adfd6b3f9bf5596b 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -17,7 +17,7 @@ var ( initialized atomic.Bool ) -func Init(logFile string, debug bool) { +func Setup(logFile string, debug bool) { initOnce.Do(func() { logRotator := &lumberjack.Logger{ Filename: logFile, @@ -42,7 +42,7 @@ func Init(logFile string, debug bool) { }) } -func IsInitialized() bool { +func Initialized() bool { return initialized.Load() }