diff options
author | Robin Jarry <robin@jarry.cc> | 2022-07-19 22:31:51 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-07-23 22:52:15 +0200 |
commit | cd1999555714fb886493d2d04b6c472be55cebef (patch) | |
tree | 1df3bcf5f687752db671d8bc9c7eab8a5c0fde71 /commands/account/export-mbox.go | |
parent | a1f779ccc9b16b22ad6cb2e0bf73c290fd0cc756 (diff) | |
download | aerc-cd1999555714fb886493d2d04b6c472be55cebef.tar.gz |
logging: use level-based logger functions
Do not pass logger objects around anymore. Shuffle some messages to make
them consistent with the new logging API. Avoid using %v when a more
specific verb exists for the argument types.
The loggers are completely disabled (i.e. Sprintf is not even called)
by default. They are only enabled when redirecting stdout to a file.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'commands/account/export-mbox.go')
-rw-r--r-- | commands/account/export-mbox.go | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/commands/account/export-mbox.go b/commands/account/export-mbox.go index 528934eb..3e86fc19 100644 --- a/commands/account/export-mbox.go +++ b/commands/account/export-mbox.go @@ -8,6 +8,7 @@ import ( "sync" "time" + "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/widgets" mboxer "git.sr.ht/~rjarry/aerc/worker/mbox" "git.sr.ht/~rjarry/aerc/worker/types" @@ -54,7 +55,7 @@ func (ExportMbox) Execute(aerc *widgets.Aerc, args []string) error { go func() { file, err := os.Create(filename) if err != nil { - acct.Logger().Println(args[0], err.Error()) + logging.Errorf("failed to create file: %v", err) aerc.PushError(err.Error()) return } @@ -72,28 +73,26 @@ func (ExportMbox) Execute(aerc *widgets.Aerc, args []string) error { for len(uids) > 0 { if retries > 0 { if retries > 10 { - errorMsg := fmt.Sprintln(args[0], "too many retries:", retries, "; stopping export") - acct.Logger().Println(errorMsg) - aerc.PushError(errorMsg) + errorMsg := fmt.Sprintf("too many retries: %d; stopping export", retries) + logging.Errorf(errorMsg) + aerc.PushError(args[0] + " " + errorMsg) break } sleeping := time.Duration(retries * 1e9 * 2) - acct.Logger().Println(args[0], "sleeping for", sleeping, "before retrying; retries:", retries) + logging.Debugf("sleeping for %s before retrying; retries: %d", sleeping, retries) time.Sleep(sleeping) } - acct.Logger().Println(args[0], "fetching", len(uids), "for export") + logging.Debugf("fetching %d for export", len(uids)) acct.Worker().PostAction(&types.FetchFullMessages{ Uids: uids, }, func(msg types.WorkerMessage) { switch msg := msg.(type) { case *types.Done: - acct.Logger().Println(args[0], "done") done <- true case *types.Error: - errMsg := fmt.Sprintln(args[0], "error encountered:", msg.Error.Error()) - acct.Logger().Println(errMsg) - aerc.PushError(errMsg) + logging.Errorf("failed to fetch message: %v", msg.Error) + aerc.PushError(args[0] + " error encountered: " + msg.Error.Error()) done <- false case *types.FullMessage: mu.Lock() @@ -115,7 +114,7 @@ func (ExportMbox) Execute(aerc *widgets.Aerc, args []string) error { } statusInfo := fmt.Sprintf("Exported %d of %d messages to %s.", ctr, len(store.Uids()), filename) aerc.PushStatus(statusInfo, 10*time.Second) - acct.Logger().Println(args[0], statusInfo) + logging.Infof(statusInfo) }() return nil |