Add logging to file

This commit is contained in:
2025-03-26 21:12:44 +01:00
parent 6313fba69e
commit e03eec0488
3 changed files with 18 additions and 9 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
.stfolder
*.log

View File

@@ -23,10 +23,14 @@ var Warning *log.Logger
func init() {
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
Error = log.New(io.MultiWriter(os.Stderr, os.Stdout),
logFile, err := os.OpenFile("updater.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening log file: %v", err)
}
Error = log.New(io.MultiWriter(os.Stderr, logFile),
fmt.Sprintf("%sERROR:%s ", "\033[0;101m", "\033[0m"),
log.Lmicroseconds|log.Lshortfile)
Warning = log.New(io.MultiWriter(os.Stdout),
Warning = log.New(io.MultiWriter(os.Stdout, logFile),
fmt.Sprintf("%sWarning:%s ", "\033[0;93m", "\033[0m"),
log.Lmicroseconds|log.Lshortfile)
}
@@ -36,6 +40,7 @@ const remoteUrl = "https://git.site.quack-lab.dev/dave/barotrauma-gamefiles/raw/
func main() {
nodl := flag.Bool("nodl", false, "nodl")
hashfile := flag.String("hashfile", "hashes.txt", "hashfile")
root := flag.String("root", ".", "root")
flag.Parse()
cwd, err := os.Getwd()
@@ -43,10 +48,13 @@ func main() {
Error.Printf("error getting cwd: %v", err)
return
}
log.Printf("cwd: %s", cwd)
log.Printf("root: %s", *root)
root := filepath.Join(cwd, "Content")
*root = filepath.Join(cwd, *root, "Content")
log.Printf("root: %s", *root)
*hashfile = filepath.Join(root, *hashfile)
*hashfile = filepath.Join(*root, *hashfile)
hashes, err := LoadLocalHashes(*hashfile)
if err != nil {
Error.Printf("error loading hashes: %v", err)
@@ -61,7 +69,7 @@ func main() {
}
log.Printf("loaded remote hashes")
files, err := doublestar.Glob(os.DirFS(root), "**/*.xml")
files, err := doublestar.Glob(os.DirFS(*root), "**/*.xml")
if err != nil {
Error.Printf("error globbing files: %v", err)
return
@@ -73,14 +81,14 @@ func main() {
go func(file string) {
defer wg.Done()
file = strings.ReplaceAll(file, "\\", "/")
path := filepath.Join(root, file)
path := filepath.Join(*root, file)
path = strings.ReplaceAll(path, "\\", "/")
hash, err := GetLocalHash(path)
if err != nil {
Error.Printf("error getting hash: %v", err)
return
}
relativepath, err := filepath.Rel(root, path)
relativepath, err := filepath.Rel(*root, path)
if err != nil {
Error.Printf("error getting relative path: %v", err)
return
@@ -125,7 +133,7 @@ func main() {
go func(file string) {
defer wg.Done()
file = strings.ReplaceAll(file, "\\", "/")
path := filepath.Join(root, file)
path := filepath.Join(*root, file)
log.Printf("Downloading %s", file)
if *nodl {
log.Printf("Skipping download for %s", file)

BIN
updater/updater.exe (Stored with Git LFS)

Binary file not shown.