about summary refs log tree commit diff stats
path: root/ui
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-01-31 21:18:21 -0500
committerDrew DeVault <sir@cmpwn.com>2018-01-31 21:18:21 -0500
commita21afdaa6bab8f6d05bbe9272700eef571548a59 (patch)
tree82149576ffdb6c13bf1a1ac2f1abb729e79cf3c9 /ui
parent1710c9054898e820700d673e21e7c7a90a3f67b1 (diff)
downloadaerc-a21afdaa6bab8f6d05bbe9272700eef571548a59.tar.gz
Improve logging
Diffstat (limited to 'ui')
-rw-r--r--ui/account.go31
1 files changed, 19 insertions, 12 deletions
diff --git a/ui/account.go b/ui/account.go
index 8353db3..59544d4 100644
--- a/ui/account.go
+++ b/ui/account.go
@@ -1,26 +1,29 @@
 package ui
 
 import (
-	"fmt"
+	"log"
 
 	tb "github.com/nsf/termbox-go"
 
+	"github.com/davecgh/go-spew/spew"
+
 	"git.sr.ht/~sircmpwn/aerc2/config"
 	"git.sr.ht/~sircmpwn/aerc2/worker"
 	"git.sr.ht/~sircmpwn/aerc2/worker/types"
 )
 
 type AccountTab struct {
-	Config *config.AccountConfig
-	Worker worker.Worker
-	Parent *UIState
-
+	Config  *config.AccountConfig
+	Worker  worker.Worker
+	Parent  *UIState
+	logger  *log.Logger
 	counter int
-	log     []string
 }
 
-func NewAccountTab(conf *config.AccountConfig) (*AccountTab, error) {
-	work, err := worker.NewWorker(conf.Source)
+func NewAccountTab(conf *config.AccountConfig,
+	logger *log.Logger) (*AccountTab, error) {
+
+	work, err := worker.NewWorker(conf.Source, logger)
 	if err != nil {
 		return nil, err
 	}
@@ -30,6 +33,7 @@ func NewAccountTab(conf *config.AccountConfig) (*AccountTab, error) {
 	return &AccountTab{
 		Config: conf,
 		Worker: work,
+		logger: logger,
 	}, nil
 }
 
@@ -49,9 +53,6 @@ func (acc *AccountTab) Render(at Geometry) {
 	}
 	TFill(at, cell)
 	TPrintf(&at, cell, "%s %d\n", acc.Name(), acc.counter)
-	for _, str := range acc.log {
-		TPrintf(&at, cell, "%s\n", str)
-	}
 	acc.counter++
 	if acc.counter%10000 == 0 {
 		acc.counter = 0
@@ -64,5 +65,11 @@ func (acc *AccountTab) GetChannel() chan types.WorkerMessage {
 }
 
 func (acc *AccountTab) HandleMessage(msg types.WorkerMessage) {
-	acc.log = append(acc.log, fmt.Sprintf("<- %T", msg))
+	switch msg.InResponseTo().(type) {
+	case types.Configure:
+		// Avoid printing passwords
+		acc.logger.Printf("<- %T\n", msg)
+	default:
+		acc.logger.Printf("<- %s", spew.Sdump(msg))
+	}
 }