diff --git a/filestorage.go b/filestorage.go index d3df9cf7..78ba2393 100644 --- a/filestorage.go +++ b/filestorage.go @@ -21,7 +21,6 @@ import ( "fmt" "io" "io/fs" - "log" "os" "path" "path/filepath" @@ -213,7 +212,7 @@ func (s *FileStorage) Lock(ctx context.Context, name string) error { // the previous acquirer either crashed or had some sort of failure that // caused them to be unable to fully acquire or retain the lock, therefore // we should treat it as if the lockfile did not exist - log.Printf("[INFO][%s] %s: Empty lockfile (%v) - likely previous process crashed or storage medium failure; treating as stale", s, filename, err2) + defaultLogger.Sugar().Infof("[%s] %s: Empty lockfile (%v) - likely previous process crashed or storage medium failure; treating as stale", s, filename, err2) } } else if err2 != nil { return fmt.Errorf("decoding lockfile contents: %w", err2) @@ -235,8 +234,7 @@ func (s *FileStorage) Lock(ctx context.Context, name string) error { // either have potential to cause infinite loops, as in caddyserver/caddy#4448, // or must give up on perfect mutual exclusivity; however, these cases are rare, // so we prefer the simpler solution that avoids infinite loops) - log.Printf("[INFO][%s] Lock for '%s' is stale (created: %s, last update: %s); removing then retrying: %s", - s, name, meta.Created, meta.Updated, filename) + defaultLogger.Sugar().Infof("[%s] Lock for '%s' is stale (created: %s, last update: %s); removing then retrying: %s", s, name, meta.Created, meta.Updated, filename) if err = os.Remove(filename); err != nil { // hopefully we can replace the lock file quickly! if !errors.Is(err, fs.ErrNotExist) { return fmt.Errorf("unable to delete stale lockfile; deadlocked: %w", err) @@ -311,7 +309,7 @@ func keepLockfileFresh(filename string) { if err := recover(); err != nil { buf := make([]byte, stackTraceBufferSize) buf = buf[:runtime.Stack(buf, false)] - log.Printf("panic: active locking: %v\n%s", err, buf) + defaultLogger.Sugar().Errorf("active locking: %v\n%s", err, buf) } }() @@ -319,7 +317,7 @@ func keepLockfileFresh(filename string) { time.Sleep(lockFreshnessInterval) done, err := updateLockfileFreshness(filename) if err != nil { - log.Printf("[ERROR] Keeping lock file fresh: %v - terminating lock maintenance (lockfile: %s)", err, filename) + defaultLogger.Sugar().Errorf("Keeping lock file fresh: %v - terminating lock maintenance (lockfile: %s)", err, filename) return } if done {