- Rewrite complet en Go : exe unique sans _internal/, sans extraction temp - GUI Windows-native via github.com/lxn/walk (TableView, TextEdit, PushButton) - Meme fonctionnalites : check repos, pull, checkout, auto-update, logs - build.bat : go build -ldflags "-H windowsgui -s -w" -> 9.6 Mo, zero dependance Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
45 lines
963 B
Go
45 lines
963 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
)
|
|
|
|
var logFile *os.File
|
|
|
|
func initLogger() {
|
|
dir := filepath.Join(exeDir(), "log")
|
|
os.MkdirAll(dir, 0755)
|
|
|
|
// Nettoyage logs > 30 jours
|
|
entries, _ := os.ReadDir(dir)
|
|
cutoff := time.Now().AddDate(0, 0, -30)
|
|
for _, e := range entries {
|
|
if !e.IsDir() {
|
|
if info, err := e.Info(); err == nil && info.ModTime().Before(cutoff) {
|
|
os.Remove(filepath.Join(dir, e.Name()))
|
|
}
|
|
}
|
|
}
|
|
|
|
logPath := filepath.Join(dir, time.Now().Format("2006-01-02")+".log")
|
|
f, err := os.OpenFile(logPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
|
if err != nil {
|
|
return
|
|
}
|
|
logFile = f
|
|
}
|
|
|
|
func logMsg(level, msg string) {
|
|
line := fmt.Sprintf("[%s] %-5s %s\n", time.Now().Format("15:04:05"), level, msg)
|
|
if logFile != nil {
|
|
logFile.WriteString(line)
|
|
}
|
|
}
|
|
|
|
func logInfo(msg string) { logMsg("INFO", msg) }
|
|
func logWarn(msg string) { logMsg("WARN", msg) }
|
|
func logError(msg string) { logMsg("ERROR", msg) }
|