diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2018-08-27 20:35:55 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2018-08-27 20:35:55 +1000 |
commit | 23a9f41d9db3e449ec79e4fde46c54b3c5611368 (patch) | |
tree | 969b5f9348c5f8e1e4e824a050695f6a604670f0 /pkg/app | |
parent | 1901901d243f4a4f9c90ce10b61aecc36b83374b (diff) | |
parent | a1c6adab59e742adc6d4207fecd41c7fd18ceeca (diff) |
Merge branch 'feature/anonymous-reporting'
Diffstat (limited to 'pkg/app')
-rw-r--r-- | pkg/app/app.go | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/pkg/app/app.go b/pkg/app/app.go index f8cc01b6c..0b163f553 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "os" + "github.com/heroku/rollrus" "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui" @@ -18,7 +19,7 @@ type App struct { closers []io.Closer Config config.AppConfigurer - Log *logrus.Logger + Log *logrus.Entry OSCommand *commands.OSCommand GitCommand *commands.GitCommand Gui *gui.Gui @@ -26,12 +27,19 @@ type App struct { Updater *updates.Updater // may only need this on the Gui } -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) @@ -40,6 +48,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{ |