From 1b812f9cd64c14ab7600626c147da88f21e0217c Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Tue, 5 Mar 2024 10:56:01 -0800 Subject: [lldb] Log to system log instead of stderr from Host::SystemLog (#83366) Currently, calls to Host::SystemLog print to stderr on all host platforms except Darwin. This severely limits its value on the command line, where we don't want to overload the user with log messages. Switch to using the syslog function on POSIX systems to send messages to the system logger instead of stdout. On Darwin systems this sends the log message to os_log, which matches what we do today. Nevertheless I kept the current implementation that uses os_log directly as it gives us more freedom. I'm not sure if there's an equivalent on Windows, so I kept the existing behavior of logging to stderr. --- lldb/source/Host/common/Host.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp index f4cec97..565138b 100644 --- a/lldb/source/Host/common/Host.cpp +++ b/lldb/source/Host/common/Host.cpp @@ -89,8 +89,19 @@ using namespace lldb; using namespace lldb_private; #if !defined(__APPLE__) +#if !defined(_WIN32) +#include +void Host::SystemLog(llvm::StringRef message) { + static llvm::once_flag g_openlog_once; + llvm::call_once(g_openlog_once, [] { + openlog("lldb", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER); + }); + syslog(LOG_INFO, "%s", message.data()); +} +#else void Host::SystemLog(llvm::StringRef message) { llvm::errs() << message; } #endif +#endif #if !defined(__APPLE__) && !defined(_WIN32) static thread_result_t -- cgit v1.1