From 913a974eca2522ba7c6d27066481bb2c6635db53 Mon Sep 17 00:00:00 2001 From: Bernhard Guillon Date: Mon, 6 Jul 2026 22:16:37 +0200 Subject: Add log level system and sync logging - log.go: log level system (DEBUG, INFO, WARN, ERROR, NONE) - CLI: -log-level flag (default info), -verbose as shorthand for debug - Watcher: logs sync/remove actions at INFO level - Watcher: logs events at DEBUG level - Errors: structured error messages (DISK FULL, PERMISSION DENIED, etc.) - Updated README with -log-level flag --- sync.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'sync.go') diff --git a/sync.go b/sync.go index 2cead22..806b7a0 100644 --- a/sync.go +++ b/sync.go @@ -3,7 +3,6 @@ package main import ( "fmt" "io" - "log" "os" "path/filepath" "time" @@ -32,12 +31,12 @@ func initialSync(hostDir, dataDir string, stack *GitignoreStack, dryRun bool) (* stats := &syncStats{} start := time.Now() - log.Printf("initial sync: scanning %s ...", hostDir) + logInfo("initial sync: scanning %s ...", hostDir) err := filepath.Walk(hostDir, func(path string, info os.FileInfo, err error) error { if err != nil { stats.errors++ - logError("walk", path, err) + logErrorf("walk %s: %v", path, err) return nil } @@ -86,7 +85,7 @@ func initialSync(hostDir, dataDir string, stack *GitignoreStack, dryRun bool) (* linkTarget, err = os.Readlink(path) if err != nil { stats.errors++ - logError("readlink", relPath, err) + logErrorf("readlink %s: %v", relPath, err) return nil } } @@ -106,35 +105,35 @@ func initialSync(hostDir, dataDir string, stack *GitignoreStack, dryRun bool) (* if info.IsDir() { if err := os.MkdirAll(destPath, info.Mode()); err != nil { stats.errors++ - logError("mkdir", relPath, err) + logErrorf("mkdir %s: %v", relPath, err) } return nil } if err := os.MkdirAll(filepath.Dir(destPath), 0755); err != nil { stats.errors++ - logError("mkdir", filepath.Dir(relPath), err) + logErrorf("mkdir %s: %v", filepath.Dir(relPath), err) return nil } if linkTarget != "" { if err := os.Symlink(linkTarget, destPath); err != nil { stats.errors++ - logError("symlink", relPath, err) + logErrorf("symlink %s: %v", relPath, err) } return nil } if err := copyFileWithRetry(path, destPath, info.Mode()); err != nil { stats.errors++ - logError("copy", relPath, err) + logErrorf("copy %s: %v", relPath, err) } return nil }) elapsed := time.Since(start) fmt.Fprintf(os.Stderr, "\r") - log.Printf("initial sync: done in %s — %d files, %d dirs, %d skipped, %d errors", + logInfo("initial sync: done in %s — %d files, %d dirs, %d skipped, %d errors", elapsed.Round(time.Millisecond), stats.files, stats.dirs, stats.skipped, stats.errors) return manifest, err -- cgit v1.2.3