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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « remoting/host/logging_linux.cc ('k') | remoting/host/logging_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/host/logging.h"
6
7 #include <asl.h>
8 #include <sys/types.h>
9 #include <unistd.h>
10
11 #include "base/logging.h"
12 #include "base/scoped_generic.h"
13 #include "base/strings/string_number_conversions.h"
14
15 namespace remoting {
16
17 namespace {
18
19 const char kChromotingLoggingFacility[] = "org.chromium.chromoting";
20
21 // Define a scoper for objects allocated by asl_new.
22 struct ScopedAslMsgTraits {
23 static aslmsg InvalidValue() {
24 return nullptr;
25 }
26 static void Free(aslmsg msg) {
27 asl_free(msg);
28 }
29 };
30 typedef base::ScopedGeneric<aslmsg, ScopedAslMsgTraits> ScopedAslMsg;
31
32 // Logging message handler that writes to syslog.
33 // The log can be obtained by running the following in a terminal:
34 // syslog -k Facility org.chromium.chromoting
35 bool LogMessageToAsl(
36 logging::LogSeverity severity,
37 const char* file,
38 int line,
39 size_t message_start,
40 const std::string& message) {
41 int level;
42 switch(severity) {
43 case logging::LOG_INFO:
44 level = ASL_LEVEL_NOTICE;
45 break;
46 case logging::LOG_WARNING:
47 level = ASL_LEVEL_WARNING;
48 break;
49 case logging::LOG_ERROR:
50 level = ASL_LEVEL_ERR;
51 break;
52 case logging::LOG_FATAL:
53 level = ASL_LEVEL_EMERG;
54 break;
55 default:
56 // 'notice' is the lowest priority that the asl libraries will log by
57 // default.
58 level = ASL_LEVEL_NOTICE;
59 break;
60 }
61
62 ScopedAslMsg asl_message(asl_new(ASL_TYPE_MSG));
63 if (!asl_message.is_valid())
64 return false;
65
66 if (asl_set(asl_message.get(), ASL_KEY_FACILITY,
67 kChromotingLoggingFacility) != 0)
68 return false;
69
70 if (asl_set(asl_message.get(), ASL_KEY_LEVEL,
71 base::IntToString(level).c_str()) != 0)
72 return false;
73
74 // Restrict read access to the message to root and the current user.
75 if (asl_set(asl_message.get(), ASL_KEY_READ_UID,
76 base::IntToString(geteuid()).c_str()) != 0)
77 return false;
78
79 if (asl_set(asl_message.get(), ASL_KEY_MSG,
80 message.c_str() + message_start) != 0)
81 return false;
82
83 asl_send(nullptr, asl_message.get());
84
85 // Don't prevent message from being logged by traditional means.
86 return false;
87 }
88
89 } // namespace
90
91 void InitHostLogging() {
92 // Write logs to the system debug log.
93 logging::LoggingSettings settings;
94 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
95 logging::InitLogging(settings);
96
97 // Write logs to syslog as well.
98 logging::SetLogMessageHandler(LogMessageToAsl);
99 }
100
101 } // namespace remoting
OLDNEW
« 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