diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2018-08-26 15:46:18 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2018-08-26 16:53:31 +1000 |
commit | 540edc0c35e97393d9a01c927f7ac962bcbf6d37 (patch) | |
tree | f9f93b1905828f0c665fc25819400e16f4cbc27e /pkg/app | |
parent | 93ab892bdd1226f9a519a938c8b28590e71e54f3 (diff) |
anonymous reporting data
Diffstat (limited to 'pkg/app')
-rw-r--r-- | pkg/app/app.go | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go index 102ab4146..a558e1b19 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -5,11 +5,12 @@ import ( "io/ioutil" "os" - "github.com/sirupsen/logrus" + "github.com/heroku/rollrus" "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui" "github.com/jesseduffield/lazygit/pkg/i18n" + "github.com/sirupsen/logrus" ) // App struct @@ -17,19 +18,26 @@ type App struct { closers []io.Closer Config config.AppConfigurer - Log *logrus.Logger + Log *logrus.Entry OSCommand *commands.OSCommand GitCommand *commands.GitCommand Gui *gui.Gui Tr *i18n.Localizer } -func newLogger(config config.AppConfigurer) *logrus.Logger { +func newProductionLogger(config config.AppConfigurer) *logrus.Logger { log := logrus.New() - if !config.GetDebug() { - log.Out = ioutil.Discard - return log + log.Out = ioutil.Discard + if config.GetUserConfig().GetString("reporting") == "on" { + // this isn't really a secret token: it only has permission to push new rollbar items + hook := rollrus.NewHook("23432119147a4367abf7c0de2aa99a2d", "production") + log.Hooks.Add(hook) } + return log +} + +func newDevelopmentLogger() *logrus.Logger { + log := logrus.New() file, err := os.OpenFile("development.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) if err != nil { panic("unable to log to file") // TODO: don't panic (also, remove this call to the `panic` function) @@ -38,6 +46,21 @@ func newLogger(config config.AppConfigurer) *logrus.Logger { return log } +func newLogger(config config.AppConfigurer) *logrus.Entry { + var log *logrus.Logger + if config.GetDebug() { + log = newDevelopmentLogger() + } else { + log = newProductionLogger(config) + } + return log.WithFields(logrus.Fields{ + "debug": config.GetDebug(), + "version": config.GetVersion(), + "commit": config.GetCommit(), + "buildDate": config.GetBuildDate(), + }) +} + // NewApp retruns a new applications func NewApp(config config.AppConfigurer) (*App, error) { app := &App{ |