summaryrefslogtreecommitdiffstats
path: root/pkg/app/app.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-05-25 18:18:35 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-05-25 18:31:32 +1000
commite0ecc9e835ef56fae7ee58408ba91e29f000344d (patch)
tree94308647a248d326c1e0cdb863623cfe63b7d66b /pkg/app/app.go
parent1f8e838052a1bc083cb50560431b2f115df8acb6 (diff)
Allow global logging when developing
I'll be honest, for all I know logging should be global in general: it is a pain to pass a logger to any struct that needs it. But smart people on the internet tell me otherwise, and I do like the idea of not having any global variables lying around. Nonetheless, I often need to log things when locally debugging and that's a different kind of logging than the kind you would include in the actual released binary. For example if I want to log something from gocui, I would rather not have gocui depend on lazygit's logging setup.
Diffstat (limited to 'pkg/app/app.go')
-rw-r--r--pkg/app/app.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go
index af34b7157..e77d2868c 100644
--- a/pkg/app/app.go
+++ b/pkg/app/app.go
@@ -10,6 +10,7 @@ import (
"strings"
"github.com/go-errors/errors"
+ "github.com/sirupsen/logrus"
"github.com/jesseduffield/generics/slices"
appTypes "github.com/jesseduffield/lazygit/pkg/app/types"
@@ -22,6 +23,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/env"
"github.com/jesseduffield/lazygit/pkg/gui"
"github.com/jesseduffield/lazygit/pkg/i18n"
+ "github.com/jesseduffield/lazygit/pkg/logs"
"github.com/jesseduffield/lazygit/pkg/updates"
)
@@ -76,6 +78,18 @@ func NewCommon(config config.AppConfigurer) (*common.Common, error) {
}, nil
}
+func newLogger(cfg config.AppConfigurer) *logrus.Entry {
+ if cfg.GetDebug() {
+ logPath, err := config.LogPath()
+ if err != nil {
+ log.Fatal(err)
+ }
+ return logs.NewDevelopmentLogger(logPath)
+ } else {
+ return logs.NewProductionLogger()
+ }
+}
+
// NewApp bootstrap a new application
func NewApp(config config.AppConfigurer, common *common.Common) (*App, error) {
app := &App{