1

log: move log file to temp directory with fallback

This commit is contained in:
2026-06-19 21:39:45 +03:00
parent c3cb8ae847
commit d0cafe1332
2 changed files with 8 additions and 4 deletions
+7 -3
View File
@@ -161,7 +161,7 @@ func main() {
mem := flag.Uint64("mem", 512*1024*1024, "memory threshold in bytes")
interval := flag.Duration("interval", time.Minute, "scan interval")
dryRun := flag.Bool("dry-run", false, "log only, do not change priorities")
doLog := flag.Bool("log", true, "write log file next to executable")
doLog := flag.Bool("log", true, "write log file to temp directory")
flag.Parse()
if *interval < 10*time.Second {
@@ -170,8 +170,12 @@ func main() {
var logFile *os.File
if *doLog {
exePath, _ := os.Executable()
f, err := os.OpenFile(filepath.Join(filepath.Dir(exePath), "autopriority.log"),
logDir := os.TempDir()
if logDir == "" {
exePath, _ := os.Executable()
logDir = filepath.Dir(exePath)
}
f, err := os.OpenFile(filepath.Join(logDir, "autopriority.log"),
os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err == nil {
logFile = f