cvd: Add support for logging to a file#2506
Conversation
| namespace cuttlefish { | ||
|
|
||
| std::vector<std::string> GetLogFiles() { | ||
| std::string log_dir = CvdDir() + "/logs"; |
There was a problem hiding this comment.
This should use PerUserDir() instead.
| std::stringstream ss; | ||
| ss << std::put_time(&tm_now, "%Y%m%d_%H%M%S") << "." << std::setfill('0') | ||
| << std::setw(3) << now_ms.count(); | ||
| return {absl::StrCat(log_dir, "/cvd_", ss.str(), ".log")}; |
There was a problem hiding this comment.
Why return a vector if it never returns more than one? Would an optional make more sense?
There was a problem hiding this comment.
std::optional makes more sense for the function, std::vector was more convenient to match the interface of LogToStderrAndFiles. Updated to return a std::optional.
Unfortunately adding an overload of LogToStderrAndFiles that takes a std::optional breaks several invocations that pass {} as the first argument because it becomes ambiguous between std::optional and std::vector even though the semantics of an empty optional and empty vector are the same.
| #include <time.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include <chrono> |
There was a problem hiding this comment.
chrono ins't used in this file. Some of the other new headers may not be needed either.
6e45cfe to
41e0e3e
Compare
Implement timestamped log file creation for the cvd command. Logs are saved in PerUserDir() + "/logs/" with a name like cvd_YYYYMMDD_HHMMSS.ms.log. This ensures logs are preserved across runs. Assisted-by: Jetski <jetski@google.com> Bug: b/507600500
Implement timestamped log file creation for the cvd command. Logs are saved in CvdDir() + "/logs/" with a name like
cvd_YYYYMMDD_HHMMSS.ms.log. This ensures logs are preserved across runs.
Assisted-by: Jetski jetski@google.com
Bug: b/507600500