Skip to content

Commit abf0ee0

Browse files
committed
Adds --log_file flag.
- The flag allows to write logs to an specific file. Logs would continue to be written to standard error.
1 parent bfd8c7c commit abf0ee0

File tree

1 file changed

+12
-0
lines changed
  • frontend/src/host_orchestrator

1 file changed

+12
-0
lines changed

frontend/src/host_orchestrator/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818
import (
1919
"flag"
2020
"fmt"
21+
"io"
2122
"log"
2223
"net/http"
2324
"net/http/httputil"
@@ -110,9 +111,20 @@ func main() {
110111
abURL := flag.String("android_build_url", defaultAndroidBuildURL, "URL to an Android Build API.")
111112
imRootDir := flag.String("cvd_artifacts_dir", defaultCVDArtifactsDir(), "Directory where cvd will download android build artifacts to.")
112113
address := flag.String("listen_addr", DefaultListenAddress, "IP address to listen for requests.")
114+
logFile := flag.String("log_file", "", "Path to file to write logs to.")
113115

114116
flag.Parse()
115117

118+
if *logFile != "" {
119+
f, err := os.OpenFile(*logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
120+
if err != nil {
121+
log.Fatalf("error opening log file %q: %v", *logFile, err)
122+
}
123+
defer f.Close()
124+
w := io.MultiWriter(os.Stderr, f)
125+
log.SetOutput(w)
126+
}
127+
116128
if err := os.MkdirAll(*imRootDir, 0774); err != nil {
117129
log.Fatalf("Unable to create artifacts directory: %v", err)
118130
}

0 commit comments

Comments
 (0)