Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(513)

Unified Diff: remoting/host/logging_mac.cc

Issue 2034393004: Allow multiple logging::LogMessage{Handler,Listener}s Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/host/logging_mac.cc
diff --git a/remoting/host/logging_mac.cc b/remoting/host/logging_mac.cc
index 39e007d409b528d5fe9b38307afe9ebc84dd8d94..ae6870c728334553ee03107304c4da3ad988e044 100644
--- a/remoting/host/logging_mac.cc
+++ b/remoting/host/logging_mac.cc
@@ -33,12 +33,19 @@ typedef base::ScopedGeneric<aslmsg, ScopedAslMsgTraits> ScopedAslMsg;
// Logging message handler that writes to syslog.
// The log can be obtained by running the following in a terminal:
// syslog -k Facility org.chromium.chromoting
-bool LogMessageToAsl(
- logging::LogSeverity severity,
- const char* file,
- int line,
- size_t message_start,
- const std::string& message) {
+class LogMessageListener : logging::LogMessageListener {
+ void OnMessage(logging::LogSeverity severity,
+ const char* file,
+ int line,
+ size_t message_start,
+ const std::string& message) override;
+};
+
+void LogMessageListener::OnMessage(logging::LogSeverity severity,
+ const char* file,
+ int line,
+ size_t message_start,
+ const std::string& message) {
int level;
switch(severity) {
case logging::LOG_INFO:
@@ -60,29 +67,28 @@ bool LogMessageToAsl(
ScopedAslMsg asl_message(asl_new(ASL_TYPE_MSG));
if (!asl_message.is_valid())
- return false;
+ return;
if (asl_set(asl_message.get(), ASL_KEY_FACILITY,
kChromotingLoggingFacility) != 0)
- return false;
+ return;
if (asl_set(asl_message.get(), ASL_KEY_LEVEL,
base::IntToString(level).c_str()) != 0)
- return false;
+ return;
// Restrict read access to the message to root and the current user.
if (asl_set(asl_message.get(), ASL_KEY_READ_UID,
base::IntToString(geteuid()).c_str()) != 0)
- return false;
+ return;
if (asl_set(asl_message.get(), ASL_KEY_MSG,
message.c_str() + message_start) != 0)
- return false;
+ return;
asl_send(nullptr, asl_message.get());
// Don't prevent message from being logged by traditional means.
- return false;
}
} // namespace
@@ -94,7 +100,9 @@ void InitHostLogging() {
logging::InitLogging(settings);
// Write logs to syslog as well.
- logging::SetLogMessageHandler(LogMessageToAsl);
+ // Intentionally leak the listener
+ auto* listener = new LogMessageListener();
+ CHECK(listener);
}
} // namespace remoting
« no previous file with comments | « remoting/host/it2me/it2me_native_messaging_host_unittest.cc ('k') | remoting/host/native_messaging/log_message_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698