Add optional "log_file" configuration option.

This commit is contained in:
Kalzu Rekku
2026-07-18 00:14:49 +03:00
parent 216074b1b1
commit 2de4d378ca
3 changed files with 19 additions and 12 deletions
+13 -9
View File
@@ -40,7 +40,7 @@ func main() {
}
if isDaemon {
startDaemon()
startDaemon(cfg.LogFile)
return
}
runEngine(cfg)
@@ -78,13 +78,17 @@ func printUsage() {
fmt.Println("Usage: engine [command] [--daemon]")
fmt.Println("\nCommands:")
fmt.Println(" run Start the WebSocket ingestor and processing engine")
fmt.Println(" Use --daemon to run in background and log to engine.log")
fmt.Println(" Use --daemon to run in background and log to the file defined in config")
fmt.Println(" recover Run startup recovery to migrate stale ticks")
fmt.Println(" maintain Run a single maintenance cycle (cleanup/retention)")
fmt.Println(" help Show this help message")
}
func startDaemon() {
func startDaemon(logPath string) {
if logPath == "" {
logPath = "engine.log"
}
// Prepare arguments for the child process (remove --daemon)
args := []string{}
for _, arg := range os.Args[1:] {
@@ -93,24 +97,24 @@ func startDaemon() {
}
}
// Prepare the command
// Prepare the command to re-run the current binary
cmd := exec.Command(os.Args[0], args...)
// Open log file for output redirection
logFile, err := os.OpenFile("engine.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
// Open the configured log file for output redirection
logFile, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("Failed to open log file: %v", err)
log.Fatalf("Failed to open log file %s: %v", logPath, err)
}
cmd.Stdout = logFile
cmd.Stderr = logFile
// Start the process
// Start the process in the background
if err := cmd.Start(); err != nil {
log.Fatalf("Failed to start daemon: %v", err)
}
fmt.Printf("Engine started in background (PID: %d). Logs: engine.log\n", cmd.Process.Pid)
fmt.Printf("Engine started in background (PID: %d). Logs: %s\n", cmd.Process.Pid, logPath)
os.Exit(0)
}