-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lldb] Log to system log instead of stderr from Host::SystemLog #83366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) ChangesCurrently, 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. Full diff: https://github.com/llvm/llvm-project/pull/83366.diff 1 Files Affected:
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index f4cec97f5af633..1af01ef5025bc4 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -89,8 +89,17 @@ using namespace lldb;
using namespace lldb_private;
#if !defined(__APPLE__)
+#if !defined(_WIN32)
+#include <syslog.h>
+void Host::SystemLog(llvm::StringRef message) {
+ openlog("lldb", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
+ syslog(LOG_INFO, "%s", message.data());
+ closelog();
+}
+#else
void Host::SystemLog(llvm::StringRef message) { llvm::errs() << message; }
#endif
+#endif
#if !defined(__APPLE__) && !defined(_WIN32)
static thread_result_t
|
lldb/source/Host/common/Host.cpp
Outdated
openlog("lldb", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER); | ||
syslog(LOG_INFO, "%s", message.data()); | ||
closelog(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been a while since I really looked deep into the syslog APIs, which are a little archaic. And it's possible that calls to Host::SystemLog
are rare enough that none of these things are concerning, even if they are valid concerns for high load use cases:
- I believe it's typical for
openlog
andcloselog
to only be called once. Opening and closing on everysyslog
call may be costly/unnecessary. - But actually, both
openlog
andcloselog
are technically optional -- still a good idea to at least callopenlog
so you can passident
andoption
(thefacility
you could just pass in thesyslog
call). Forcloselog
, I wonder if you could just skip that, and hopefully theopenlog()
call on subsequentHost::SystemLog()
calls would end up being noop'd/cached? - IIRC, calls to
syslog
can block, e.g. if the daemon processing syslog entries gets backed up, thensyslog
will block until the queue becomes less full. Keepingsyslog
calls on a separate thread may be safer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, cc @oontvoo who is looking at this stuff more closely now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Jordan. I've moved the openlog
behind a call_once
flag and omitted the closelog
.
I considered executing syslog
on the debugger's thread pool but the fact that Core depends on Host means that would be a layering violation and there's no good place to manage the futures something like std::async
would return.
Right now the system log function is only used for the corresponding log handler which is purely opt-in. I do plan to use it in other places (e.g. the debugger diagnostics) but even then I expect it to be relatively low traffic.
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.
0694285
to
6656cf1
Compare
@rupprecht @oontvoo How do you feel about the current approach? The other alternative is to make this function a NOOP on all platforms but Darwin (where I want to actively use it). It's not currently load bearing (except the log, which is opt-in). |
This approach LGTM. Potentially we will want calls to |
…#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. (cherry picked from commit 1b812f9)
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.