| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef THIRD_PARTY_LIBJINGLE_OVERRIDES_WEBRTC_BASE_DIAGNOSTIC_LOGGING_H_ | 11 #ifndef THIRD_PARTY_LIBJINGLE_OVERRIDES_WEBRTC_BASE_DIAGNOSTIC_LOGGING_H_ |
| 12 #define THIRD_PARTY_LIBJINGLE_OVERRIDES_WEBRTC_BASE_DIAGNOSTIC_LOGGING_H_ | 12 #define THIRD_PARTY_LIBJINGLE_OVERRIDES_WEBRTC_BASE_DIAGNOSTIC_LOGGING_H_ |
| 13 | 13 |
| 14 #include <sstream> | 14 #include <sstream> |
| 15 #include <string> | 15 #include <string> |
| 16 | 16 |
| 17 #include "base/logging.h" | 17 #include "third_party/webrtc/base/checks.h" |
| 18 #include "third_party/webrtc/base/scoped_ref_ptr.h" | 18 #include "third_party/webrtc/base/scoped_ref_ptr.h" |
| 19 | 19 |
| 20 namespace rtc { | 20 namespace rtc { |
| 21 | 21 |
| 22 /////////////////////////////////////////////////////////////////////////////// | 22 /////////////////////////////////////////////////////////////////////////////// |
| 23 // ConstantLabel can be used to easily generate string names from constant | 23 // ConstantLabel can be used to easily generate string names from constant |
| 24 // values. This can be useful for logging descriptive names of error messages. | 24 // values. This can be useful for logging descriptive names of error messages. |
| 25 // Usage: | 25 // Usage: |
| 26 // const ConstantLabel LIBRARY_ERRORS[] = { | 26 // const ConstantLabel LIBRARY_ERRORS[] = { |
| 27 // KLABEL(SOME_ERROR), | 27 // KLABEL(SOME_ERROR), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // these constants as Chrome does. | 65 // these constants as Chrome does. |
| 66 enum LoggingSeverity { LS_ERROR = 1, | 66 enum LoggingSeverity { LS_ERROR = 1, |
| 67 LS_WARNING = 2, | 67 LS_WARNING = 2, |
| 68 LS_INFO = 3, | 68 LS_INFO = 3, |
| 69 LS_VERBOSE = 4, | 69 LS_VERBOSE = 4, |
| 70 LS_SENSITIVE = 5, | 70 LS_SENSITIVE = 5, |
| 71 INFO = LS_INFO, | 71 INFO = LS_INFO, |
| 72 WARNING = LS_WARNING, | 72 WARNING = LS_WARNING, |
| 73 LERROR = LS_ERROR }; | 73 LERROR = LS_ERROR }; |
| 74 | 74 |
| 75 inline int WebRtcSevToChromeSev(LoggingSeverity sev) { | |
| 76 switch (sev) { | |
| 77 case LS_ERROR: | |
| 78 return ::logging::LOG_ERROR; | |
| 79 case LS_WARNING: | |
| 80 return ::logging::LOG_WARNING; | |
| 81 case LS_INFO: | |
| 82 return ::logging::LOG_INFO; | |
| 83 case LS_VERBOSE: | |
| 84 case LS_SENSITIVE: | |
| 85 return ::logging::LOG_VERBOSE; | |
| 86 default: | |
| 87 NOTREACHED(); | |
| 88 return ::logging::LOG_FATAL; | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 inline int WebRtcVerbosityLevel(LoggingSeverity sev) { | |
| 93 switch (sev) { | |
| 94 case LS_ERROR: | |
| 95 return -2; | |
| 96 case LS_WARNING: | |
| 97 return -1; | |
| 98 case LS_INFO: // We treat 'info' and 'verbose' as the same verbosity level. | |
| 99 case LS_VERBOSE: | |
| 100 return 1; | |
| 101 case LS_SENSITIVE: | |
| 102 return 2; | |
| 103 default: | |
| 104 NOTREACHED(); | |
| 105 return 0; | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 // LogErrorContext assists in interpreting the meaning of an error value. | 75 // LogErrorContext assists in interpreting the meaning of an error value. |
| 110 enum LogErrorContext { | 76 enum LogErrorContext { |
| 111 ERRCTX_NONE, | 77 ERRCTX_NONE, |
| 112 ERRCTX_ERRNO, // System-local errno | 78 ERRCTX_ERRNO, // System-local errno |
| 113 ERRCTX_HRESULT, // Windows HRESULT | 79 ERRCTX_HRESULT, // Windows HRESULT |
| 114 ERRCTX_OSSTATUS, // MacOS OSStatus | 80 ERRCTX_OSSTATUS, // MacOS OSStatus |
| 115 | 81 |
| 116 // Abbreviations for LOG_E macro | 82 // Abbreviations for LOG_E macro |
| 117 ERRCTX_EN = ERRCTX_ERRNO, // LOG_E(sev, EN, x) | 83 ERRCTX_EN = ERRCTX_ERRNO, // LOG_E(sev, EN, x) |
| 118 ERRCTX_HR = ERRCTX_HRESULT, // LOG_E(sev, HR, x) | 84 ERRCTX_HR = ERRCTX_HRESULT, // LOG_E(sev, HR, x) |
| 119 ERRCTX_OS = ERRCTX_OSSTATUS, // LOG_E(sev, OS, x) | 85 ERRCTX_OS = ERRCTX_OSSTATUS, // LOG_E(sev, OS, x) |
| 120 }; | 86 }; |
| 121 | 87 |
| 122 // Class that writes a log message to the logging delegate ("WebRTC logging | 88 // Class that writes a log message to the logging delegate ("WebRTC logging |
| 123 // stream" in Chrome) and to Chrome's logging stream. | 89 // stream" in Chrome) and to Chrome's logging stream. |
| 124 class DiagnosticLogMessage { | 90 class DiagnosticLogMessage { |
| 125 public: | 91 public: |
| 126 DiagnosticLogMessage(const char* file, int line, LoggingSeverity severity, | 92 DiagnosticLogMessage(const char* file, int line, LoggingSeverity severity, |
| 127 bool log_to_chrome, LogErrorContext err_ctx, int err); | 93 LogErrorContext err_ctx, int err); |
| 128 DiagnosticLogMessage(const char* file, int line, LoggingSeverity severity, | 94 DiagnosticLogMessage(const char* file, int line, LoggingSeverity severity, |
| 129 bool log_to_chrome, LogErrorContext err_ctx, int err, | 95 LogErrorContext err_ctx, int err, const char* module); |
| 130 const char* module); | |
| 131 ~DiagnosticLogMessage(); | 96 ~DiagnosticLogMessage(); |
| 132 | 97 |
| 133 void CreateTimestamp(); | 98 void CreateTimestamp(); |
| 134 | 99 |
| 135 std::ostream& stream() { return print_stream_; } | 100 std::ostream& stream() { return print_stream_; } |
| 136 | 101 |
| 137 private: | 102 private: |
| 138 const char* file_name_; | 103 const char* file_name_; |
| 139 const int line_; | 104 const int line_; |
| 140 const LoggingSeverity severity_; | 105 const LoggingSeverity severity_; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 // InitDiagnosticLogging. Change also in init_webrtc.h/cc. | 148 // InitDiagnosticLogging. Change also in init_webrtc.h/cc. |
| 184 // TODO(grunell): typedef the delegate function. | 149 // TODO(grunell): typedef the delegate function. |
| 185 void InitDiagnosticLoggingDelegateFunction( | 150 void InitDiagnosticLoggingDelegateFunction( |
| 186 void (*delegate)(const std::string&)); | 151 void (*delegate)(const std::string&)); |
| 187 | 152 |
| 188 void SetExtraLoggingInit( | 153 void SetExtraLoggingInit( |
| 189 void (*function)(void (*delegate)(const std::string&))); | 154 void (*function)(void (*delegate)(const std::string&))); |
| 190 } // namespace rtc | 155 } // namespace rtc |
| 191 | 156 |
| 192 #endif // THIRD_PARTY_LIBJINGLE_OVERRIDES_WEBRTC_BASE_DIAGNOSTIC_LOGGING_H_ | 157 #endif // THIRD_PARTY_LIBJINGLE_OVERRIDES_WEBRTC_BASE_DIAGNOSTIC_LOGGING_H_ |
| OLD | NEW |