From 70f46757449c8f24b818f4dfc5dcb87da7e327d6 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Wed, 23 Nov 2022 10:43:44 +0100 Subject: logging: homogenize levels The main goal is to ensure that by default, the log file (if configured) does not grow out of proportions. Most of the logging messages in aerc are actually for debugging and/or trace purposes. Define clear rules for logging levels. Enforce these rules everywhere. After this patch, here is what the log file looks like after starting up with a single account: INFO 2022/11/24 20:26:16.147164 aerc.go:176: Starting up version 0.13.0-100-g683981479c60 (go1.18.7 amd64 linux) INFO 2022/11/24 20:26:17.546448 account.go:254: [work] connected. Signed-off-by: Robin Jarry Tested-by: Bence Ferdinandy Acked-by: Tim Culverhouse --- worker/maildir/worker.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'worker/maildir/worker.go') diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go index 2cf7897a..2a8a49bd 100644 --- a/worker/maildir/worker.go +++ b/worker/maildir/worker.go @@ -200,7 +200,7 @@ func (w *Worker) getDirectoryInfo(name string) *models.DirectoryInfo { keyFlags[key] = flags } } else { - logging.Infof("disabled flags cache: %q: %v", dir, err) + logging.Tracef("disabled flags cache: %q: %v", dir, err) } uids, err := w.c.UIDs(dir) @@ -221,7 +221,8 @@ func (w *Worker) getDirectoryInfo(name string) *models.DirectoryInfo { ok := false flags, ok = keyFlags[message.key] if !ok { - logging.Debugf("message (key=%q uid=%d) not found in map cache", message.key, message.uid) + logging.Tracef("message (key=%q uid=%d) not found in map cache", + message.key, message.uid) flags, err = message.Flags() if err != nil { logging.Errorf("could not get flags: %v", err) @@ -320,7 +321,7 @@ func (w *Worker) handleConfigure(msg *types.Configure) error { return err } w.c = c - logging.Infof("configured base maildir: %s", dir) + logging.Debugf("configured base maildir: %s", dir) return nil } @@ -357,7 +358,7 @@ func (w *Worker) handleListDirectories(msg *types.ListDirectories) error { } func (w *Worker) handleOpenDirectory(msg *types.OpenDirectory) error { - logging.Infof("opening %s", msg.Directory) + logging.Debugf("opening %s", msg.Directory) // open the directory dir, err := w.c.OpenDirectory(msg.Directory) @@ -767,13 +768,13 @@ func (w *Worker) handleAppendMessage(msg *types.AppendMessage) error { dest := w.c.Store.Dir(msg.Destination) _, writer, err := dest.Create(lib.ToMaildirFlags(msg.Flags)) if err != nil { - logging.Errorf("could not create message at %s: %v", msg.Destination, err) - return err + return fmt.Errorf("could not create message at %s: %w", + msg.Destination, err) } defer writer.Close() if _, err := io.Copy(writer, msg.Reader); err != nil { - logging.Errorf("could not write message to destination: %v", err) - return err + return fmt.Errorf( + "could not write message to destination: %w", err) } w.worker.PostMessage(&types.Done{ Message: types.RespondTo(msg), @@ -785,12 +786,12 @@ func (w *Worker) handleAppendMessage(msg *types.AppendMessage) error { } func (w *Worker) handleSearchDirectory(msg *types.SearchDirectory) error { - logging.Infof("Searching directory %v with args: %v", *w.selected, msg.Argv) + logging.Debugf("Searching directory %v with args: %v", *w.selected, msg.Argv) criteria, err := parseSearch(msg.Argv) if err != nil { return err } - logging.Infof("Searching with parsed criteria: %#v", criteria) + logging.Tracef("Searching with parsed criteria: %#v", criteria) uids, err := w.search(criteria) if err != nil { return err -- cgit