aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'widgets')
-rw-r--r--widgets/account-wizard.go3
-rw-r--r--widgets/account.go31
-rw-r--r--widgets/aerc.go23
-rw-r--r--widgets/compose.go3
-rw-r--r--widgets/dirlist.go9
-rw-r--r--widgets/msglist.go5
-rw-r--r--widgets/msgviewer.go5
7 files changed, 29 insertions, 50 deletions
diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go
index b352af67..ab691395 100644
--- a/widgets/account-wizard.go
+++ b/widgets/account-wizard.go
@@ -534,8 +534,7 @@ func (wizard *AccountWizard) finish(tutorial bool) {
}
wizard.conf.Accounts = append(wizard.conf.Accounts, account)
- view, err := NewAccountView(wizard.aerc, wizard.conf, &account,
- wizard.aerc.logger, wizard.aerc, nil)
+ view, err := NewAccountView(wizard.aerc, wizard.conf, &account, wizard.aerc, nil)
if err != nil {
wizard.aerc.NewTab(errorScreen(err.Error(), wizard.conf.Ui),
account.Name)
diff --git a/widgets/account.go b/widgets/account.go
index c76b6fc8..93a277db 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -3,7 +3,6 @@ package widgets
import (
"errors"
"fmt"
- "log"
"time"
"github.com/gdamore/tcell/v2"
@@ -29,7 +28,6 @@ type AccountView struct {
labels []string
grid *ui.Grid
host TabHost
- logger *log.Logger
msglist *MessageList
worker *types.Worker
state *statusline.State
@@ -45,7 +43,7 @@ func (acct *AccountView) UiConfig() *config.UIConfig {
}
func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountConfig,
- logger *log.Logger, host TabHost, deferLoop chan struct{},
+ host TabHost, deferLoop chan struct{},
) (*AccountView, error) {
acctUiConf := conf.GetUiConfig(map[config.ContextType]string{
config.UI_CONTEXT_ACCOUNT: acct.Name,
@@ -56,7 +54,6 @@ func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountCon
aerc: aerc,
conf: conf,
host: host,
- logger: logger,
state: statusline.NewState(acct.Name, len(conf.Accounts) > 1, conf.Statusline),
uiConf: acctUiConf,
}
@@ -70,20 +67,20 @@ func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountCon
{Strategy: ui.SIZE_WEIGHT, Size: ui.Const(1)},
})
- worker, err := worker.NewWorker(acct.Source, logger)
+ worker, err := worker.NewWorker(acct.Source)
if err != nil {
host.SetError(fmt.Sprintf("%s: %s", acct.Name, err))
- logger.Printf("%s: %s\n", acct.Name, err)
+ logging.Errorf("%s: %v", acct.Name, err)
return view, err
}
view.worker = worker
- view.dirlist = NewDirectoryList(conf, acct, logger, worker)
+ view.dirlist = NewDirectoryList(conf, acct, worker)
if acctUiConf.SidebarWidth > 0 {
view.grid.AddChild(ui.NewBordered(view.dirlist, ui.BORDER_RIGHT, acctUiConf))
}
- view.msglist = NewMessageList(conf, logger, aerc)
+ view.msglist = NewMessageList(conf, aerc)
view.grid.AddChild(view.msglist).At(0, 1)
go func() {
@@ -134,7 +131,7 @@ func (acct *AccountView) UpdateStatus() {
}
func (acct *AccountView) PushStatus(status string, expiry time.Duration) {
- acct.aerc.PushStatus(fmt.Sprintf("%s: %v", acct.acct.Name, status), expiry)
+ acct.aerc.PushStatus(fmt.Sprintf("%s: %s", acct.acct.Name, status), expiry)
}
func (acct *AccountView) PushError(err error) {
@@ -149,10 +146,6 @@ func (acct *AccountView) Worker() *types.Worker {
return acct.worker
}
-func (acct *AccountView) Logger() *log.Logger {
- return acct.logger
-}
-
func (acct *AccountView) Name() string {
return acct.acct.Name
}
@@ -243,7 +236,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
switch msg.InResponseTo().(type) {
case *types.Connect, *types.Reconnect:
acct.SetStatus(statusline.ConnectionActivity("Listing mailboxes..."))
- acct.logger.Println("Listing mailboxes...")
+ logging.Debugf("Listing mailboxes...")
acct.dirlist.UpdateList(func(dirs []string) {
var dir string
for _, _dir := range dirs {
@@ -259,14 +252,14 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
acct.dirlist.Select(dir)
}
acct.msglist.SetInitDone()
- acct.logger.Println("Connected.")
+ logging.Infof("%s connected.", acct.acct.Name)
acct.SetStatus(statusline.SetConnected(true))
acct.newConn = true
})
case *types.Disconnect:
acct.dirlist.ClearList()
acct.msglist.SetStore(nil)
- acct.logger.Println("Disconnected.")
+ logging.Infof("%s disconnected.", acct.acct.Name)
acct.SetStatus(statusline.SetConnected(false))
case *types.OpenDirectory:
if store, ok := acct.dirlist.SelectedMsgStore(); ok {
@@ -371,13 +364,13 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
case *types.LabelList:
acct.labels = msg.Labels
case *types.ConnError:
- acct.logger.Printf("connection error: [%s] %v", acct.acct.Name, msg.Error)
+ logging.Errorf("%s connection error: %v", acct.acct.Name, msg.Error)
acct.SetStatus(statusline.SetConnected(false))
acct.PushError(msg.Error)
acct.msglist.SetStore(nil)
acct.worker.PostAction(&types.Reconnect{}, nil)
case *types.Error:
- acct.logger.Printf("%v", msg.Error)
+ logging.Errorf("%s unexpected error: %v", acct.acct.Name, msg.Error)
acct.PushError(msg.Error)
}
acct.UpdateStatus()
@@ -401,7 +394,7 @@ func (acct *AccountView) CheckMail() {
dirs := acct.dirlist.List()
dirs = acct.dirlist.FilterDirs(dirs, acct.AccountConfig().CheckMailInclude, false)
dirs = acct.dirlist.FilterDirs(dirs, exclude, true)
- acct.logger.Printf("Checking for new mail on account %s", acct.Name())
+ logging.Infof("Checking for new mail on account %s", acct.Name())
acct.SetStatus(statusline.ConnectionActivity("Checking for new mail..."))
msg := &types.CheckMail{
Directories: dirs,
diff --git a/widgets/aerc.go b/widgets/aerc.go
index c56c4df4..68144aa0 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
- "log"
"net/url"
"strings"
"time"
@@ -18,6 +17,7 @@ import (
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/lib/crypto"
"git.sr.ht/~rjarry/aerc/lib/ui"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
)
@@ -29,7 +29,6 @@ type Aerc struct {
conf *config.AercConfig
focused ui.Interactive
grid *ui.Grid
- logger *log.Logger
simulating int
statusbar *ui.Stack
statusline *StatusLine
@@ -49,7 +48,7 @@ type Choice struct {
Command []string
}
-func NewAerc(conf *config.AercConfig, logger *log.Logger,
+func NewAerc(conf *config.AercConfig,
crypto crypto.Provider, cmd func(cmd []string) error,
complete func(cmd string) []string, cmdHistory lib.History,
deferLoop chan struct{}) *Aerc {
@@ -77,7 +76,6 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger,
cmdHistory: cmdHistory,
complete: complete,
grid: grid,
- logger: logger,
statusbar: statusbar,
statusline: statusline,
prompts: ui.NewStack(conf.Ui),
@@ -89,7 +87,7 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger,
conf.Triggers.ExecuteCommand = cmd
for i, acct := range conf.Accounts {
- view, err := NewAccountView(aerc, conf, &conf.Accounts[i], logger, aerc, deferLoop)
+ view, err := NewAccountView(aerc, conf, &conf.Accounts[i], aerc, deferLoop)
if err != nil {
tabs.Add(errorScreen(err.Error(), conf.Ui), acct.Name, nil)
} else {
@@ -136,11 +134,11 @@ func (aerc *Aerc) OnBeep(f func() error) {
func (aerc *Aerc) Beep() {
if aerc.beep == nil {
- aerc.logger.Printf("should beep, but no beeper")
+ logging.Warnf("should beep, but no beeper")
return
}
if err := aerc.beep(); err != nil {
- aerc.logger.Printf("tried to beep, but could not: %v", err)
+ logging.Errorf("tried to beep, but could not: %v", err)
}
}
@@ -311,10 +309,6 @@ func (aerc *Aerc) Config() *config.AercConfig {
return aerc.conf
}
-func (aerc *Aerc) Logger() *log.Logger {
- return aerc.logger
-}
-
func (aerc *Aerc) SelectedAccount() *AccountView {
return aerc.account(aerc.SelectedTabContent())
}
@@ -616,7 +610,7 @@ func (aerc *Aerc) Mbox(source string) error {
acctConf = *selectedAcct.acct
info := fmt.Sprintf("Loading outgoing mbox mail settings from account [%s]", selectedAcct.Name())
aerc.PushStatus(info, 10*time.Second)
- aerc.Logger().Println(info)
+ logging.Infof(info)
} else {
acctConf.From = "<user@localhost>"
}
@@ -627,7 +621,7 @@ func (aerc *Aerc) Mbox(source string) error {
acctConf.Postpone = "Drafts"
acctConf.CopyTo = "Sent"
- mboxView, err := NewAccountView(aerc, aerc.conf, &acctConf, aerc.logger, aerc, nil)
+ mboxView, err := NewAccountView(aerc, aerc.conf, &acctConf, aerc, nil)
if err != nil {
aerc.NewTab(errorScreen(err.Error(), aerc.conf.Ui), acctConf.Name)
} else {
@@ -648,8 +642,7 @@ func (aerc *Aerc) CloseBackends() error {
err := c.Close()
if err != nil {
returnErr = err
- aerc.logger.Printf("Closing backend failed for %v: %v\n",
- acct.Name(), err)
+ logging.Errorf("Closing backend failed for %s: %v", acct.Name(), err)
}
}
return returnErr
diff --git a/widgets/compose.go b/widgets/compose.go
index 87331bd1..a4ed27ce 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -23,6 +23,7 @@ import (
"git.sr.ht/~rjarry/aerc/lib/format"
"git.sr.ht/~rjarry/aerc/lib/templates"
"git.sr.ht/~rjarry/aerc/lib/ui"
+ "git.sr.ht/~rjarry/aerc/logging"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
)
@@ -89,7 +90,7 @@ func NewComposer(aerc *Aerc, acct *AccountView, conf *config.AercConfig,
cmpl := completer.New(cmd, func(err error) {
aerc.PushError(
fmt.Sprintf("could not complete header: %v", err))
- worker.Logger.Printf("could not complete header: %v", err)
+ logging.Errorf("could not complete header: %v", err)
})
email, err := ioutil.TempFile("", "aerc-compose-*.eml")
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index 5c3416c7..2047c304 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -3,7 +3,6 @@ package widgets
import (
"context"
"fmt"
- "log"
"math"
"os"
"regexp"
@@ -55,7 +54,6 @@ type DirectoryList struct {
acctConf *config.AccountConfig
store *lib.DirStore
dirs []string
- logger *log.Logger
selecting string
selected string
spinner *Spinner
@@ -67,7 +65,7 @@ type DirectoryList struct {
}
func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig,
- logger *log.Logger, worker *types.Worker,
+ worker *types.Worker,
) DirectoryLister {
ctx, cancel := context.WithCancel(context.Background())
@@ -76,7 +74,6 @@ func NewDirectoryList(conf *config.AercConfig, acctConf *config.AccountConfig,
dirlist := &DirectoryList{
aercConf: conf,
acctConf: acctConf,
- logger: logger,
store: lib.NewDirStore(),
worker: worker,
skipSelect: ctx,
@@ -202,7 +199,7 @@ func (dirlist *DirectoryList) Select(name string) {
})
dirlist.Invalidate()
case <-ctx.Done():
- dirlist.logger.Println("dirlist: skip", name)
+ logging.Debugf("dirlist: skip %s", name)
return
}
}(ctx)
@@ -531,7 +528,7 @@ func (dirlist *DirectoryList) getSortCriteria() []*types.SortCriterion {
}
criteria, err := libsort.GetSortCriteria(dirlist.UiConfig().Sort)
if err != nil {
- dirlist.logger.Printf("getSortCriteria failed: %v", err)
+ logging.Errorf("getSortCriteria failed: %v", err)
return nil
}
return criteria
diff --git a/widgets/msglist.go b/widgets/msglist.go
index e9603cae..a190c184 100644
--- a/widgets/msglist.go
+++ b/widgets/msglist.go
@@ -2,7 +2,6 @@ package widgets
import (
"fmt"
- "log"
"math"
"strings"
@@ -22,7 +21,6 @@ type MessageList struct {
ui.Invalidatable
Scrollable
conf *config.AercConfig
- logger *log.Logger
height int
nmsgs int
spinner *Spinner
@@ -31,10 +29,9 @@ type MessageList struct {
aerc *Aerc
}
-func NewMessageList(conf *config.AercConfig, logger *log.Logger, aerc *Aerc) *MessageList {
+func NewMessageList(conf *config.AercConfig, aerc *Aerc) *MessageList {
ml := &MessageList{
conf: conf,
- logger: logger,
spinner: NewSpinner(&conf.Ui),
isInitalizing: true,
aerc: aerc,
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index 59384d4b..eec786c5 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -229,7 +229,7 @@ func createSwitcher(acct *AccountView, switcher *PartSwitcher,
return err
}
selectedPriority := -1
- fmt.Printf("Selecting best message from %v\n", conf.Viewer.Alternatives)
+ logging.Infof("Selecting best message from %v", conf.Viewer.Alternatives)
for i, pv := range switcher.parts {
pv.OnInvalidate(func(_ ui.Drawable) {
switcher.Invalidate()
@@ -312,8 +312,7 @@ func (mv *MessageViewer) ToggleHeaders() {
mv.conf.Viewer.ShowHeaders = !mv.conf.Viewer.ShowHeaders
err := createSwitcher(mv.acct, switcher, mv.conf, mv.msg)
if err != nil {
- mv.acct.Logger().Printf(
- "warning: error during create switcher - %v", err)
+ logging.Errorf("cannot create switcher: %v", err)
}
switcher.Invalidate()
}