Skip to content

Cherrypick logging changes #5132

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

JDevlieghere
Copy link

  • [lldb] Introduce the concept of a log handler (NFC)
  • [lldb] Add RotatingLogHandler
  • [lldb] Remove LogHandler::Create functions (NFC)
  • [lldb] Support a buffered logging mode
  • [lldb] Make thread safety the responsibility of the log handlers
  • [lldb] Replace Host::SystemLog with Debugger::Report{Error,Warning}
  • [lldb] Add SystemLogHandler for emitting log messages to the system log
  • [lldb] Move Host::SystemLog out of !defined(_WIN32)
  • [lldb] Add support for specifying a log handler
  • [lldb] Add a log dump command

This patch introduces the concept of a log handlers. Log handlers allow
customizing the way log output is emitted. The StreamCallback class
tried to do something conceptually similar. The benefit of the log
handler interface is that you don't need to conform to llvm's
raw_ostream interface.

Differential revision: https://reviews.llvm.org/D127922

(cherry picked from commit 6ff49af)
Add a log handler that maintains a circular buffer with a fixed size.

Differential revision: https://reviews.llvm.org/D127937

(cherry picked from commit 6ac608b)
Remove the LogHandler::Create functions. Except for the StreamHandler
they were just forwarding their arguments to std::make_shared.

(cherry picked from commit de74756)
This patch adds a buffered logging mode to lldb. A buffer size can be
passed to `log enable` with the -b flag. If no buffer size is specified,
logging is unbuffered.

Differential revision: https://reviews.llvm.org/D127986

(cherry picked from commit 09dea54)
Drop the thread-safe flag and make the locking strategy the
responsibility of the individual log handler.

Previously we got away with a non-thread safe mode because we were using
unbuffered streams that rely on the underlying syscalls/OS for
synchronization. With the introduction of log handlers, we can have
arbitrary logic involved in writing out the logs. With this patch the
log handlers can pick the most appropriate locking strategy for their
particular implementation.

Differential revision: https://reviews.llvm.org/D127922

(cherry picked from commit 70841b9)
As it exists today, Host::SystemLog is used exclusively for error
reporting. With the introduction of diagnostic events, we have a better
way of reporting those. Instead of printing directly to stderr, these
messages now get printed to the debugger's error stream (when using the
default event handler). Alternatively, if someone is listening for these
events, they can decide how to display them, for example in the context
of an IDE such as Xcode.

This change also means we no longer write these messages to the system
log on Darwin. As far as I know, nobody is relying on this, but I think
this is something we could add to the diagnostic event mechanism.

Differential revision: https://reviews.llvm.org/D128480

(cherry picked from commit 6879391)
Add a system log handler that emits log messages to the operating system
log. In addition to the log handler itself, this patch also introduces a
new Host::SystemLog helper function to abstract over writing to the
system log.

Differential revision: https://reviews.llvm.org/D128321

(cherry picked from commit 1e5d526)
The definition of Host::SystemLog was (unintentionally) guarded by
!defined(_WIN32).

(cherry picked from commit 87a3293)
This patch adds a new flag to `log enable`, allowing the user to specify
a custom log handler. In addition to the default (stream) handler, this
allows using the circular log handler (which logs to a fixed size,
in-memory circular buffer) as well as the system log handler (which logs
to the operating system log).

Differential revision: https://reviews.llvm.org/D128323

(cherry picked from commit be265d2)
Add a log dump command to dump logs to a file. This only works for
channels that have a log handler associated that supports dumping. For
now that's limited to the circular log handler, but more could be added
in the future.

Differential revision: https://reviews.llvm.org/D128557

(cherry picked from commit 9bdb7e5)
@JDevlieghere
Copy link
Author

@swift-ci please test

1 similar comment
@JDevlieghere
Copy link
Author

@swift-ci please test

@JDevlieghere
Copy link
Author

@swift-ci please test

@JDevlieghere JDevlieghere merged commit 962469a into stable/20220421 Aug 16, 2022
@JDevlieghere JDevlieghere deleted the 🍒/rebranch/6ff49af33d09+6ac608b3d897+de7475657156+09dea546692f+70841b97eb2e+6879391908ca+1e5d5261e2b6+87a32939611a+be265d25ca5e+9bdb7e573427 branch August 16, 2022 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant