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

Unified Diff: remoting/host/logging_mac.cc

Issue 1073883002: Change logging to syslog; fix CRD in Yosemite (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « remoting/host/logging_linux.cc ('k') | remoting/host/logging_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/logging_mac.cc
diff --git a/remoting/host/logging_mac.cc b/remoting/host/logging_mac.cc
new file mode 100644
index 0000000000000000000000000000000000000000..08249e874b3aafb17a5599c2ae8e2263d1b349db
--- /dev/null
+++ b/remoting/host/logging_mac.cc
@@ -0,0 +1,101 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/host/logging.h"
+
+#include <asl.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "base/logging.h"
+#include "base/scoped_generic.h"
+#include "base/strings/string_number_conversions.h"
+
+namespace remoting {
+
+namespace {
+
+const char kChromotingLoggingFacility[] = "org.chromium.chromoting";
+
+// Define a scoper for objects allocated by asl_new.
+struct ScopedAslMsgTraits {
+ static aslmsg InvalidValue() {
+ return nullptr;
+ }
+ static void Free(aslmsg msg) {
+ asl_free(msg);
+ }
+};
+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) {
+ int level;
+ switch(severity) {
+ case logging::LOG_INFO:
+ level = ASL_LEVEL_NOTICE;
+ break;
+ case logging::LOG_WARNING:
+ level = ASL_LEVEL_WARNING;
+ break;
+ case logging::LOG_ERROR:
+ level = ASL_LEVEL_ERR;
+ break;
+ case logging::LOG_FATAL:
+ level = ASL_LEVEL_EMERG;
+ break;
+ default:
+ // 'notice' is the lowest priority that the asl libraries will log by
+ // default.
+ level = ASL_LEVEL_NOTICE;
+ break;
+ }
+
+ ScopedAslMsg asl_message(asl_new(ASL_TYPE_MSG));
+ if (!asl_message.is_valid())
+ return false;
+
+ if (asl_set(asl_message.get(), ASL_KEY_FACILITY,
+ kChromotingLoggingFacility) != 0)
+ return false;
+
+ if (asl_set(asl_message.get(), ASL_KEY_LEVEL,
+ base::IntToString(level).c_str()) != 0)
+ return false;
+
+ // 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;
+
+ if (asl_set(asl_message.get(), ASL_KEY_MSG,
+ message.c_str() + message_start) != 0)
+ return false;
+
+ asl_send(nullptr, asl_message.get());
+
+ // Don't prevent message from being logged by traditional means.
+ return false;
+}
+
+} // namespace
+
+void InitHostLogging() {
+ // Write logs to the system debug log.
+ logging::LoggingSettings settings;
+ settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
+ logging::InitLogging(settings);
+
+ // Write logs to syslog as well.
+ logging::SetLogMessageHandler(LogMessageToAsl);
+}
+
+} // namespace remoting
« no previous file with comments | « remoting/host/logging_linux.cc ('k') | remoting/host/logging_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698