Refactor fetch and pacman packages into subpackages
Split fetch into alpm and aur subpackages for better organization. Rename state to log. Split pacman into read and sync subpackages. Remove validation in favor of read.DBFreshness.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
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
|
||||
writeTimestamp()
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetLogWriter() io.Writer {
|
||||
return logFile
|
||||
}
|
||||
|
||||
func Write(msg []byte) {
|
||||
logFile.Write(msg)
|
||||
}
|
||||
|
||||
func Close() error {
|
||||
if logFile == nil {
|
||||
return nil
|
||||
}
|
||||
return logFile.Close()
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
|
||||
func writeTimestamp() {
|
||||
ts := time.Now().Format("2006-01-02 15:04:05")
|
||||
header := fmt.Sprintf("\n--- %s ---\n", ts)
|
||||
logFile.Write([]byte(header))
|
||||
}
|
||||
Reference in New Issue
Block a user