| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #define WEBRTC_BASE_LOGGING_H_ | 47 #define WEBRTC_BASE_LOGGING_H_ |
| 48 | 48 |
| 49 #ifdef HAVE_CONFIG_H | 49 #ifdef HAVE_CONFIG_H |
| 50 #include "config.h" // NOLINT | 50 #include "config.h" // NOLINT |
| 51 #endif | 51 #endif |
| 52 | 52 |
| 53 #include <list> | 53 #include <list> |
| 54 #include <sstream> | 54 #include <sstream> |
| 55 #include <string> | 55 #include <string> |
| 56 #include <utility> | 56 #include <utility> |
| 57 |
| 57 #include "webrtc/base/basictypes.h" | 58 #include "webrtc/base/basictypes.h" |
| 58 #include "webrtc/base/criticalsection.h" | 59 #include "webrtc/base/constructormagic.h" |
| 59 #include "webrtc/base/thread_annotations.h" | 60 #include "webrtc/base/thread_annotations.h" |
| 60 | 61 |
| 61 namespace rtc { | 62 namespace rtc { |
| 62 | 63 |
| 63 /////////////////////////////////////////////////////////////////////////////// | 64 /////////////////////////////////////////////////////////////////////////////// |
| 64 // ConstantLabel can be used to easily generate string names from constant | 65 // ConstantLabel can be used to easily generate string names from constant |
| 65 // values. This can be useful for logging descriptive names of error messages. | 66 // values. This can be useful for logging descriptive names of error messages. |
| 66 // Usage: | 67 // Usage: |
| 67 // const ConstantLabel LIBRARY_ERRORS[] = { | 68 // const ConstantLabel LIBRARY_ERRORS[] = { |
| 68 // KLABEL(SOME_ERROR), | 69 // KLABEL(SOME_ERROR), |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 // Virtual sink interface that can receive log messages. | 125 // Virtual sink interface that can receive log messages. |
| 125 class LogSink { | 126 class LogSink { |
| 126 public: | 127 public: |
| 127 LogSink() {} | 128 LogSink() {} |
| 128 virtual ~LogSink() {} | 129 virtual ~LogSink() {} |
| 129 virtual void OnLogMessage(const std::string& message) = 0; | 130 virtual void OnLogMessage(const std::string& message) = 0; |
| 130 }; | 131 }; |
| 131 | 132 |
| 132 class LogMessage { | 133 class LogMessage { |
| 133 public: | 134 public: |
| 134 static const uint32_t WARN_SLOW_LOGS_DELAY = 50; // ms | |
| 135 | |
| 136 LogMessage(const char* file, int line, LoggingSeverity sev, | 135 LogMessage(const char* file, int line, LoggingSeverity sev, |
| 137 LogErrorContext err_ctx = ERRCTX_NONE, int err = 0, | 136 LogErrorContext err_ctx = ERRCTX_NONE, int err = 0, |
| 138 const char* module = NULL); | 137 const char* module = NULL); |
| 139 | 138 |
| 140 LogMessage(const char* file, | 139 LogMessage(const char* file, |
| 141 int line, | 140 int line, |
| 142 LoggingSeverity sev, | 141 LoggingSeverity sev, |
| 143 const std::string& tag); | 142 const std::string& tag); |
| 144 | 143 |
| 145 ~LogMessage(); | 144 ~LogMessage(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 188 |
| 190 // Parses the provided parameter stream to configure the options above. | 189 // Parses the provided parameter stream to configure the options above. |
| 191 // Useful for configuring logging from the command line. | 190 // Useful for configuring logging from the command line. |
| 192 static void ConfigureLogging(const char* params); | 191 static void ConfigureLogging(const char* params); |
| 193 | 192 |
| 194 private: | 193 private: |
| 195 typedef std::pair<LogSink*, LoggingSeverity> StreamAndSeverity; | 194 typedef std::pair<LogSink*, LoggingSeverity> StreamAndSeverity; |
| 196 typedef std::list<StreamAndSeverity> StreamList; | 195 typedef std::list<StreamAndSeverity> StreamList; |
| 197 | 196 |
| 198 // Updates min_sev_ appropriately when debug sinks change. | 197 // Updates min_sev_ appropriately when debug sinks change. |
| 199 static void UpdateMinLogSeverity() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 198 static void UpdateMinLogSeverity(); |
| 200 | 199 |
| 201 // These write out the actual log messages. | 200 // These write out the actual log messages. |
| 202 static void OutputToDebug(const std::string& msg, | 201 static void OutputToDebug(const std::string& msg, |
| 203 LoggingSeverity severity, | 202 LoggingSeverity severity, |
| 204 const std::string& tag); | 203 const std::string& tag); |
| 205 | 204 |
| 206 // The ostream that buffers the formatted message before output | 205 // The ostream that buffers the formatted message before output |
| 207 std::ostringstream print_stream_; | 206 std::ostringstream print_stream_; |
| 208 | 207 |
| 209 // The severity level of this message | 208 // The severity level of this message |
| 210 LoggingSeverity severity_; | 209 LoggingSeverity severity_; |
| 211 | 210 |
| 212 // The Android debug output tag. | 211 // The Android debug output tag. |
| 213 std::string tag_; | 212 std::string tag_; |
| 214 | 213 |
| 215 // String data generated in the constructor, that should be appended to | 214 // String data generated in the constructor, that should be appended to |
| 216 // the message before output. | 215 // the message before output. |
| 217 std::string extra_; | 216 std::string extra_; |
| 218 | 217 |
| 219 // If time it takes to write to stream is more than this, log one | |
| 220 // additional warning about it. | |
| 221 uint32_t warn_slow_logs_delay_; | |
| 222 | |
| 223 // Global lock for the logging subsystem | |
| 224 static CriticalSection crit_; | |
| 225 | |
| 226 // dbg_sev_ is the thresholds for those output targets | 218 // dbg_sev_ is the thresholds for those output targets |
| 227 // min_sev_ is the minimum (most verbose) of those levels, and is used | 219 // min_sev_ is the minimum (most verbose) of those levels, and is used |
| 228 // as a short-circuit in the logging macros to identify messages that won't | 220 // as a short-circuit in the logging macros to identify messages that won't |
| 229 // be logged. | 221 // be logged. |
| 230 // ctx_sev_ is the minimum level at which file context is displayed | 222 // ctx_sev_ is the minimum level at which file context is displayed |
| 231 static LoggingSeverity min_sev_, dbg_sev_, ctx_sev_; | 223 static LoggingSeverity min_sev_, dbg_sev_, ctx_sev_; |
| 232 | 224 |
| 233 // The output streams and their associated severities | 225 // The output streams and their associated severities |
| 234 static StreamList streams_; | 226 static StreamList streams_; |
| 235 | 227 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 #define PLOG(sev, err) \ | 351 #define PLOG(sev, err) \ |
| 360 LOG_ERR_EX(sev, err) | 352 LOG_ERR_EX(sev, err) |
| 361 | 353 |
| 362 // TODO(?): Add an "assert" wrapper that logs in the same manner. | 354 // TODO(?): Add an "assert" wrapper that logs in the same manner. |
| 363 | 355 |
| 364 #endif // LOG | 356 #endif // LOG |
| 365 | 357 |
| 366 } // namespace rtc | 358 } // namespace rtc |
| 367 | 359 |
| 368 #endif // WEBRTC_BASE_LOGGING_H_ | 360 #endif // WEBRTC_BASE_LOGGING_H_ |
| OLD | NEW |