refactor: replace log statements with fmt for console output

This commit is contained in:
2025-01-21 20:56:58 -06:00
parent 837960e41b
commit 0d8e8acf3a
3 changed files with 16 additions and 14 deletions

View File

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

View File

@@ -1,10 +1,11 @@
package steamcache package steamcache
import ( import (
"fmt"
"io" "io"
"log"
"net/http" "net/http"
"net/url" "net/url"
"os"
"s1d3sw1ped/SteamCache2/steamcache/avgcachestate" "s1d3sw1ped/SteamCache2/steamcache/avgcachestate"
"s1d3sw1ped/SteamCache2/vfs" "s1d3sw1ped/SteamCache2/vfs"
"s1d3sw1ped/SteamCache2/vfs/cache" "s1d3sw1ped/SteamCache2/vfs/cache"
@@ -79,7 +80,7 @@ func New(address string, memorySize string, memoryMultiplier int, diskSize strin
} }
func (sc *SteamCache) Run() { func (sc *SteamCache) Run() {
log.Printf("SteamCache2 running on %s", sc.address) fmt.Printf("SteamCache2 running on %s", sc.address)
sc.mu.Lock() sc.mu.Lock()
sc.dirty = true sc.dirty = true
@@ -95,7 +96,8 @@ func (sc *SteamCache) Run() {
err := http.ListenAndServe(sc.address, sc) err := http.ListenAndServe(sc.address, sc)
if err != nil { if err != nil {
log.Fatal(err) fmt.Println(err)
os.Exit(1)
} }
} }
@@ -103,8 +105,8 @@ func (sc *SteamCache) LogStats() {
sc.mu.Lock() sc.mu.Lock()
defer sc.mu.Unlock() defer sc.mu.Unlock()
if sc.dirty { if sc.dirty {
log.Printf( fmt.Printf(
"SteamCache2 %s: (%d) %s/%s %s: (%d) %s/%s Hitrate: %f%%", "%s: (%d) %s/%s %s: (%d) %s/%s Hitrate: %f%%",
sc.memory.Name(), len(sc.memory.StatAll()), units.HumanSize(float64(sc.memory.Size())), units.HumanSize(float64(sc.memory.Capacity())), sc.memory.Name(), len(sc.memory.StatAll()), units.HumanSize(float64(sc.memory.Size())), units.HumanSize(float64(sc.memory.Capacity())),
sc.disk.Name(), len(sc.disk.StatAll()), units.HumanSize(float64(sc.disk.Size())), units.HumanSize(float64(sc.disk.Capacity())), sc.disk.Name(), len(sc.disk.StatAll()), units.HumanSize(float64(sc.disk.Size())), units.HumanSize(float64(sc.disk.Capacity())),
sc.hits.Avg()*100, sc.hits.Avg()*100,
@@ -139,7 +141,7 @@ func (sc *SteamCache) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// tstart := time.Now() // tstart := time.Now()
// defer func() { // defer func() {
// log.Printf("%s %s %s took %s", r.Method, r.URL.String(), w.Header().Get("X-LanCache-Status"), time.Since(tstart)) // fmt.Printf("%s %s %s took %s", r.Method, r.URL.String(), w.Header().Get("X-LanCache-Status"), time.Since(tstart))
// }() // }()
sc.mu.Lock() sc.mu.Lock()

View File

@@ -1,7 +1,7 @@
package disk package disk
import ( import (
"log" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"s1d3sw1ped/SteamCache2/vfs" "s1d3sw1ped/SteamCache2/vfs"
@@ -53,14 +53,14 @@ func NewSkipInit(root string, capacity int64) *DiskFS {
} }
func (d *DiskFS) init() { func (d *DiskFS) init() {
// log.Printf("DiskFS(%s, %s) init", d.root, units.HumanSize(float64(d.capacity))) // fmt.Printf("DiskFS(%s, %s) init", d.root, units.HumanSize(float64(d.capacity)))
tstart := time.Now() tstart := time.Now()
d.walk(d.root) d.walk(d.root)
d.sg.Wait() d.sg.Wait()
log.Printf("DiskFS(%s, %s) init took %v", d.root, units.HumanSize(float64(d.capacity)), time.Since(tstart)) fmt.Printf("DiskFS(%s, %s) init took %v", d.root, units.HumanSize(float64(d.capacity)), time.Since(tstart))
} }
func (d *DiskFS) walk(path string) { func (d *DiskFS) walk(path string) {
@@ -86,7 +86,7 @@ func (d *DiskFS) walk(path string) {
d.info[k] = vfs.NewFileInfoFromOS(info, k) d.info[k] = vfs.NewFileInfoFromOS(info, k)
d.mu.Unlock() d.mu.Unlock()
// log.Printf("DiskFS(%s, %s) init: %s", d.root, units.HumanSize(float64(d.capacity)), npath) // fmt.Printf("DiskFS(%s, %s) init: %s", d.root, units.HumanSize(float64(d.capacity)), npath)
return nil return nil
}) })
}() }()