Skip to content

Commit

Permalink
logging
Browse files Browse the repository at this point in the history
  • Loading branch information
laktak committed Dec 30, 2024
1 parent 907b5f2 commit 0ab3d43
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
5 changes: 5 additions & 0 deletions cmd/chkbit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
23 changes: 13 additions & 10 deletions status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -141,6 +141,7 @@ func (s *store) Finish() (err error) {
if s.cacheFileW != "" {
os.Remove(s.cacheFileW)
}
updated = true
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0ab3d43

Please sign in to comment.