You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.7 KiB
1.7 KiB
Implementation
Log File Location
- Path:
/var/log/declpac.log - Single merged log file (stdout + stderr intermingled in order of arrival)
State-Modifying Functions (need logging)
SyncPackages()-pacman -S --needed <packages>InstallAUR()-git clone+makepkg -si --noconfirmMarkAllAsDeps()-pacman -D --asdepsMarkAsExplicit()-pacman -D --asexplicit <packages>CleanupOrphans()-pacman -Rns
Functions to Skip (read-only)
DryRun()- queries onlygetInstalledCount()- pacman -Qq
Execution Patterns
| Pattern | Functions | How |
|---|---|---|
| Streaming | MarkAllAsDeps, MarkAsExplicit, InstallAUR | io.MultiWriter to tee to both terminal and log |
| Captured | SyncPackages, CleanupOrphans | capture with CombinedOutput(), write to log, write to terminal |
Error Handling
- Write error to log BEFORE returning from function
- Print error to stderr so user sees it
Dependencies
- Add to imports:
io,os,path/filepath
Structure
// pkg/state/state.go
var logFile *os.File
func OpenLog() error {
logPath := filepath.Join("/var/log", "declpac.log")
f, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
}
logFile = f
return nil
}
func GetLogWriter() io.Writer {
return logFile
}
func Close() error {
if logFile == nil {
return nil
}
return logFile.Close()
}
Flow in Sync() or main entrypoint
- Call
OpenLog()at program start, defer close - Each state-modifying function uses
state.GetLogWriter()via MultiWriter
Wire into main.go
- Open log at start of
run() - Pass log writer to pacman package (via exported function or global)