OLD | NEW |
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 Loading... |
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 void LogMessageToAsl( |
37 logging::LogSeverity severity, | 37 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) { |
42 int level; | 42 int level; |
43 switch(severity) { | 43 switch(severity) { |
44 case logging::LOG_INFO: | 44 case logging::LOG_INFO: |
45 level = ASL_LEVEL_NOTICE; | 45 level = ASL_LEVEL_NOTICE; |
46 break; | 46 break; |
47 case logging::LOG_WARNING: | 47 case logging::LOG_WARNING: |
48 level = ASL_LEVEL_WARNING; | 48 level = ASL_LEVEL_WARNING; |
49 break; | 49 break; |
50 case logging::LOG_ERROR: | 50 case logging::LOG_ERROR: |
51 case logging::LOG_FATAL: | 51 case logging::LOG_FATAL: |
52 level = ASL_LEVEL_ERR; | 52 level = ASL_LEVEL_ERR; |
53 break; | 53 break; |
54 default: | 54 default: |
55 // 'notice' is the lowest priority that the asl libraries will log by | 55 // 'notice' is the lowest priority that the asl libraries will log by |
56 // default. | 56 // default. |
57 level = ASL_LEVEL_NOTICE; | 57 level = ASL_LEVEL_NOTICE; |
58 break; | 58 break; |
59 } | 59 } |
60 | 60 |
61 ScopedAslMsg asl_message(asl_new(ASL_TYPE_MSG)); | 61 ScopedAslMsg asl_message(asl_new(ASL_TYPE_MSG)); |
62 if (!asl_message.is_valid()) | 62 if (!asl_message.is_valid()) |
63 return false; | 63 return; |
64 | 64 |
65 if (asl_set(asl_message.get(), ASL_KEY_FACILITY, | 65 if (asl_set(asl_message.get(), ASL_KEY_FACILITY, |
66 kChromotingLoggingFacility) != 0) | 66 kChromotingLoggingFacility) != 0) |
67 return false; | 67 return; |
68 | 68 |
69 if (asl_set(asl_message.get(), ASL_KEY_LEVEL, | 69 if (asl_set(asl_message.get(), ASL_KEY_LEVEL, |
70 base::IntToString(level).c_str()) != 0) | 70 base::IntToString(level).c_str()) != 0) |
71 return false; | 71 return; |
72 | 72 |
73 // Restrict read access to the message to root and the current user. | 73 // Restrict read access to the message to root and the current user. |
74 if (asl_set(asl_message.get(), ASL_KEY_READ_UID, | 74 if (asl_set(asl_message.get(), ASL_KEY_READ_UID, |
75 base::IntToString(geteuid()).c_str()) != 0) | 75 base::IntToString(geteuid()).c_str()) != 0) |
76 return false; | 76 return; |
77 | 77 |
78 if (asl_set(asl_message.get(), ASL_KEY_MSG, | 78 if (asl_set(asl_message.get(), ASL_KEY_MSG, |
79 message.c_str() + message_start) != 0) | 79 message.c_str() + message_start) != 0) |
80 return false; | 80 return; |
81 | 81 |
82 asl_send(nullptr, asl_message.get()); | 82 asl_send(nullptr, asl_message.get()); |
83 | 83 |
84 // Don't prevent message from being logged by traditional means. | 84 // Don't prevent message from being logged by traditional means. |
85 return false; | |
86 } | 85 } |
87 | 86 |
88 } // namespace | 87 } // namespace |
89 | 88 |
90 void InitHostLogging() { | 89 void InitHostLogging() { |
91 // Write logs to the system debug log. | 90 // Write logs to the system debug log. |
92 logging::LoggingSettings settings; | 91 logging::LoggingSettings settings; |
93 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 92 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
94 logging::InitLogging(settings); | 93 logging::InitLogging(settings); |
95 | 94 |
96 // Write logs to syslog as well. | 95 // Write logs to syslog as well. |
97 logging::SetLogMessageHandler(LogMessageToAsl); | 96 logging::AddLogMessageListener(LogMessageToAsl); |
98 } | 97 } |
99 | 98 |
100 } // namespace remoting | 99 } // namespace remoting |
OLD | NEW |