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 26 matching lines...) Expand all Loading... | |
37 #include <vector> | 37 #include <vector> |
38 | 38 |
39 #include "webrtc/base/logging.h" | 39 #include "webrtc/base/logging.h" |
40 #include "webrtc/base/platform_thread.h" | 40 #include "webrtc/base/platform_thread.h" |
41 #include "webrtc/base/scoped_ptr.h" | 41 #include "webrtc/base/scoped_ptr.h" |
42 #include "webrtc/base/stringencode.h" | 42 #include "webrtc/base/stringencode.h" |
43 #include "webrtc/base/stringutils.h" | 43 #include "webrtc/base/stringutils.h" |
44 #include "webrtc/base/timeutils.h" | 44 #include "webrtc/base/timeutils.h" |
45 | 45 |
46 namespace rtc { | 46 namespace rtc { |
47 namespace { | |
48 | |
49 // Return the filename portion of the string (that following the last slash). | |
50 const char* FilenameFromPath(const char* file) { | |
51 const char* end1 = ::strrchr(file, '/'); | |
52 const char* end2 = ::strrchr(file, '\\'); | |
53 if (!end1 && !end2) | |
54 return file; | |
55 else | |
56 return (end1 > end2) ? end1 + 1 : end2 + 1; | |
57 } | |
58 | |
59 } // namespace | |
47 | 60 |
48 ///////////////////////////////////////////////////////////////////////////// | 61 ///////////////////////////////////////////////////////////////////////////// |
49 // Constant Labels | 62 // Constant Labels |
50 ///////////////////////////////////////////////////////////////////////////// | 63 ///////////////////////////////////////////////////////////////////////////// |
51 | 64 |
52 const char * FindLabel(int value, const ConstantLabel entries[]) { | 65 const char* FindLabel(int value, const ConstantLabel entries[]) { |
53 for (int i = 0; entries[i].label; ++i) { | 66 for (int i = 0; entries[i].label; ++i) { |
54 if (value == entries[i].value) { | 67 if (value == entries[i].value) { |
55 return entries[i].label; | 68 return entries[i].label; |
56 } | 69 } |
57 } | 70 } |
58 return 0; | 71 return 0; |
59 } | 72 } |
60 | 73 |
61 std::string ErrorName(int err, const ConstantLabel * err_table) { | 74 std::string ErrorName(int err, const ConstantLabel* err_table) { |
62 if (err == 0) | 75 if (err == 0) |
63 return "No error"; | 76 return "No error"; |
64 | 77 |
65 if (err_table != 0) { | 78 if (err_table != 0) { |
66 if (const char * value = FindLabel(err, err_table)) | 79 if (const char* value = FindLabel(err, err_table)) |
67 return value; | 80 return value; |
68 } | 81 } |
69 | 82 |
70 char buffer[16]; | 83 char buffer[16]; |
71 snprintf(buffer, sizeof(buffer), "0x%08x", err); | 84 snprintf(buffer, sizeof(buffer), "0x%08x", err); |
72 return buffer; | 85 return buffer; |
73 } | 86 } |
74 | 87 |
75 ///////////////////////////////////////////////////////////////////////////// | 88 ///////////////////////////////////////////////////////////////////////////// |
76 // LogMessage | 89 // LogMessage |
77 ///////////////////////////////////////////////////////////////////////////// | 90 ///////////////////////////////////////////////////////////////////////////// |
78 | 91 |
79 // By default, release builds don't log, debug builds at info level | 92 // By default, release builds don't log, debug builds at info level |
80 #if _DEBUG | 93 #if _DEBUG |
81 LoggingSeverity LogMessage::min_sev_ = LS_INFO; | 94 LoggingSeverity LogMessage::min_sev_ = LS_INFO; |
82 LoggingSeverity LogMessage::dbg_sev_ = LS_INFO; | 95 LoggingSeverity LogMessage::dbg_sev_ = LS_INFO; |
83 #else // !_DEBUG | 96 #else // !_DEBUG |
84 LoggingSeverity LogMessage::min_sev_ = LS_NONE; | 97 LoggingSeverity LogMessage::min_sev_ = LS_NONE; |
85 LoggingSeverity LogMessage::dbg_sev_ = LS_NONE; | 98 LoggingSeverity LogMessage::dbg_sev_ = LS_NONE; |
86 #endif // !_DEBUG | 99 #endif // !_DEBUG |
100 bool LogMessage::log_to_stderr_ = true; | |
87 | 101 |
88 // Global lock for log subsystem, only needed to serialize access to streams_. | 102 // Global lock for log subsystem, only needed to serialize access to streams_. |
89 CriticalSection LogMessage::crit_; | 103 CriticalSection LogMessage::crit_; |
90 | 104 |
91 // The list of logging streams currently configured. | 105 // The list of logging streams currently configured. |
92 // Note: we explicitly do not clean this up, because of the uncertain ordering | 106 // Note: we explicitly do not clean this up, because of the uncertain ordering |
93 // of destructors at program exit. Let the person who sets the stream trigger | 107 // of destructors at program exit. Let the person who sets the stream trigger |
94 // cleanup by setting to NULL, or let it leak (safe at program exit). | 108 // cleanup by setting to NULL, or let it leak (safe at program exit). |
95 LogMessage::StreamList LogMessage::streams_ GUARDED_BY(LogMessage::crit_); | 109 LogMessage::StreamList LogMessage::streams_ GUARDED_BY(LogMessage::crit_); |
96 | 110 |
(...skipping 12 matching lines...) Expand all Loading... | |
109 print_stream_ << "[" << std::setfill('0') << std::setw(3) << (time / 1000) | 123 print_stream_ << "[" << std::setfill('0') << std::setw(3) << (time / 1000) |
110 << ":" << std::setw(3) << (time % 1000) << std::setfill(' ') | 124 << ":" << std::setw(3) << (time % 1000) << std::setfill(' ') |
111 << "] "; | 125 << "] "; |
112 } | 126 } |
113 | 127 |
114 if (thread_) { | 128 if (thread_) { |
115 PlatformThreadId id = CurrentThreadId(); | 129 PlatformThreadId id = CurrentThreadId(); |
116 print_stream_ << "[" << std::dec << id << "] "; | 130 print_stream_ << "[" << std::dec << id << "] "; |
117 } | 131 } |
118 | 132 |
133 print_stream_ << "(" << FilenameFromPath(file) << ":" << line << "): "; | |
134 | |
119 if (err_ctx != ERRCTX_NONE) { | 135 if (err_ctx != ERRCTX_NONE) { |
120 std::ostringstream tmp; | 136 std::ostringstream tmp; |
121 tmp << "[0x" << std::setfill('0') << std::hex << std::setw(8) << err << "]"; | 137 tmp << "[0x" << std::setfill('0') << std::hex << std::setw(8) << err << "]"; |
122 switch (err_ctx) { | 138 switch (err_ctx) { |
123 case ERRCTX_ERRNO: | 139 case ERRCTX_ERRNO: |
124 tmp << " " << strerror(err); | 140 tmp << " " << strerror(err); |
125 break; | 141 break; |
126 #if WEBRTC_WIN | 142 #if WEBRTC_WIN |
127 case ERRCTX_HRESULT: { | 143 case ERRCTX_HRESULT: { |
128 char msgbuf[256]; | 144 char msgbuf[256]; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 void LogMessage::LogTimestamps(bool on) { | 223 void LogMessage::LogTimestamps(bool on) { |
208 timestamp_ = on; | 224 timestamp_ = on; |
209 } | 225 } |
210 | 226 |
211 void LogMessage::LogToDebug(LoggingSeverity min_sev) { | 227 void LogMessage::LogToDebug(LoggingSeverity min_sev) { |
212 dbg_sev_ = min_sev; | 228 dbg_sev_ = min_sev; |
213 CritScope cs(&crit_); | 229 CritScope cs(&crit_); |
214 UpdateMinLogSeverity(); | 230 UpdateMinLogSeverity(); |
215 } | 231 } |
216 | 232 |
233 void LogMessage::SetLogToStderr(bool log_to_stderr) { | |
234 log_to_stderr_ = log_to_stderr; | |
Andrew MacDonald
2015/09/05 05:32:18
My intuition is to protect this with the mutex, bu
hlundin-webrtc
2015/09/06 10:10:44
Acknowledged.
| |
235 } | |
236 | |
217 int LogMessage::GetLogToStream(LogSink* stream) { | 237 int LogMessage::GetLogToStream(LogSink* stream) { |
218 CritScope cs(&crit_); | 238 CritScope cs(&crit_); |
219 LoggingSeverity sev = LS_NONE; | 239 LoggingSeverity sev = LS_NONE; |
220 for (StreamList::iterator it = streams_.begin(); it != streams_.end(); ++it) { | 240 for (StreamList::iterator it = streams_.begin(); it != streams_.end(); ++it) { |
221 if (!stream || stream == it->first) { | 241 if (!stream || stream == it->first) { |
222 sev = std::min(sev, it->second); | 242 sev = std::min(sev, it->second); |
223 } | 243 } |
224 } | 244 } |
225 return sev; | 245 return sev; |
226 } | 246 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 void LogMessage::UpdateMinLogSeverity() EXCLUSIVE_LOCKS_REQUIRED(crit_) { | 327 void LogMessage::UpdateMinLogSeverity() EXCLUSIVE_LOCKS_REQUIRED(crit_) { |
308 LoggingSeverity min_sev = dbg_sev_; | 328 LoggingSeverity min_sev = dbg_sev_; |
309 for (StreamList::iterator it = streams_.begin(); it != streams_.end(); ++it) { | 329 for (StreamList::iterator it = streams_.begin(); it != streams_.end(); ++it) { |
310 min_sev = std::min(dbg_sev_, it->second); | 330 min_sev = std::min(dbg_sev_, it->second); |
311 } | 331 } |
312 min_sev_ = min_sev; | 332 min_sev_ = min_sev; |
313 } | 333 } |
314 | 334 |
315 void LogMessage::OutputToDebug(const std::string& str, | 335 void LogMessage::OutputToDebug(const std::string& str, |
316 LoggingSeverity severity) { | 336 LoggingSeverity severity) { |
317 bool log_to_stderr = true; | 337 bool log_to_stderr = log_to_stderr_; |
318 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) && (!defined(DEBUG) || defined(N DEBUG)) | 338 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) && (!defined(DEBUG) || defined(N DEBUG)) |
319 // On the Mac, all stderr output goes to the Console log and causes clutter. | 339 // On the Mac, all stderr output goes to the Console log and causes clutter. |
320 // So in opt builds, don't log to stderr unless the user specifically sets | 340 // So in opt builds, don't log to stderr unless the user specifically sets |
321 // a preference to do so. | 341 // a preference to do so. |
322 CFStringRef key = CFStringCreateWithCString(kCFAllocatorDefault, | 342 CFStringRef key = CFStringCreateWithCString(kCFAllocatorDefault, |
323 "logToStdErr", | 343 "logToStdErr", |
324 kCFStringEncodingUTF8); | 344 kCFStringEncodingUTF8); |
325 CFStringRef domain = CFBundleGetIdentifier(CFBundleGetMainBundle()); | 345 CFStringRef domain = CFBundleGetIdentifier(CFBundleGetMainBundle()); |
326 if (key != NULL && domain != NULL) { | 346 if (key != NULL && domain != NULL) { |
327 Boolean exists_and_is_valid; | 347 Boolean exists_and_is_valid; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 } | 542 } |
523 | 543 |
524 if (state) { | 544 if (state) { |
525 state->unprintable_count_[input] = consecutive_unprintable; | 545 state->unprintable_count_[input] = consecutive_unprintable; |
526 } | 546 } |
527 } | 547 } |
528 | 548 |
529 ////////////////////////////////////////////////////////////////////// | 549 ////////////////////////////////////////////////////////////////////// |
530 | 550 |
531 } // namespace rtc | 551 } // namespace rtc |
OLD | NEW |