feat: add logging to Docker and iptables operations, fix iptables path
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
- Create /var/log/network-go directory in Dockerfile for log storage - Add comprehensive logging to Docker client creation, network management, and container operations - Add logging to iptables rule management (list, delete, etc.) - Fix iptables executable path resolution in deleteMatchingLinesInContainer to use configured binary path
This commit is contained in:
@@ -3,9 +3,10 @@ package watcher
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"firewall_containers/network-go/logger"
|
||||
)
|
||||
|
||||
// FileWatcher periodically checks a file for changes using MD5 hash
|
||||
@@ -42,7 +43,7 @@ func (fw *FileWatcher) Start() {
|
||||
// Compute initial hash
|
||||
hash, err := fw.hashFile()
|
||||
if err != nil {
|
||||
log.Printf("WATCHER: initial hash computation failed for %s: %v", fw.path, err)
|
||||
logger.Warn("WATCHER: initial hash computation failed for %s: %v", fw.path, err)
|
||||
} else {
|
||||
fw.lastHash = hash
|
||||
}
|
||||
@@ -51,22 +52,22 @@ func (fw *FileWatcher) Start() {
|
||||
ticker := time.NewTicker(fw.period)
|
||||
defer ticker.Stop()
|
||||
|
||||
log.Printf("WATCHER: started watching %s every %s", fw.path, fw.period)
|
||||
logger.Info("WATCHER: started watching %s every %s", fw.path, fw.period)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-fw.stopCh:
|
||||
log.Printf("WATCHER: stopped watching %s", fw.path)
|
||||
logger.Info("WATCHER: stopped watching %s", fw.path)
|
||||
return
|
||||
case <-ticker.C:
|
||||
hash, err := fw.hashFile()
|
||||
if err != nil {
|
||||
log.Printf("WATCHER: failed to hash %s: %v", fw.path, err)
|
||||
logger.Warn("WATCHER: failed to hash %s: %v", fw.path, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if hash != fw.lastHash {
|
||||
log.Printf("WATCHER: detected change in %s", fw.path)
|
||||
logger.Info("WATCHER: detected change in %s", fw.path)
|
||||
fw.lastHash = hash
|
||||
if fw.onChange != nil {
|
||||
fw.onChange()
|
||||
|
||||
Reference in New Issue
Block a user