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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 virtual void OnLogMessage(const std::string& message) = 0; | 129 virtual void OnLogMessage(const std::string& message) = 0; |
130 }; | 130 }; |
131 | 131 |
132 class LogMessage { | 132 class LogMessage { |
133 public: | 133 public: |
134 static const uint32 WARN_SLOW_LOGS_DELAY = 50; // ms | 134 static const uint32 WARN_SLOW_LOGS_DELAY = 50; // ms |
135 | 135 |
136 LogMessage(const char* file, int line, LoggingSeverity sev, | 136 LogMessage(const char* file, int line, LoggingSeverity sev, |
137 LogErrorContext err_ctx = ERRCTX_NONE, int err = 0, | 137 LogErrorContext err_ctx = ERRCTX_NONE, int err = 0, |
138 const char* module = NULL); | 138 const char* module = NULL); |
| 139 |
| 140 LogMessage(const char* file, |
| 141 int line, |
| 142 LoggingSeverity sev, |
| 143 const std::string& tag); |
| 144 |
139 ~LogMessage(); | 145 ~LogMessage(); |
140 | 146 |
141 static inline bool Loggable(LoggingSeverity sev) { return (sev >= min_sev_); } | 147 static inline bool Loggable(LoggingSeverity sev) { return (sev >= min_sev_); } |
142 std::ostream& stream() { return print_stream_; } | 148 std::ostream& stream() { return print_stream_; } |
143 | 149 |
144 // Returns the time at which this function was called for the first time. | 150 // Returns the time at which this function was called for the first time. |
145 // The time will be used as the logging start time. | 151 // The time will be used as the logging start time. |
146 // If this is not called externally, the LogMessage ctor also calls it, in | 152 // If this is not called externally, the LogMessage ctor also calls it, in |
147 // which case the logging start time will be the time of the first LogMessage | 153 // which case the logging start time will be the time of the first LogMessage |
148 // instance is created. | 154 // instance is created. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 static void ConfigureLogging(const char* params); | 192 static void ConfigureLogging(const char* params); |
187 | 193 |
188 private: | 194 private: |
189 typedef std::pair<LogSink*, LoggingSeverity> StreamAndSeverity; | 195 typedef std::pair<LogSink*, LoggingSeverity> StreamAndSeverity; |
190 typedef std::list<StreamAndSeverity> StreamList; | 196 typedef std::list<StreamAndSeverity> StreamList; |
191 | 197 |
192 // Updates min_sev_ appropriately when debug sinks change. | 198 // Updates min_sev_ appropriately when debug sinks change. |
193 static void UpdateMinLogSeverity() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 199 static void UpdateMinLogSeverity() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
194 | 200 |
195 // These write out the actual log messages. | 201 // These write out the actual log messages. |
196 static void OutputToDebug(const std::string& msg, LoggingSeverity severity_); | 202 static void OutputToDebug(const std::string& msg, |
| 203 LoggingSeverity severity, |
| 204 const std::string& tag); |
197 | 205 |
198 // The ostream that buffers the formatted message before output | 206 // The ostream that buffers the formatted message before output |
199 std::ostringstream print_stream_; | 207 std::ostringstream print_stream_; |
200 | 208 |
201 // The severity level of this message | 209 // The severity level of this message |
202 LoggingSeverity severity_; | 210 LoggingSeverity severity_; |
203 | 211 |
| 212 // The Android debug output tag. |
| 213 std::string android_tag_; |
| 214 |
204 // String data generated in the constructor, that should be appended to | 215 // String data generated in the constructor, that should be appended to |
205 // the message before output. | 216 // the message before output. |
206 std::string extra_; | 217 std::string extra_; |
207 | 218 |
208 // If time it takes to write to stream is more than this, log one | 219 // If time it takes to write to stream is more than this, log one |
209 // additional warning about it. | 220 // additional warning about it. |
210 uint32 warn_slow_logs_delay_; | 221 uint32 warn_slow_logs_delay_; |
211 | 222 |
212 // Global lock for the logging subsystem | 223 // Global lock for the logging subsystem |
213 static CriticalSection crit_; | 224 static CriticalSection crit_; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 (0) | 345 (0) |
335 #elif defined(WEBRTC_POSIX) | 346 #elif defined(WEBRTC_POSIX) |
336 #define LOG_ERR_EX(sev, err) \ | 347 #define LOG_ERR_EX(sev, err) \ |
337 LOG_ERRNO_EX(sev, err) | 348 LOG_ERRNO_EX(sev, err) |
338 #define LOG_ERR(sev) \ | 349 #define LOG_ERR(sev) \ |
339 LOG_ERRNO(sev) | 350 LOG_ERRNO(sev) |
340 #define LAST_SYSTEM_ERROR \ | 351 #define LAST_SYSTEM_ERROR \ |
341 (errno) | 352 (errno) |
342 #endif // WEBRTC_WIN | 353 #endif // WEBRTC_WIN |
343 | 354 |
| 355 #define LOG_TAG(sev, tag) \ |
| 356 LOG_SEVERITY_PRECONDITION(sev) \ |
| 357 rtc::LogMessage(__FILE__, __LINE__, sev, tag).stream() |
| 358 |
344 #define PLOG(sev, err) \ | 359 #define PLOG(sev, err) \ |
345 LOG_ERR_EX(sev, err) | 360 LOG_ERR_EX(sev, err) |
346 | 361 |
347 // TODO(?): Add an "assert" wrapper that logs in the same manner. | 362 // TODO(?): Add an "assert" wrapper that logs in the same manner. |
348 | 363 |
349 #endif // LOG | 364 #endif // LOG |
350 | 365 |
351 } // namespace rtc | 366 } // namespace rtc |
352 | 367 |
353 #endif // WEBRTC_BASE_LOGGING_H_ | 368 #endif // WEBRTC_BASE_LOGGING_H_ |
OLD | NEW |