Skip to content

Commit

Permalink
More logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Fesaa committed Jul 26, 2024
1 parent 1ffbef1 commit ce2aa5c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func Default() *Logger {

var def Logger

func IsTraceEnabled() bool {
return Default().IsTraceEnabled()
}

func Error(msg string, args ...any) {
Default().log(slog.LevelError, msg, args...)
}
Expand Down Expand Up @@ -81,6 +85,10 @@ func (l *Logger) Fatal(msg string, args ...any) {
panic("fatal log call")
}

func (l *Logger) IsTraceEnabled() bool {
return l._log.Enabled(nil, LevelTrace)
}

func With(args ...any) *Logger {
return Default().With(args...)
}
Expand Down
13 changes: 11 additions & 2 deletions yoitsu/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ func removeAll(path, infoHash string, re ...bool) {
}
return re[0]
}()
log.Trace("removing directory", "dir", path, "infoHash", infoHash, "reTry", reTry)

err := os.RemoveAll(path)
if err != nil {
log.Error("error while deleting directory", "dir", path, "err", err, "infoHash", infoHash)
}

stat, err := os.Stat(path)
log.Trace("os.Stat", "err", func() string {
if err != nil {
return err.Error()
}
return "<nil>"
}())
if !errors.Is(err, os.ErrNotExist) {
log.Error("error while deleting directory. Directory is still present??", "dir", path, "err", err, "infoHash", infoHash)

Expand All @@ -31,8 +38,10 @@ func removeAll(path, infoHash string, re ...bool) {
log.Error("error while deleting directory", "dir", path, "err", err, "infoHash", infoHash)
}

for _, d := range info {
log.Debug("Found file", "name", d.Name(), "dir", d.IsDir(), "type", d.Type())
if log.IsTraceEnabled() {
for _, d := range info {
log.Trace("Found file", "name", d.Name(), "dir", d.IsDir(), "type", d.Type())
}
}
}

Expand Down

0 comments on commit ce2aa5c

Please sign in to comment.