Skip to content

Commit 0694285

Browse files
committed
[lldb] Log to system log instead of stderr from Host::SystemLog
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.
1 parent 9728170 commit 0694285

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lldb/source/Host/common/Host.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,17 @@ using namespace lldb;
8989
using namespace lldb_private;
9090

9191
#if !defined(__APPLE__)
92+
#if !defined(_WIN32)
93+
#include <syslog.h>
94+
void Host::SystemLog(llvm::StringRef message) {
95+
openlog("lldb", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
96+
syslog(LOG_INFO, "%s", message.data());
97+
closelog();
98+
}
99+
#else
92100
void Host::SystemLog(llvm::StringRef message) { llvm::errs() << message; }
93101
#endif
102+
#endif
94103

95104
#if !defined(__APPLE__) && !defined(_WIN32)
96105
static thread_result_t

0 commit comments

Comments
 (0)