aboutsummaryrefslogtreecommitdiffstats
path: root/worker/imap/cache.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-11-27 11:29:34 +0100
committerRobin Jarry <robin@jarry.cc>2022-12-02 22:10:49 +0100
commit23a05d17ac1d23466ff73efa19576d43d06efe4b (patch)
tree49986587a62bdd89eb06ffa2aadf05f6d45cb3e7 /worker/imap/cache.go
parent70f46757449c8f24b818f4dfc5dcb87da7e327d6 (diff)
downloadaerc-23a05d17ac1d23466ff73efa19576d43d06efe4b.tar.gz
logging: rename package to log
Use the same name than the builtin "log" package. That way, we do not risk logging in the wrong place. Suggested-by: Tim Culverhouse <tim@timculverhouse.com> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'worker/imap/cache.go')
-rw-r--r--worker/imap/cache.go30
1 files changed, 15 insertions, 15 deletions
diff --git a/worker/imap/cache.go b/worker/imap/cache.go
index cf92dfaa..a889f725 100644
--- a/worker/imap/cache.go
+++ b/worker/imap/cache.go
@@ -9,7 +9,7 @@ import (
"path"
"time"
- "git.sr.ht/~rjarry/aerc/logging"
+ "git.sr.ht/~rjarry/aerc/log"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
"github.com/emersion/go-message"
@@ -34,18 +34,18 @@ func (w *IMAPWorker) initCacheDb(acct string) {
cd, err := cacheDir()
if err != nil {
w.cache = nil
- logging.Errorf("unable to find cache directory: %v", err)
+ log.Errorf("unable to find cache directory: %v", err)
return
}
p := path.Join(cd, acct)
db, err := leveldb.OpenFile(p, nil)
if err != nil {
w.cache = nil
- logging.Errorf("failed opening cache db: %v", err)
+ log.Errorf("failed opening cache db: %v", err)
return
}
w.cache = db
- logging.Debugf("cache db opened: %s", p)
+ log.Debugf("cache db opened: %s", p)
if w.config.cacheMaxAge.Hours() > 0 {
go w.cleanCache(p)
}
@@ -54,11 +54,11 @@ func (w *IMAPWorker) initCacheDb(acct string) {
func (w *IMAPWorker) cacheHeader(mi *models.MessageInfo) {
uv := fmt.Sprintf("%d", w.selected.UidValidity)
uid := fmt.Sprintf("%d", mi.Uid)
- logging.Debugf("caching header for message %s.%s", uv, uid)
+ log.Debugf("caching header for message %s.%s", uv, uid)
hdr := bytes.NewBuffer(nil)
err := textproto.WriteHeader(hdr, mi.RFC822Headers.Header.Header)
if err != nil {
- logging.Errorf("cannot write header %s.%s: %v", uv, uid, err)
+ log.Errorf("cannot write header %s.%s: %v", uv, uid, err)
return
}
h := &CachedHeader{
@@ -73,18 +73,18 @@ func (w *IMAPWorker) cacheHeader(mi *models.MessageInfo) {
enc := gob.NewEncoder(data)
err = enc.Encode(h)
if err != nil {
- logging.Errorf("cannot encode message %s.%s: %v", uv, uid, err)
+ log.Errorf("cannot encode message %s.%s: %v", uv, uid, err)
return
}
err = w.cache.Put([]byte("header."+uv+"."+uid), data.Bytes(), nil)
if err != nil {
- logging.Errorf("cannot write header for message %s.%s: %v", uv, uid, err)
+ log.Errorf("cannot write header for message %s.%s: %v", uv, uid, err)
return
}
}
func (w *IMAPWorker) getCachedHeaders(msg *types.FetchMessageHeaders) []uint32 {
- logging.Tracef("Retrieving headers from cache: %v", msg.Uids)
+ log.Tracef("Retrieving headers from cache: %v", msg.Uids)
var need []uint32
uv := fmt.Sprintf("%d", w.selected.UidValidity)
for _, uid := range msg.Uids {
@@ -98,14 +98,14 @@ func (w *IMAPWorker) getCachedHeaders(msg *types.FetchMessageHeaders) []uint32 {
dec := gob.NewDecoder(bytes.NewReader(data))
err = dec.Decode(ch)
if err != nil {
- logging.Errorf("cannot decode cached header %s.%s: %v", uv, u, err)
+ log.Errorf("cannot decode cached header %s.%s: %v", uv, u, err)
need = append(need, uid)
continue
}
hr := bytes.NewReader(ch.Header)
textprotoHeader, err := textproto.ReadHeader(bufio.NewReader(hr))
if err != nil {
- logging.Errorf("cannot read cached header %s.%s: %v", uv, u, err)
+ log.Errorf("cannot read cached header %s.%s: %v", uv, u, err)
need = append(need, uid)
continue
}
@@ -122,7 +122,7 @@ func (w *IMAPWorker) getCachedHeaders(msg *types.FetchMessageHeaders) []uint32 {
if err != nil {
mi.Refs = refs
}
- logging.Tracef("located cached header %s.%s", uv, u)
+ log.Tracef("located cached header %s.%s", uv, u)
w.worker.PostMessage(&types.MessageInfo{
Message: types.RespondTo(msg),
Info: mi,
@@ -154,14 +154,14 @@ func (w *IMAPWorker) cleanCache(path string) {
dec := gob.NewDecoder(bytes.NewReader(data))
err := dec.Decode(ch)
if err != nil {
- logging.Errorf("cannot clean database %d: %v", w.selected.UidValidity, err)
+ log.Errorf("cannot clean database %d: %v", w.selected.UidValidity, err)
continue
}
exp := ch.Created.Add(w.config.cacheMaxAge)
if exp.Before(time.Now()) {
err = w.cache.Delete(iter.Key(), nil)
if err != nil {
- logging.Errorf("cannot clean database %d: %v", w.selected.UidValidity, err)
+ log.Errorf("cannot clean database %d: %v", w.selected.UidValidity, err)
continue
}
removed++
@@ -170,6 +170,6 @@ func (w *IMAPWorker) cleanCache(path string) {
}
iter.Release()
elapsed := time.Since(start)
- logging.Debugf("%s: removed %d/%d expired entries in %s",
+ log.Debugf("%s: removed %d/%d expired entries in %s",
path, removed, scanned, elapsed)
}