diff --git a/cmd/soft/root.go b/cmd/soft/root.go index e8317dd88..1f4cbeacd 100644 --- a/cmd/soft/root.go +++ b/cmd/soft/root.go @@ -4,6 +4,7 @@ import ( "runtime/debug" "github.com/charmbracelet/log" + _ "github.com/charmbracelet/soft-serve/log" "github.com/spf13/cobra" ) diff --git a/cmd/soft/serve.go b/cmd/soft/serve.go index 469ba8546..332796394 100644 --- a/cmd/soft/serve.go +++ b/cmd/soft/serve.go @@ -7,7 +7,6 @@ import ( "syscall" "time" - "github.com/charmbracelet/log" "github.com/charmbracelet/soft-serve/server" "github.com/charmbracelet/soft-serve/server/config" "github.com/spf13/cobra" @@ -26,10 +25,6 @@ var ( return err } - if cfg.Debug { - log.SetLevel(log.DebugLevel) - } - done := make(chan os.Signal, 1) lch := make(chan error, 1) go func() { diff --git a/server/config/config.go b/server/config/config.go index 14dcff657..a7bc67f9c 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -51,9 +51,6 @@ type Config struct { // DataPath is the path to the directory where Soft Serve will store its data. DataPath string `env:"DATA_PATH" envDefault:"data"` - // Debug enables debug logging. - Debug bool `env:"DEBUG" envDefault:"false"` - // Backend is the Git backend to use. Backend backend.Backend @@ -70,9 +67,6 @@ func DefaultConfig() *Config { }); err != nil { log.Fatal(err) } - if cfg.Debug { - log.SetLevel(log.DebugLevel) - } fb, err := file.NewFileBackend(cfg.DataPath) if err != nil { log.Fatal(err) diff --git a/server/ssh.go b/server/ssh.go index 1c7392825..5a1752a4f 100644 --- a/server/ssh.go +++ b/server/ssh.go @@ -40,6 +40,7 @@ func NewSSHServer(cfg *config.Config) (*SSHServer, error) { cm.Middleware(cfg), // Git middleware. s.Middleware(cfg), + // Logging middleware. lm.MiddlewareWithLogger(logger), ), } @@ -66,9 +67,7 @@ func NewSSHServer(cfg *config.Config) (*SSHServer, error) { // PublicKeyAuthHandler handles public key authentication. func (s *SSHServer) PublicKeyHandler(ctx ssh.Context, pk ssh.PublicKey) bool { - al := s.cfg.Access.AccessLevel("", pk) - logger.Debug("publickey handler", "level", al) - return al > backend.NoAccess + return s.cfg.Access.AccessLevel("", pk) > backend.NoAccess } // KeyboardInteractiveHandler handles keyboard interactive authentication. diff --git a/ui/pages/repo/log.go b/ui/pages/repo/log.go index 23bc23880..6b5546590 100644 --- a/ui/pages/repo/log.go +++ b/ui/pages/repo/log.go @@ -2,7 +2,6 @@ package repo import ( "fmt" - "log" "strings" "time" @@ -386,7 +385,7 @@ func (l *Log) StatusBarInfo() string { func (l *Log) countCommitsCmd() tea.Msg { if l.ref == nil { - log.Printf("ui: log: ref is nil") + logger.Debugf("ui: log: ref is nil") return common.ErrorMsg(errNoRef) } r, err := l.repo.Repository() @@ -395,7 +394,7 @@ func (l *Log) countCommitsCmd() tea.Msg { } count, err := r.CountCommits(l.ref) if err != nil { - log.Printf("ui: error counting commits: %v", err) + logger.Debugf("ui: error counting commits: %v", err) return common.ErrorMsg(err) } return LogCountMsg(count) @@ -412,7 +411,7 @@ func (l *Log) updateCommitsCmd() tea.Msg { } } if l.ref == nil { - log.Printf("ui: log: ref is nil") + logger.Debugf("ui: log: ref is nil") return common.ErrorMsg(errNoRef) } items := make([]selector.IdentifiableItem, count) @@ -426,7 +425,7 @@ func (l *Log) updateCommitsCmd() tea.Msg { // CommitsByPage pages start at 1 cc, err := r.CommitsByPage(l.ref, page+1, limit) if err != nil { - log.Printf("ui: error loading commits: %v", err) + logger.Debugf("ui: error loading commits: %v", err) return common.ErrorMsg(err) } for i, c := range cc { @@ -448,12 +447,12 @@ func (l *Log) selectCommitCmd(commit *git.Commit) tea.Cmd { func (l *Log) loadDiffCmd() tea.Msg { r, err := l.repo.Repository() if err != nil { - log.Printf("ui: error loading diff repository: %v", err) + logger.Debugf("ui: error loading diff repository: %v", err) return common.ErrorMsg(err) } diff, err := r.Diff(l.selectedCommit) if err != nil { - log.Printf("ui: error loading diff: %v", err) + logger.Debugf("ui: error loading diff: %v", err) return common.ErrorMsg(err) } return LogDiffMsg(diff) diff --git a/ui/pages/repo/refs.go b/ui/pages/repo/refs.go index b0af0defe..aa4e81f94 100644 --- a/ui/pages/repo/refs.go +++ b/ui/pages/repo/refs.go @@ -3,7 +3,6 @@ package repo import ( "errors" "fmt" - "log" "sort" "strings" @@ -182,7 +181,7 @@ func (r *Refs) updateItemsCmd() tea.Msg { } refs, err := rr.References() if err != nil { - log.Printf("ui: error getting references: %v", err) + logger.Debugf("ui: error getting references: %v", err) return common.ErrorMsg(err) } for _, ref := range refs { @@ -228,10 +227,10 @@ func UpdateRefCmd(repo backend.Repository) tea.Cmd { if bs, err := r.Branches(); err != nil && len(bs) == 0 { return EmptyRepoMsg{} } - log.Printf("ui: error getting HEAD reference: %v", err) + logger.Debugf("ui: error getting HEAD reference: %v", err) return common.ErrorMsg(err) } - log.Printf("HEAD: %s", ref.Name()) + logger.Debugf("HEAD: %s", ref.Name()) return RefMsg(ref) } } diff --git a/ui/pages/repo/repo.go b/ui/pages/repo/repo.go index 5d498b154..16c2af44f 100644 --- a/ui/pages/repo/repo.go +++ b/ui/pages/repo/repo.go @@ -9,6 +9,7 @@ import ( "github.com/charmbracelet/bubbles/spinner" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/log" "github.com/charmbracelet/soft-serve/git" "github.com/charmbracelet/soft-serve/server/backend" "github.com/charmbracelet/soft-serve/ui/common" @@ -17,6 +18,10 @@ import ( "github.com/charmbracelet/soft-serve/ui/components/tabs" ) +var ( + logger = log.WithPrefix("ui.repo") +) + type state int const ( diff --git a/ui/pages/selection/selection.go b/ui/pages/selection/selection.go index 5638a743e..bfd1f31f6 100644 --- a/ui/pages/selection/selection.go +++ b/ui/pages/selection/selection.go @@ -2,19 +2,23 @@ package selection import ( "fmt" - "log" "sort" "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/list" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/log" "github.com/charmbracelet/soft-serve/ui/common" "github.com/charmbracelet/soft-serve/ui/components/code" "github.com/charmbracelet/soft-serve/ui/components/selector" "github.com/charmbracelet/soft-serve/ui/components/tabs" ) +var ( + logger = log.WithPrefix("ui.selection") +) + type pane int const ( @@ -191,7 +195,7 @@ func (s *Selection) Init() tea.Cmd { for _, r := range repos { item, err := NewItem(r, cfg) if err != nil { - log.Printf("ui: failed to create item for %s: %v", r.Name(), err) + logger.Debugf("ui: failed to create item for %s: %v", r.Name(), err) continue } sortedItems = append(sortedItems, item) diff --git a/ui/ui.go b/ui/ui.go index e81de69c3..29f4cde45 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -2,12 +2,12 @@ package ui import ( "errors" - "log" "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/list" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/log" "github.com/charmbracelet/soft-serve/server/backend" "github.com/charmbracelet/soft-serve/ui/common" "github.com/charmbracelet/soft-serve/ui/components/footer" @@ -17,6 +17,10 @@ import ( "github.com/charmbracelet/soft-serve/ui/pages/selection" ) +var ( + logger = log.WithPrefix("ui") +) + type page int const ( @@ -164,7 +168,7 @@ func (ui *UI) IsFiltering() bool { // Update implements tea.Model. func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { - log.Printf("msg received: %T", msg) + logger.Debugf("msg received: %T", msg) cmds := make([]tea.Cmd, 0) switch msg := msg.(type) { case tea.WindowSizeMsg: @@ -294,7 +298,7 @@ func (ui *UI) openRepo(rn string) (backend.Repository, error) { } repos, err := cfg.Backend.Repositories() if err != nil { - log.Printf("ui: failed to list repos: %v", err) + logger.Debugf("ui: failed to list repos: %v", err) return nil, err } for _, r := range repos {