feat: integrate zerolog for structured logging and replace fmt with logger

This commit is contained in:
2025-01-21 23:33:14 -06:00
parent 0d8e8acf3a
commit 0ca2a9eeed
6 changed files with 59 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
package steamcache
import (
"fmt"
"s1d3sw1ped/SteamCache2/steamcache/logger"
"s1d3sw1ped/SteamCache2/vfs"
"s1d3sw1ped/SteamCache2/vfs/cachestate"
"time"
@@ -17,7 +17,7 @@ func randomgc(vfss vfs.VFS, stats []*vfs.FileInfo) int64 {
err := vfss.Delete(randfile.Name())
if err != nil {
// If we failed to delete the file, log it and return 0
// fmt.Printf("Failed to delete %s: %v", randfile.Name(), err)
// logger.Logger.Error().Err(err).Msgf("Failed to delete %s", randfile.Name())
return 0
}
@@ -39,7 +39,12 @@ func memorygc(vfss vfs.VFS, size int) {
}
}
fmt.Printf("GC of %s took %v to reclaim %s by deleting %d files", vfss.Name(), time.Since(tstart), units.HumanSize(float64(reclaimed)), deletions)
logger.Logger.Info().
Str("name", vfss.Name()).
Str("duration", time.Since(tstart).String()).
Str("reclaimed", units.HumanSize(float64(reclaimed))).
Int("deletions", deletions).
Msgf("GC")
}
func diskgc(vfss vfs.VFS, size int) {
@@ -57,7 +62,12 @@ func diskgc(vfss vfs.VFS, size int) {
}
}
fmt.Printf("GC of %s took %v to reclaim %s by deleting %d files", vfss.Name(), time.Since(tstart), units.HumanSize(float64(reclaimed)), deletions)
logger.Logger.Info().
Str("name", vfss.Name()).
Str("duration", time.Since(tstart).String()).
Str("reclaimed", units.HumanSize(float64(reclaimed))).
Int("deletions", deletions).
Msgf("GC")
}
func cachehandler(fi *vfs.FileInfo, cs cachestate.CacheState) bool {