on main help sign in
refactor(log): rename log initialization function for clarity
c2d0d64Ayman Bagabas
internal/config/load.go+2−6
@@ -52,16 +52,12 @@ func Load(workingDir string, debug bool) (*Config, error) {
52 cfg.Options.Debug = true
52 cfg.Options.Debug = true
53 }
53 }
54
54
55− // Init logs
55+ // Setup logs
56− log.Init(
56+ log.Setup(
57 filepath.Join(cfg.Options.DataDirectory, "logs", fmt.Sprintf("%s.log", appName)),
57 filepath.Join(cfg.Options.DataDirectory, "logs", fmt.Sprintf("%s.log", appName)),
58 cfg.Options.Debug,
58 cfg.Options.Debug,
59 )
59 )
60
60
61− if err != nil {
62− return nil, fmt.Errorf("failed to load config: %w", err)
63− }
64−
65 // Load known providers, this loads the config from fur
61 // Load known providers, this loads the config from fur
66 providers, err := LoadProviders(client.New())
62 providers, err := LoadProviders(client.New())
67 if err != nil || len(providers) == 0 {
63 if err != nil || len(providers) == 0 {
internal/fsext/fileutil.go+2−2
@@ -26,13 +26,13 @@ func init() {
26 var err error
26 var err error
27 rgPath, err = exec.LookPath("rg")
27 rgPath, err = exec.LookPath("rg")
28 if err != nil {
28 if err != nil {
29− if log.IsInitialized() {
29+ if log.Initialized() {
30 slog.Warn("Ripgrep (rg) not found in $PATH. Some features might be limited or slower.")
30 slog.Warn("Ripgrep (rg) not found in $PATH. Some features might be limited or slower.")
31 }
31 }
32 }
32 }
33 fzfPath, err = exec.LookPath("fzf")
33 fzfPath, err = exec.LookPath("fzf")
34 if err != nil {
34 if err != nil {
35− if log.IsInitialized() {
35+ if log.Initialized() {
36 slog.Warn("FZF not found in $PATH. Some features might be limited or slower.")
36 slog.Warn("FZF not found in $PATH. Some features might be limited or slower.")
37 }
37 }
38 }
38 }
internal/log/log.go+2−2
@@ -17,7 +17,7 @@ var (
17 initialized atomic.Bool
17 initialized atomic.Bool
18)
18)
19
19
20−func Init(logFile string, debug bool) {
20+func Setup(logFile string, debug bool) {
21 initOnce.Do(func() {
21 initOnce.Do(func() {
22 logRotator := &lumberjack.Logger{
22 logRotator := &lumberjack.Logger{
23 Filename: logFile,
23 Filename: logFile,
@@ -42,7 +42,7 @@ func Init(logFile string, debug bool) {
42 })
42 })
43}
43}
44
44
45−func IsInitialized() bool {
45+func Initialized() bool {
46 return initialized.Load()
46 return initialized.Load()
47}
47}
48
48