on main help sign in
Merge pull request #113 from charmbracelet/log-warn

Remove Ripgrep and FZF warnings from stderr

commiteeeb9a036c309b9132cc2f7129478f37872aa8d2 authorKujtim Hoxha <kujtimii.h@gmail.com> dateWed 9 Jul 2025, 09:46 (1 year ago) parentf4c7c5cc2d0d64
3 files changed+20−10
internal/config/load.go+2−6 internal/fsext/fileutil.go+7−2 internal/log/log.go+11−2
internal/config/load.go+2−6
@@ -52,16 +52,12 @@ func Load(workingDir string, debug bool) (*Config, error) {
5252 cfg.Options.Debug = true
5353 }
5454
55− // Init logs
56− log.Init(
55+ // Setup logs
56+ log.Setup(
5757 filepath.Join(cfg.Options.DataDirectory, "logs", fmt.Sprintf("%s.log", appName)),
5858 cfg.Options.Debug,
5959 )
6060
61− if err != nil {
62− return nil, fmt.Errorf("failed to load config: %w", err)
63− }
64−
6561 // Load known providers, this loads the config from fur
6662 providers, err := LoadProviders(client.New())
6763 if err != nil || len(providers) == 0 {
internal/fsext/fileutil.go+7−2
@@ -12,6 +12,7 @@ import (
1212
1313 "github.com/bmatcuk/doublestar/v4"
1414 "github.com/charlievieth/fastwalk"
15+ "github.com/charmbracelet/crush/internal/log"
1516
1617 ignore "github.com/sabhiram/go-gitignore"
1718)
@@ -25,11 +26,15 @@ func init() {
2526 var err error
2627 rgPath, err = exec.LookPath("rg")
2728 if err != nil {
28− slog.Warn("Ripgrep (rg) not found in $PATH. Some features might be limited or slower.")
29+ if log.Initialized() {
30+ slog.Warn("Ripgrep (rg) not found in $PATH. Some features might be limited or slower.")
31+ }
2932 }
3033 fzfPath, err = exec.LookPath("fzf")
3134 if err != nil {
32− slog.Warn("FZF not found in $PATH. Some features might be limited or slower.")
35+ if log.Initialized() {
36+ slog.Warn("FZF not found in $PATH. Some features might be limited or slower.")
37+ }
3338 }
3439}
3540
internal/log/log.go+11−2
@@ -6,14 +6,18 @@ import (
66 "os"
77 "runtime/debug"
88 "sync"
9+ "sync/atomic"
910 "time"
1011
1112 "gopkg.in/natefinch/lumberjack.v2"
1213)
1314
14−var initOnce sync.Once
15+var (
16+ initOnce sync.Once
17+ initialized atomic.Bool
18+)
1519
16−func Init(logFile string, debug bool) {
20+func Setup(logFile string, debug bool) {
1721 initOnce.Do(func() {
1822 logRotator := &lumberjack.Logger{
1923 Filename: logFile,
@@ -34,9 +38,14 @@ func Init(logFile string, debug bool) {
3438 })
3539
3640 slog.SetDefault(slog.New(logger))
41+ initialized.Store(true)
3742 })
3843}
3944
45+func Initialized() bool {
46+ return initialized.Load()
47+}
48+
4049func RecoverPanic(name string, cleanup func()) {
4150 if r := recover(); r != nil {
4251 // Create a timestamped panic log file