aboutsummaryrefslogtreecommitdiffstats
path: root/sync.go
diff options
context:
space:
mode:
authorBernhard Guillon <Bernhard.Guillon@begu.org>2026-07-06 22:16:37 +0200
committerBernhard Guillon <Bernhard.Guillon@begu.org>2026-07-06 22:16:37 +0200
commit913a974eca2522ba7c6d27066481bb2c6635db53 (patch)
treef0cfc1ee173a762662b586fca5db9db422592093 /sync.go
parent5f2ba9c3d37a1c8658aea411188a6763e982b1ab (diff)
downloadsourcewatch-913a974eca2522ba7c6d27066481bb2c6635db53.tar.gz
sourcewatch-913a974eca2522ba7c6d27066481bb2c6635db53.zip
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
Diffstat (limited to 'sync.go')
-rw-r--r--sync.go17
1 files changed, 8 insertions, 9 deletions
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