| Index: base/logging.cc
|
| diff --git a/base/logging.cc b/base/logging.cc
|
| index 98cecd094fd84e7312c9a3e9998dfb44cfd05925..8322d905d16b800caf2126d4e75c77d2c91e5c65 100644
|
| --- a/base/logging.cc
|
| +++ b/base/logging.cc
|
| @@ -51,6 +51,7 @@ typedef pthread_mutex_t* MutexHandle;
|
| #include <algorithm>
|
| #include <cstring>
|
| #include <ctime>
|
| +#include <deque>
|
| #include <iomanip>
|
| #include <ostream>
|
| #include <string>
|
| @@ -60,6 +61,7 @@ typedef pthread_mutex_t* MutexHandle;
|
| #include "base/debug/alias.h"
|
| #include "base/debug/debugger.h"
|
| #include "base/debug/stack_trace.h"
|
| +#include "base/lazy_instance.h"
|
| #include "base/posix/eintr_wrapper.h"
|
| #include "base/strings/string_piece.h"
|
| #include "base/strings/string_util.h"
|
| @@ -125,8 +127,9 @@ bool show_error_dialogs = false;
|
| // An assert handler override specified by the client to be called instead of
|
| // the debug message dialog and process termination.
|
| LogAssertHandlerFunction log_assert_handler = nullptr;
|
| -// A log message handler that gets notified of every log message we process.
|
| -LogMessageHandlerFunction log_message_handler = nullptr;
|
| +// Log message handlers that get notified of every log message we process.
|
| +base::LazyInstance<std::deque<LogMessageHandlerFunction>>::Leaky
|
| + log_message_handlers = LAZY_INSTANCE_INITIALIZER;
|
|
|
| // Helper functions to wrap platform differences.
|
|
|
| @@ -400,7 +403,8 @@ bool ShouldCreateLogMessage(int severity) {
|
| // Return true here unless we know ~LogMessage won't do anything. Note that
|
| // ~LogMessage writes to stderr if severity_ >= kAlwaysPrintErrorLevel, even
|
| // when g_logging_destination is LOG_NONE.
|
| - return g_logging_destination != LOG_NONE || log_message_handler ||
|
| + return g_logging_destination != LOG_NONE ||
|
| + !log_message_handlers.Get().empty() ||
|
| severity >= kAlwaysPrintErrorLevel;
|
| }
|
|
|
| @@ -434,12 +438,18 @@ void SetLogAssertHandler(LogAssertHandlerFunction handler) {
|
| log_assert_handler = handler;
|
| }
|
|
|
| -void SetLogMessageHandler(LogMessageHandlerFunction handler) {
|
| - log_message_handler = handler;
|
| +void PushLogMessageHandler(LogMessageHandlerFunction handler) {
|
| + log_message_handlers.Get().push_front(handler);
|
| }
|
|
|
| -LogMessageHandlerFunction GetLogMessageHandler() {
|
| - return log_message_handler;
|
| +void PopLogMessageHandler() {
|
| + log_message_handlers.Get().pop_front();
|
| +}
|
| +
|
| +LogMessageHandlerFunction GetTopLogMessageHandler() {
|
| + if (log_message_handlers.Get().empty())
|
| + return nullptr;
|
| + return log_message_handlers.Get().front();
|
| }
|
|
|
| // Explicit instantiations for commonly used comparisons.
|
| @@ -528,12 +538,12 @@ LogMessage::~LogMessage() {
|
| stream_ << std::endl;
|
| std::string str_newline(stream_.str());
|
|
|
| - // Give any log message handler first dibs on the message.
|
| - if (log_message_handler &&
|
| - log_message_handler(severity_, file_, line_,
|
| - message_start_, str_newline)) {
|
| - // The handler took care of it, no further processing.
|
| - return;
|
| + // Give log message handlers first dibs on the message.
|
| + for (auto* handler : log_message_handlers.Get()) {
|
| + if (handler(severity_, file_, line_, message_start_, str_newline)) {
|
| + // The handler took care of it, no further processing.
|
| + return;
|
| + }
|
| }
|
|
|
| if ((g_logging_destination & LOG_TO_SYSTEM_DEBUG_LOG) != 0) {
|
|
|