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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/logging.h" 5 #include "remoting/host/logging.h"
6 6
7 #include <asl.h> 7 #include <asl.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 15 matching lines...) Expand all
26 } 26 }
27 static void Free(aslmsg msg) { 27 static void Free(aslmsg msg) {
28 asl_free(msg); 28 asl_free(msg);
29 } 29 }
30 }; 30 };
31 typedef base::ScopedGeneric<aslmsg, ScopedAslMsgTraits> ScopedAslMsg; 31 typedef base::ScopedGeneric<aslmsg, ScopedAslMsgTraits> ScopedAslMsg;
32 32
33 // Logging message handler that writes to syslog. 33 // Logging message handler that writes to syslog.
34 // The log can be obtained by running the following in a terminal: 34 // The log can be obtained by running the following in a terminal:
35 // syslog -k Facility org.chromium.chromoting 35 // syslog -k Facility org.chromium.chromoting
36 bool LogMessageToAsl( 36 class LogMessageListener : logging::LogMessageListener {
37 logging::LogSeverity severity, 37 void OnMessage(logging::LogSeverity severity,
38 const char* file, 38 const char* file,
39 int line, 39 int line,
40 size_t message_start, 40 size_t message_start,
41 const std::string& message) { 41 const std::string& message) override;
42 };
43
44 void LogMessageListener::OnMessage(logging::LogSeverity severity,
45 const char* file,
46 int line,
47 size_t message_start,
48 const std::string& message) {
42 int level; 49 int level;
43 switch(severity) { 50 switch(severity) {
44 case logging::LOG_INFO: 51 case logging::LOG_INFO:
45 level = ASL_LEVEL_NOTICE; 52 level = ASL_LEVEL_NOTICE;
46 break; 53 break;
47 case logging::LOG_WARNING: 54 case logging::LOG_WARNING:
48 level = ASL_LEVEL_WARNING; 55 level = ASL_LEVEL_WARNING;
49 break; 56 break;
50 case logging::LOG_ERROR: 57 case logging::LOG_ERROR:
51 case logging::LOG_FATAL: 58 case logging::LOG_FATAL:
52 level = ASL_LEVEL_ERR; 59 level = ASL_LEVEL_ERR;
53 break; 60 break;
54 default: 61 default:
55 // 'notice' is the lowest priority that the asl libraries will log by 62 // 'notice' is the lowest priority that the asl libraries will log by
56 // default. 63 // default.
57 level = ASL_LEVEL_NOTICE; 64 level = ASL_LEVEL_NOTICE;
58 break; 65 break;
59 } 66 }
60 67
61 ScopedAslMsg asl_message(asl_new(ASL_TYPE_MSG)); 68 ScopedAslMsg asl_message(asl_new(ASL_TYPE_MSG));
62 if (!asl_message.is_valid()) 69 if (!asl_message.is_valid())
63 return false; 70 return;
64 71
65 if (asl_set(asl_message.get(), ASL_KEY_FACILITY, 72 if (asl_set(asl_message.get(), ASL_KEY_FACILITY,
66 kChromotingLoggingFacility) != 0) 73 kChromotingLoggingFacility) != 0)
67 return false; 74 return;
68 75
69 if (asl_set(asl_message.get(), ASL_KEY_LEVEL, 76 if (asl_set(asl_message.get(), ASL_KEY_LEVEL,
70 base::IntToString(level).c_str()) != 0) 77 base::IntToString(level).c_str()) != 0)
71 return false; 78 return;
72 79
73 // Restrict read access to the message to root and the current user. 80 // Restrict read access to the message to root and the current user.
74 if (asl_set(asl_message.get(), ASL_KEY_READ_UID, 81 if (asl_set(asl_message.get(), ASL_KEY_READ_UID,
75 base::IntToString(geteuid()).c_str()) != 0) 82 base::IntToString(geteuid()).c_str()) != 0)
76 return false; 83 return;
77 84
78 if (asl_set(asl_message.get(), ASL_KEY_MSG, 85 if (asl_set(asl_message.get(), ASL_KEY_MSG,
79 message.c_str() + message_start) != 0) 86 message.c_str() + message_start) != 0)
80 return false; 87 return;
81 88
82 asl_send(nullptr, asl_message.get()); 89 asl_send(nullptr, asl_message.get());
83 90
84 // Don't prevent message from being logged by traditional means. 91 // Don't prevent message from being logged by traditional means.
85 return false;
86 } 92 }
87 93
88 } // namespace 94 } // namespace
89 95
90 void InitHostLogging() { 96 void InitHostLogging() {
91 // Write logs to the system debug log. 97 // Write logs to the system debug log.
92 logging::LoggingSettings settings; 98 logging::LoggingSettings settings;
93 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 99 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
94 logging::InitLogging(settings); 100 logging::InitLogging(settings);
95 101
96 // Write logs to syslog as well. 102 // Write logs to syslog as well.
97 logging::SetLogMessageHandler(LogMessageToAsl); 103 // Intentionally leak the listener
104 auto* listener = new LogMessageListener();
105 CHECK(listener);
98 } 106 }
99 107
100 } // namespace remoting 108 } // namespace remoting
OLDNEW
« 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