[Lldb-commits] [lldb] [lldb-dap] Improving logging support and formatting. (PR #170731)

Ebuka Ezike via lldb-commits lldb-commits at lists.llvm.org
Fri Dec 5 09:11:38 PST 2025


================
@@ -642,17 +641,19 @@ int main(int argc, char *argv[]) {
   }
 #endif
 
-  std::unique_ptr<Log> log = nullptr;
-  const char *log_file_path = getenv("LLDBDAP_LOG");
-  if (log_file_path) {
-    std::error_code EC;
-    log = std::make_unique<Log>(log_file_path, EC);
-    if (EC) {
-      llvm::logAllUnhandledErrors(llvm::errorCodeToError(EC), llvm::errs(),
-                                  "Failed to create log file: ");
+  std::unique_ptr<llvm::raw_ostream> log_os;
+  if (const char *log_file_path = getenv("LLDBDAP_LOG"); log_file_path) {
+    int FD;
+    if (std::error_code EC =
+            llvm::sys::fs::openFileForWrite(log_file_path, FD)) {
+      llvm::errs() << "Failed to open log file: " << log_file_path << ": "
+                   << EC.message() << "\n";
       return EXIT_FAILURE;
     }
+    log_os = std::make_unique<llvm::raw_fd_ostream>(FD, /*shouldClose=*/true);
   }
+  Log::Mutex mutex;
+  Log log(log_os ? *log_os : llvm::nulls(), mutex);
----------------
da-viper wrote:

Just to confirm the `llvm::nulls()` does not actually create a file stream to `/dev/null` it is just a `no-op` 

https://github.com/llvm/llvm-project/pull/170731


More information about the lldb-commits mailing list