50af1b9613
This should be the final code update before we start testing things. I think all the code is now in place to have the program function, barring any bugs in my code. So, with that said, here's the changelog: global changes: ``` - implement logger.go across the whole program ``` changes to main.go: ``` - add an import for strings - implement the roughed in handling functions ``` changes to logger.go: ``` - create this little helper package to just handle all our logging nice and gracefully ``` changes to all_updater.go: ``` - basically completely redone. Accomplishes the same thing, just in a different, more efficient way. ``` changes to aur.go: ``` - add a function to clear the AllPac build cache for aur ``` changes to install.go: ``` - removed a duplicate function, set install.go to call the right one ``` changes to pacman.go: ``` - removed GetVersionFromPacman function (it shouldn't be here, it should be in search.go) ``` changes to search.go: ``` - add functions for getting info from, and parsing output from Snap, Pacman, Flatpak, and aur ```
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package logger
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"fmt"
|
|
)
|
|
|
|
var Logger *log.Logger
|
|
|
|
func Init(logFilePath string) error {
|
|
if err := os.MkdirAll(filepath.Dir(logFilePath), 0755); err != nil {
|
|
return err
|
|
}
|
|
|
|
logFile, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
Logger = log.New(logFile, "AllPac: ", log.Ldate|log.Ltime|log.Lshortfile)
|
|
Logger.SetOutput(io.MultiWriter(os.Stderr, logFile))
|
|
|
|
return nil
|
|
}
|
|
|
|
func Info(v ...interface{}) {
|
|
Logger.Println("INFO: " + fmt.Sprint(v...))
|
|
}
|
|
|
|
func Infof(format string, v ...interface{}) {
|
|
Logger.Printf("INFO: "+format, v...)
|
|
}
|
|
|
|
func Warn(v ...interface{}) {
|
|
Logger.Println("WARN: " + fmt.Sprint(v...))
|
|
}
|
|
|
|
func Warnf(format string, v ...interface{}) {
|
|
Logger.Printf("WARN: "+format, v...)
|
|
}
|
|
|
|
func Error(v ...interface{}) {
|
|
Logger.Println("ERROR: " + fmt.Sprint(v...))
|
|
}
|
|
|
|
func Errorf(format string, v ...interface{}) {
|
|
Logger.Printf("ERROR: "+format, v...)
|
|
}
|
|
|
|
func Debug(v ...interface{}) {
|
|
Logger.Println("DEBUG: " + fmt.Sprint(v...))
|
|
}
|
|
|
|
func Debugf(format string, v ...interface{}) {
|
|
Logger.Printf("DEBUG: "+format, v...)
|
|
}
|