From 0ab3d43e76288a7bc7f1759ae466dfefc1b004f3 Mon Sep 17 00:00:00 2001 From: Christian Zangl Date: Mon, 30 Dec 2024 19:48:06 +0100 Subject: [PATCH] logging --- cmd/chkbit/main.go | 5 +++++ context.go | 9 ++++----- status.go | 23 +++++++++++++---------- store.go | 3 ++- worker.go | 2 +- 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/cmd/chkbit/main.go b/cmd/chkbit/main.go index 259821f..35133b7 100644 --- a/cmd/chkbit/main.go +++ b/cmd/chkbit/main.go @@ -128,6 +128,11 @@ func (m *Main) logStatus(stat chkbit.Status, message string) bool { } if m.verbose || !stat.IsVerbose() { + + if m.progress == Quiet && stat == chkbit.STATUS_INFO { + return false + } + col := "" if stat.IsErrorOrWarning() { col = termAlertFG diff --git a/context.go b/context.go index a57416f..5cd824f 100644 --- a/context.go +++ b/context.go @@ -87,16 +87,13 @@ func (context *Context) log(stat Status, message string) { } case STATUS_MISSING: context.NumDel++ - //case STATUS_PANIC: - //case STATUS_ERR_IDX: - //case STATUS_IGNORE: } context.LogQueue <- &LogEvent{stat, message} } func (context *Context) logErr(path string, err error) { - context.LogQueue <- &LogEvent{STATUS_PANIC, path + ": " + err.Error()} + context.log(STATUS_PANIC, path+": "+err.Error()) } func (context *Context) perfMonFiles(numFiles int64) { @@ -152,8 +149,10 @@ func (context *Context) Process(pathList []string) { }() wg.Wait() - if err := context.store.Finish(); err != nil { + if updated, err := context.store.Finish(); err != nil { context.logErr("index", err) + } else if updated { + context.log(STATUS_INFO, "The index db was updated") } context.LogQueue <- nil } diff --git a/status.go b/status.go index 49d5cf3..95c5f30 100644 --- a/status.go +++ b/status.go @@ -3,16 +3,19 @@ package chkbit type Status string const ( - STATUS_PANIC Status = "EXC" - STATUS_ERR_IDX Status = "EIX" - STATUS_ERR_DMG Status = "DMG" - STATUS_UPDATE_INDEX Status = "iup" - STATUS_UP_WARN_OLD Status = "old" - STATUS_UPDATE Status = "upd" - STATUS_NEW Status = "new" - STATUS_OK Status = "ok " - STATUS_IGNORE Status = "ign" - STATUS_MISSING Status = "del" + STATUS_PANIC Status = "EXC" + STATUS_ERR_IDX Status = "ERX" + STATUS_ERR_DMG Status = "DMG" + STATUS_UP_WARN_OLD Status = "old" + STATUS_UPDATE Status = "upd" + STATUS_NEW Status = "new" + STATUS_OK Status = "ok " + STATUS_IGNORE Status = "ign" + STATUS_MISSING Status = "del" + STATUS_INFO Status = "msg" + + // internal + STATUS_UPDATE_INDEX Status = "xup" ) func (s Status) String() string { diff --git a/store.go b/store.go index c73d1e3..66a3315 100644 --- a/store.go +++ b/store.go @@ -93,7 +93,7 @@ func (s *store) Open(readOnly bool, numWorkers int) error { return err } -func (s *store) Finish() (err error) { +func (s *store) Finish() (updated bool, err error) { if !s.useDb { return @@ -141,6 +141,7 @@ func (s *store) Finish() (err error) { if s.cacheFileW != "" { os.Remove(s.cacheFileW) } + updated = true } return } diff --git a/worker.go b/worker.go index e8921ff..83760ab 100644 --- a/worker.go +++ b/worker.go @@ -17,7 +17,7 @@ func (context *Context) runWorker(id int) { index := newIndex(context, item.path, item.filesToIndex, item.dirList, !context.UpdateIndex) err := index.load() if err != nil { - context.log(STATUS_PANIC, index.getIndexFilepath()+": "+err.Error()) + context.logErr(index.getIndexFilepath(), err) } if context.ShowIgnoredOnly {