henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 11 | // RTC_LOG(...) an ostream target that can be used to send formatted |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 12 | // output to a variety of logging targets, such as debugger console, stderr, |
Tommi | 0eefb4d | 2015-05-23 09:54:07 +0200 | [diff] [blame] | 13 | // or any LogSink. |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 14 | // The severity level passed as the first argument to the logging |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 15 | // functions is used as a filter, to limit the verbosity of the logging. |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 16 | // Static members of LogMessage documented below are used to control the |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 17 | // verbosity and target of the output. |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 18 | // There are several variations on the RTC_LOG macro which facilitate logging |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 19 | // of common error conditions, detailed below. |
| 20 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 21 | // RTC_LOG(sev) logs the given stream at severity "sev", which must be a |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 22 | // compile-time constant of the LoggingSeverity type, without the namespace |
| 23 | // prefix. |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 24 | // RTC_LOG_V(sev) Like RTC_LOG(), but sev is a run-time variable of the |
| 25 | // LoggingSeverity type (basically, it just doesn't prepend the namespace). |
| 26 | // RTC_LOG_F(sev) Like RTC_LOG(), but includes the name of the current function. |
| 27 | // RTC_LOG_T(sev) Like RTC_LOG(), but includes the this pointer. |
| 28 | // RTC_LOG_T_F(sev) Like RTC_LOG_F(), but includes the this pointer. |
| 29 | // RTC_LOG_GLE(M)(sev [, mod]) attempt to add a string description of the |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 30 | // HRESULT returned by GetLastError. The "M" variant allows searching of a |
| 31 | // DLL's string table for the error description. |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 32 | // RTC_LOG_ERRNO(sev) attempts to add a string description of an errno-derived |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 33 | // error. errno and associated facilities exist on both Windows and POSIX, |
| 34 | // but on Windows they only apply to the C/C++ runtime. |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 35 | // RTC_LOG_ERR(sev) is an alias for the platform's normal error system, i.e. |
| 36 | // _GLE on Windows and _ERRNO on POSIX. |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 37 | // (The above three also all have _EX versions that let you specify the error |
| 38 | // code, rather than using the last one.) |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 39 | // RTC_LOG_E(sev, ctx, err, ...) logs a detailed error interpreted using the |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 40 | // specified context. |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 41 | // RTC_LOG_CHECK_LEVEL(sev) (and RTC_LOG_CHECK_LEVEL_V(sev)) can be used as a |
| 42 | // test before performing expensive or sensitive operations whose sole |
| 43 | // purpose is to output logging data at the desired level. |
| 44 | // Lastly, RTC_PLOG(sev, err) is an alias for RTC_LOG_ERR_EX. |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 45 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 46 | #ifndef RTC_BASE_LOGGING_H_ |
| 47 | #define RTC_BASE_LOGGING_H_ |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 48 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 49 | #include <errno.h> |
mostynb | e38e4f6 | 2016-05-12 01:08:20 -0700 | [diff] [blame] | 50 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 51 | #include <list> |
| 52 | #include <sstream> |
| 53 | #include <string> |
| 54 | #include <utility> |
| 55 | |
| 56 | #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
| 57 | #include <CoreServices/CoreServices.h> |
| 58 | #endif |
| 59 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 60 | #include "rtc_base/basictypes.h" |
| 61 | #include "rtc_base/constructormagic.h" |
| 62 | #include "rtc_base/thread_annotations.h" |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 63 | |
| 64 | namespace rtc { |
| 65 | |
| 66 | /////////////////////////////////////////////////////////////////////////////// |
| 67 | // ConstantLabel can be used to easily generate string names from constant |
| 68 | // values. This can be useful for logging descriptive names of error messages. |
| 69 | // Usage: |
| 70 | // const ConstantLabel LIBRARY_ERRORS[] = { |
| 71 | // KLABEL(SOME_ERROR), |
| 72 | // KLABEL(SOME_OTHER_ERROR), |
| 73 | // ... |
| 74 | // LASTLABEL |
| 75 | // } |
| 76 | // |
| 77 | // int err = LibraryFunc(); |
| 78 | // LOG(LS_ERROR) << "LibraryFunc returned: " |
| 79 | // << ErrorName(err, LIBRARY_ERRORS); |
| 80 | |
| 81 | struct ConstantLabel { int value; const char * label; }; |
| 82 | #define KLABEL(x) { x, #x } |
| 83 | #define TLABEL(x, y) { x, y } |
| 84 | #define LASTLABEL { 0, 0 } |
| 85 | |
| 86 | const char* FindLabel(int value, const ConstantLabel entries[]); |
| 87 | std::string ErrorName(int err, const ConstantLabel* err_table); |
| 88 | |
| 89 | #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
| 90 | // Returns a UTF8 description from an OS X Status error. |
| 91 | std::string DescriptionFromOSStatus(OSStatus err); |
| 92 | #endif |
| 93 | |
| 94 | ////////////////////////////////////////////////////////////////////// |
| 95 | |
| 96 | // Note that the non-standard LoggingSeverity aliases exist because they are |
| 97 | // still in broad use. The meanings of the levels are: |
| 98 | // LS_SENSITIVE: Information which should only be logged with the consent |
| 99 | // of the user, due to privacy concerns. |
| 100 | // LS_VERBOSE: This level is for data which we do not want to appear in the |
| 101 | // normal debug log, but should appear in diagnostic logs. |
| 102 | // LS_INFO: Chatty level used in debugging for all sorts of things, the default |
| 103 | // in debug builds. |
| 104 | // LS_WARNING: Something that may warrant investigation. |
| 105 | // LS_ERROR: Something that should not have occurred. |
| 106 | // LS_NONE: Don't log. |
| 107 | enum LoggingSeverity { |
| 108 | LS_SENSITIVE, |
| 109 | LS_VERBOSE, |
| 110 | LS_INFO, |
| 111 | LS_WARNING, |
| 112 | LS_ERROR, |
| 113 | LS_NONE, |
| 114 | INFO = LS_INFO, |
| 115 | WARNING = LS_WARNING, |
| 116 | LERROR = LS_ERROR |
| 117 | }; |
| 118 | |
| 119 | // LogErrorContext assists in interpreting the meaning of an error value. |
| 120 | enum LogErrorContext { |
| 121 | ERRCTX_NONE, |
| 122 | ERRCTX_ERRNO, // System-local errno |
| 123 | ERRCTX_HRESULT, // Windows HRESULT |
| 124 | ERRCTX_OSSTATUS, // MacOS OSStatus |
| 125 | |
| 126 | // Abbreviations for LOG_E macro |
| 127 | ERRCTX_EN = ERRCTX_ERRNO, // LOG_E(sev, EN, x) |
| 128 | ERRCTX_HR = ERRCTX_HRESULT, // LOG_E(sev, HR, x) |
| 129 | ERRCTX_OS = ERRCTX_OSSTATUS, // LOG_E(sev, OS, x) |
| 130 | }; |
| 131 | |
| 132 | // Virtual sink interface that can receive log messages. |
| 133 | class LogSink { |
| 134 | public: |
| 135 | LogSink() {} |
| 136 | virtual ~LogSink() {} |
| 137 | virtual void OnLogMessage(const std::string& message) = 0; |
| 138 | }; |
| 139 | |
| 140 | class LogMessage { |
| 141 | public: |
| 142 | LogMessage(const char* file, |
| 143 | int line, |
| 144 | LoggingSeverity sev, |
| 145 | LogErrorContext err_ctx = ERRCTX_NONE, |
| 146 | int err = 0, |
| 147 | const char* module = nullptr); |
| 148 | |
| 149 | LogMessage(const char* file, |
| 150 | int line, |
| 151 | LoggingSeverity sev, |
| 152 | const std::string& tag); |
| 153 | |
| 154 | ~LogMessage(); |
| 155 | |
| 156 | static inline bool Loggable(LoggingSeverity sev) { return (sev >= min_sev_); } |
| 157 | std::ostream& stream() { return print_stream_; } |
| 158 | |
| 159 | // Returns the time at which this function was called for the first time. |
| 160 | // The time will be used as the logging start time. |
| 161 | // If this is not called externally, the LogMessage ctor also calls it, in |
| 162 | // which case the logging start time will be the time of the first LogMessage |
| 163 | // instance is created. |
| 164 | static int64_t LogStartTime(); |
| 165 | |
| 166 | // Returns the wall clock equivalent of |LogStartTime|, in seconds from the |
| 167 | // epoch. |
| 168 | static uint32_t WallClockStartTime(); |
| 169 | |
| 170 | // LogThreads: Display the thread identifier of the current thread |
| 171 | static void LogThreads(bool on = true); |
| 172 | |
| 173 | // LogTimestamps: Display the elapsed time of the program |
| 174 | static void LogTimestamps(bool on = true); |
| 175 | |
| 176 | // These are the available logging channels |
| 177 | // Debug: Debug console on Windows, otherwise stderr |
| 178 | static void LogToDebug(LoggingSeverity min_sev); |
| 179 | static LoggingSeverity GetLogToDebug() { return dbg_sev_; } |
| 180 | |
| 181 | // Sets whether logs will be directed to stderr in debug mode. |
| 182 | static void SetLogToStderr(bool log_to_stderr); |
| 183 | |
| 184 | // Stream: Any non-blocking stream interface. LogMessage takes ownership of |
| 185 | // the stream. Multiple streams may be specified by using AddLogToStream. |
| 186 | // LogToStream is retained for backwards compatibility; when invoked, it |
| 187 | // will discard any previously set streams and install the specified stream. |
| 188 | // GetLogToStream gets the severity for the specified stream, of if none |
| 189 | // is specified, the minimum stream severity. |
| 190 | // RemoveLogToStream removes the specified stream, without destroying it. |
| 191 | static int GetLogToStream(LogSink* stream = nullptr); |
| 192 | static void AddLogToStream(LogSink* stream, LoggingSeverity min_sev); |
| 193 | static void RemoveLogToStream(LogSink* stream); |
| 194 | |
| 195 | // Testing against MinLogSeverity allows code to avoid potentially expensive |
| 196 | // logging operations by pre-checking the logging level. |
| 197 | static int GetMinLogSeverity() { return min_sev_; } |
| 198 | |
| 199 | // Parses the provided parameter stream to configure the options above. |
| 200 | // Useful for configuring logging from the command line. |
| 201 | static void ConfigureLogging(const char* params); |
| 202 | |
| 203 | private: |
| 204 | typedef std::pair<LogSink*, LoggingSeverity> StreamAndSeverity; |
| 205 | typedef std::list<StreamAndSeverity> StreamList; |
| 206 | |
| 207 | // Updates min_sev_ appropriately when debug sinks change. |
| 208 | static void UpdateMinLogSeverity(); |
| 209 | |
| 210 | // These write out the actual log messages. |
| 211 | static void OutputToDebug(const std::string& msg, |
| 212 | LoggingSeverity severity, |
| 213 | const std::string& tag); |
| 214 | |
| 215 | // The ostream that buffers the formatted message before output |
| 216 | std::ostringstream print_stream_; |
| 217 | |
| 218 | // The severity level of this message |
| 219 | LoggingSeverity severity_; |
| 220 | |
| 221 | // The Android debug output tag. |
| 222 | std::string tag_; |
| 223 | |
| 224 | // String data generated in the constructor, that should be appended to |
| 225 | // the message before output. |
| 226 | std::string extra_; |
| 227 | |
| 228 | // dbg_sev_ is the thresholds for those output targets |
| 229 | // min_sev_ is the minimum (most verbose) of those levels, and is used |
| 230 | // as a short-circuit in the logging macros to identify messages that won't |
| 231 | // be logged. |
| 232 | // ctx_sev_ is the minimum level at which file context is displayed |
| 233 | static LoggingSeverity min_sev_, dbg_sev_, ctx_sev_; |
| 234 | |
| 235 | // The output streams and their associated severities |
| 236 | static StreamList streams_; |
| 237 | |
| 238 | // Flags for formatting options |
| 239 | static bool thread_, timestamp_; |
| 240 | |
| 241 | // Determines if logs will be directed to stderr in debug mode. |
| 242 | static bool log_to_stderr_; |
| 243 | |
| 244 | RTC_DISALLOW_COPY_AND_ASSIGN(LogMessage); |
| 245 | }; |
| 246 | |
| 247 | ////////////////////////////////////////////////////////////////////// |
| 248 | // Logging Helpers |
| 249 | ////////////////////////////////////////////////////////////////////// |
| 250 | |
| 251 | class LogMultilineState { |
| 252 | public: |
| 253 | size_t unprintable_count_[2]; |
| 254 | LogMultilineState() { |
| 255 | unprintable_count_[0] = unprintable_count_[1] = 0; |
| 256 | } |
| 257 | }; |
| 258 | |
| 259 | // When possible, pass optional state variable to track various data across |
| 260 | // multiple calls to LogMultiline. Otherwise, pass null. |
| 261 | void LogMultiline(LoggingSeverity level, const char* label, bool input, |
| 262 | const void* data, size_t len, bool hex_mode, |
| 263 | LogMultilineState* state); |
| 264 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 265 | // The following non-obvious technique for implementation of a |
| 266 | // conditional log stream was stolen from google3/base/logging.h. |
| 267 | |
| 268 | // This class is used to explicitly ignore values in the conditional |
| 269 | // logging macros. This avoids compiler warnings like "value computed |
| 270 | // is not used" and "statement has no effect". |
| 271 | |
| 272 | class LogMessageVoidify { |
| 273 | public: |
| 274 | LogMessageVoidify() { } |
| 275 | // This has to be an operator with a precedence lower than << but |
| 276 | // higher than ?: |
| 277 | void operator&(std::ostream&) { } |
| 278 | }; |
| 279 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 280 | #define RTC_LOG_SEVERITY_PRECONDITION(sev) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 281 | !(rtc::LogMessage::Loggable(sev)) \ |
| 282 | ? (void) 0 \ |
| 283 | : rtc::LogMessageVoidify() & |
| 284 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 285 | #define RTC_LOG(sev) \ |
| 286 | RTC_LOG_SEVERITY_PRECONDITION(rtc::sev) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 287 | rtc::LogMessage(__FILE__, __LINE__, rtc::sev).stream() |
| 288 | |
| 289 | // The _V version is for when a variable is passed in. It doesn't do the |
| 290 | // namespace concatination. |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 291 | #define RTC_LOG_V(sev) \ |
| 292 | RTC_LOG_SEVERITY_PRECONDITION(sev) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 293 | rtc::LogMessage(__FILE__, __LINE__, sev).stream() |
| 294 | |
| 295 | // The _F version prefixes the message with the current function name. |
| 296 | #if (defined(__GNUC__) && !defined(NDEBUG)) || defined(WANT_PRETTY_LOG_F) |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 297 | #define RTC_LOG_F(sev) RTC_LOG(sev) << __PRETTY_FUNCTION__ << ": " |
| 298 | #define RTC_LOG_T_F(sev) RTC_LOG(sev) << this << ": " \ |
| 299 | << __PRETTY_FUNCTION__ << ": " |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 300 | #else |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 301 | #define RTC_LOG_F(sev) RTC_LOG(sev) << __FUNCTION__ << ": " |
| 302 | #define RTC_LOG_T_F(sev) RTC_LOG(sev) << this << ": " << __FUNCTION__ << ": " |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 303 | #endif |
| 304 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 305 | #define RTC_LOG_CHECK_LEVEL(sev) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 306 | rtc::LogCheckLevel(rtc::sev) |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 307 | #define RTC_LOG_CHECK_LEVEL_V(sev) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 308 | rtc::LogCheckLevel(sev) |
| 309 | |
| 310 | inline bool LogCheckLevel(LoggingSeverity sev) { |
| 311 | return (LogMessage::GetMinLogSeverity() <= sev); |
| 312 | } |
| 313 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 314 | #define RTC_LOG_E(sev, ctx, err, ...) \ |
| 315 | RTC_LOG_SEVERITY_PRECONDITION(rtc::sev) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 316 | rtc::LogMessage(__FILE__, __LINE__, rtc::sev, \ |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 317 | rtc::ERRCTX_ ## ctx, err , ##__VA_ARGS__) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 318 | .stream() |
| 319 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 320 | #define RTC_LOG_T(sev) RTC_LOG(sev) << this << ": " |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 321 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 322 | #define RTC_LOG_ERRNO_EX(sev, err) \ |
| 323 | RTC_LOG_E(sev, ERRNO, err) |
| 324 | #define RTC_LOG_ERRNO(sev) \ |
| 325 | RTC_LOG_ERRNO_EX(sev, errno) |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 326 | |
| 327 | #if defined(WEBRTC_WIN) |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 328 | #define RTC_LOG_GLE_EX(sev, err) \ |
| 329 | RTC_LOG_E(sev, HRESULT, err) |
| 330 | #define RTC_LOG_GLE(sev) \ |
| 331 | RTC_LOG_GLE_EX(sev, GetLastError()) |
| 332 | #define RTC_LOG_GLEM(sev, mod) \ |
| 333 | RTC_LOG_E(sev, HRESULT, GetLastError(), mod) |
| 334 | #define RTC_LOG_ERR_EX(sev, err) \ |
| 335 | RTC_LOG_GLE_EX(sev, err) |
| 336 | #define RTC_LOG_ERR(sev) \ |
| 337 | RTC_LOG_GLE(sev) |
| 338 | #define RTC_LAST_SYSTEM_ERROR \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 339 | (::GetLastError()) |
| 340 | #elif defined(__native_client__) && __native_client__ |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 341 | #define RTC_LOG_ERR_EX(sev, err) \ |
| 342 | RTC_LOG(sev) |
| 343 | #define RTC_LOG_ERR(sev) \ |
| 344 | RTC_LOG(sev) |
| 345 | #define RTC_LAST_SYSTEM_ERROR \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 346 | (0) |
| 347 | #elif defined(WEBRTC_POSIX) |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 348 | #define RTC_LOG_ERR_EX(sev, err) \ |
| 349 | RTC_LOG_ERRNO_EX(sev, err) |
| 350 | #define RTC_LOG_ERR(sev) \ |
| 351 | RTC_LOG_ERRNO(sev) |
| 352 | #define RTC_LAST_SYSTEM_ERROR \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 353 | (errno) |
| 354 | #endif // WEBRTC_WIN |
| 355 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 356 | #define RTC_LOG_TAG(sev, tag) \ |
| 357 | RTC_LOG_SEVERITY_PRECONDITION(sev) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 358 | rtc::LogMessage(nullptr, 0, sev, tag).stream() |
| 359 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 360 | #define RTC_PLOG(sev, err) \ |
| 361 | RTC_LOG_ERR_EX(sev, err) |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 362 | |
| 363 | // TODO(?): Add an "assert" wrapper that logs in the same manner. |
| 364 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 365 | // TODO(bugs.webrtc.org/8452): Remove these backwards compatibility wrappers. |
| 366 | #ifndef LOG |
| 367 | |
| 368 | #define LOG(sev) RTC_LOG(sev) |
| 369 | #define LOG_V(sev) RTC_LOG_V(sev) |
| 370 | #define LOG_F(sev) RTC_LOG_F(sev) |
| 371 | #define LOG_T_F(sev) RTC_LOG_T_F(sev) |
| 372 | #define LOG_CHECK_LEVEL(sev) RTC_LOG_CHECK_LEVEL(sev) |
| 373 | #define LOG_CHECK_LEVEL_V(sev) RTC_LOG_CHECK_LEVEL_V(sev) |
| 374 | #define LOG_E(sev, ctx, err, ...) RTC_LOG_E(sev, ctx, err, ##__VA_ARGS__) |
| 375 | #define LOG_T(sev) RTC_LOG_T(sev) |
| 376 | #define LOG_ERRNO_EX(sev, err) RTC_LOG_ERRNO_EX(sev, err) |
| 377 | #define LOG_ERRNO(sev) RTC_LOG_ERRNO(sev) |
| 378 | |
| 379 | #define LAST_SYSTEM_ERROR RTC_LAST_SYSTEM_ERROR |
| 380 | #define LOG_ERR_EX(sev, err) RTC_LOG_ERR_EX(sev, err) |
| 381 | #define LOG_ERR(sev) RTC_LOG_ERR(sev) |
| 382 | |
| 383 | #if defined(WEBRTC_WIN) |
| 384 | #define LOG_GLE_EX(sev, err) RTC_LOG_GLE_EX(sev, err) |
| 385 | #define LOG_GLE(sev) RTC_LOG_GLE(sev) |
| 386 | #define LOG_GLEM(sev, mod) RTC_LOG_GLEM(sev, mod) |
| 387 | #endif // WEBRTC_WIN |
| 388 | |
| 389 | #define LOG_TAG(sev, tag) RTC_LOG_TAG(sev, tag) |
| 390 | #define PLOG(sev, err) RTC_PLOG(sev, err) |
| 391 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 392 | #endif // LOG |
| 393 | |
| 394 | } // namespace rtc |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 395 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 396 | #endif // RTC_BASE_LOGGING_H_ |