| 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 17 matching lines...) Expand all Loading... |
| 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 bool LogMessageToAsl( |
| 37 logging::LogSeverity severity, | 37 logging::LogSeverity severity, |
| 38 const char* file, | 38 const std::string& file, |
| 39 int line, | 39 int line, |
| 40 size_t message_start, | |
| 41 const std::string& message) { | 40 const std::string& message) { |
| 42 int level; | 41 int level; |
| 43 switch(severity) { | 42 switch(severity) { |
| 44 case logging::LOG_INFO: | 43 case logging::LOG_INFO: |
| 45 level = ASL_LEVEL_NOTICE; | 44 level = ASL_LEVEL_NOTICE; |
| 46 break; | 45 break; |
| 47 case logging::LOG_WARNING: | 46 case logging::LOG_WARNING: |
| 48 level = ASL_LEVEL_WARNING; | 47 level = ASL_LEVEL_WARNING; |
| 49 break; | 48 break; |
| 50 case logging::LOG_ERROR: | 49 case logging::LOG_ERROR: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 69 if (asl_set(asl_message.get(), ASL_KEY_LEVEL, | 68 if (asl_set(asl_message.get(), ASL_KEY_LEVEL, |
| 70 base::IntToString(level).c_str()) != 0) | 69 base::IntToString(level).c_str()) != 0) |
| 71 return false; | 70 return false; |
| 72 | 71 |
| 73 // Restrict read access to the message to root and the current user. | 72 // Restrict read access to the message to root and the current user. |
| 74 if (asl_set(asl_message.get(), ASL_KEY_READ_UID, | 73 if (asl_set(asl_message.get(), ASL_KEY_READ_UID, |
| 75 base::IntToString(geteuid()).c_str()) != 0) | 74 base::IntToString(geteuid()).c_str()) != 0) |
| 76 return false; | 75 return false; |
| 77 | 76 |
| 78 if (asl_set(asl_message.get(), ASL_KEY_MSG, | 77 if (asl_set(asl_message.get(), ASL_KEY_MSG, |
| 79 message.c_str() + message_start) != 0) | 78 message.c_str()) != 0) |
| 80 return false; | 79 return false; |
| 81 | 80 |
| 82 asl_send(nullptr, asl_message.get()); | 81 asl_send(nullptr, asl_message.get()); |
| 83 | 82 |
| 84 // Don't prevent message from being logged by traditional means. | 83 // Don't prevent message from being logged by traditional means. |
| 85 return false; | 84 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::AddLogMessageHandler(LogMessageToAsl); |
| 98 } | 97 } |
| 99 | 98 |
| 100 } // namespace remoting | 99 } // namespace remoting |
| OLD | NEW |