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. |
Tommi | 9ecdcdf | 2018-02-24 15:52:11 +0100 | [diff] [blame^] | 29 | // RTC_LOG_GLE(sev [, mod]) attempt to add a string description of the |
| 30 | // HRESULT returned by GetLastError. |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 31 | // 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] | 32 | // error. errno and associated facilities exist on both Windows and POSIX, |
| 33 | // but on Windows they only apply to the C/C++ runtime. |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 34 | // RTC_LOG_ERR(sev) is an alias for the platform's normal error system, i.e. |
| 35 | // _GLE on Windows and _ERRNO on POSIX. |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 36 | // (The above three also all have _EX versions that let you specify the error |
| 37 | // code, rather than using the last one.) |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 38 | // 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] | 39 | // specified context. |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 40 | // RTC_LOG_CHECK_LEVEL(sev) (and RTC_LOG_CHECK_LEVEL_V(sev)) can be used as a |
| 41 | // test before performing expensive or sensitive operations whose sole |
| 42 | // purpose is to output logging data at the desired level. |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 43 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 44 | #ifndef RTC_BASE_LOGGING_H_ |
| 45 | #define RTC_BASE_LOGGING_H_ |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 46 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 47 | #include <errno.h> |
mostynb | e38e4f6 | 2016-05-12 01:08:20 -0700 | [diff] [blame] | 48 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 49 | #include <list> |
| 50 | #include <sstream> |
| 51 | #include <string> |
| 52 | #include <utility> |
| 53 | |
| 54 | #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
| 55 | #include <CoreServices/CoreServices.h> |
| 56 | #endif |
| 57 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 58 | #include "rtc_base/basictypes.h" |
| 59 | #include "rtc_base/constructormagic.h" |
| 60 | #include "rtc_base/thread_annotations.h" |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 61 | |
Fredrik Solenberg | b3d7cac | 2017-11-17 15:22:37 +0100 | [diff] [blame] | 62 | #if !defined(NDEBUG) || defined(DLOG_ALWAYS_ON) |
| 63 | #define RTC_DLOG_IS_ON 1 |
| 64 | #else |
| 65 | #define RTC_DLOG_IS_ON 0 |
| 66 | #endif |
| 67 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 68 | namespace rtc { |
| 69 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 70 | #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
| 71 | // Returns a UTF8 description from an OS X Status error. |
| 72 | std::string DescriptionFromOSStatus(OSStatus err); |
| 73 | #endif |
| 74 | |
| 75 | ////////////////////////////////////////////////////////////////////// |
| 76 | |
| 77 | // Note that the non-standard LoggingSeverity aliases exist because they are |
| 78 | // still in broad use. The meanings of the levels are: |
| 79 | // LS_SENSITIVE: Information which should only be logged with the consent |
| 80 | // of the user, due to privacy concerns. |
| 81 | // LS_VERBOSE: This level is for data which we do not want to appear in the |
| 82 | // normal debug log, but should appear in diagnostic logs. |
| 83 | // LS_INFO: Chatty level used in debugging for all sorts of things, the default |
| 84 | // in debug builds. |
| 85 | // LS_WARNING: Something that may warrant investigation. |
| 86 | // LS_ERROR: Something that should not have occurred. |
| 87 | // LS_NONE: Don't log. |
| 88 | enum LoggingSeverity { |
| 89 | LS_SENSITIVE, |
| 90 | LS_VERBOSE, |
| 91 | LS_INFO, |
| 92 | LS_WARNING, |
| 93 | LS_ERROR, |
| 94 | LS_NONE, |
| 95 | INFO = LS_INFO, |
| 96 | WARNING = LS_WARNING, |
| 97 | LERROR = LS_ERROR |
| 98 | }; |
| 99 | |
| 100 | // LogErrorContext assists in interpreting the meaning of an error value. |
| 101 | enum LogErrorContext { |
| 102 | ERRCTX_NONE, |
| 103 | ERRCTX_ERRNO, // System-local errno |
| 104 | ERRCTX_HRESULT, // Windows HRESULT |
| 105 | ERRCTX_OSSTATUS, // MacOS OSStatus |
| 106 | |
| 107 | // Abbreviations for LOG_E macro |
| 108 | ERRCTX_EN = ERRCTX_ERRNO, // LOG_E(sev, EN, x) |
| 109 | ERRCTX_HR = ERRCTX_HRESULT, // LOG_E(sev, HR, x) |
| 110 | ERRCTX_OS = ERRCTX_OSSTATUS, // LOG_E(sev, OS, x) |
| 111 | }; |
| 112 | |
| 113 | // Virtual sink interface that can receive log messages. |
| 114 | class LogSink { |
| 115 | public: |
| 116 | LogSink() {} |
| 117 | virtual ~LogSink() {} |
| 118 | virtual void OnLogMessage(const std::string& message) = 0; |
| 119 | }; |
| 120 | |
| 121 | class LogMessage { |
| 122 | public: |
| 123 | LogMessage(const char* file, |
| 124 | int line, |
| 125 | LoggingSeverity sev, |
| 126 | LogErrorContext err_ctx = ERRCTX_NONE, |
Tommi | 9ecdcdf | 2018-02-24 15:52:11 +0100 | [diff] [blame^] | 127 | int err = 0); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 128 | |
Tommi | 9ecdcdf | 2018-02-24 15:52:11 +0100 | [diff] [blame^] | 129 | #if defined(WEBRTC_ANDROID) |
| 130 | LogMessage(const char* file, int line, LoggingSeverity sev, const char* tag); |
| 131 | #endif |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 132 | |
| 133 | ~LogMessage(); |
| 134 | |
Jonas Olsson | 2b6f135 | 2018-02-15 11:57:03 +0100 | [diff] [blame] | 135 | static bool Loggable(LoggingSeverity sev); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 136 | std::ostream& stream() { return print_stream_; } |
| 137 | |
| 138 | // Returns the time at which this function was called for the first time. |
| 139 | // The time will be used as the logging start time. |
| 140 | // If this is not called externally, the LogMessage ctor also calls it, in |
| 141 | // which case the logging start time will be the time of the first LogMessage |
| 142 | // instance is created. |
| 143 | static int64_t LogStartTime(); |
| 144 | |
| 145 | // Returns the wall clock equivalent of |LogStartTime|, in seconds from the |
| 146 | // epoch. |
| 147 | static uint32_t WallClockStartTime(); |
| 148 | |
| 149 | // LogThreads: Display the thread identifier of the current thread |
| 150 | static void LogThreads(bool on = true); |
| 151 | |
| 152 | // LogTimestamps: Display the elapsed time of the program |
| 153 | static void LogTimestamps(bool on = true); |
| 154 | |
| 155 | // These are the available logging channels |
| 156 | // Debug: Debug console on Windows, otherwise stderr |
| 157 | static void LogToDebug(LoggingSeverity min_sev); |
Jonas Olsson | 2b6f135 | 2018-02-15 11:57:03 +0100 | [diff] [blame] | 158 | static LoggingSeverity GetLogToDebug(); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 159 | |
| 160 | // Sets whether logs will be directed to stderr in debug mode. |
| 161 | static void SetLogToStderr(bool log_to_stderr); |
| 162 | |
| 163 | // Stream: Any non-blocking stream interface. LogMessage takes ownership of |
| 164 | // the stream. Multiple streams may be specified by using AddLogToStream. |
| 165 | // LogToStream is retained for backwards compatibility; when invoked, it |
| 166 | // will discard any previously set streams and install the specified stream. |
| 167 | // GetLogToStream gets the severity for the specified stream, of if none |
| 168 | // is specified, the minimum stream severity. |
| 169 | // RemoveLogToStream removes the specified stream, without destroying it. |
| 170 | static int GetLogToStream(LogSink* stream = nullptr); |
| 171 | static void AddLogToStream(LogSink* stream, LoggingSeverity min_sev); |
| 172 | static void RemoveLogToStream(LogSink* stream); |
| 173 | |
| 174 | // Testing against MinLogSeverity allows code to avoid potentially expensive |
| 175 | // logging operations by pre-checking the logging level. |
Jonas Olsson | 2b6f135 | 2018-02-15 11:57:03 +0100 | [diff] [blame] | 176 | static int GetMinLogSeverity(); |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 177 | |
| 178 | // Parses the provided parameter stream to configure the options above. |
| 179 | // Useful for configuring logging from the command line. |
| 180 | static void ConfigureLogging(const char* params); |
| 181 | |
| 182 | private: |
| 183 | typedef std::pair<LogSink*, LoggingSeverity> StreamAndSeverity; |
| 184 | typedef std::list<StreamAndSeverity> StreamList; |
| 185 | |
| 186 | // Updates min_sev_ appropriately when debug sinks change. |
| 187 | static void UpdateMinLogSeverity(); |
| 188 | |
| 189 | // These write out the actual log messages. |
Tommi | 9ecdcdf | 2018-02-24 15:52:11 +0100 | [diff] [blame^] | 190 | #if defined(WEBRTC_ANDROID) |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 191 | static void OutputToDebug(const std::string& msg, |
| 192 | LoggingSeverity severity, |
Tommi | 9ecdcdf | 2018-02-24 15:52:11 +0100 | [diff] [blame^] | 193 | const char* tag); |
| 194 | #else |
| 195 | static void OutputToDebug(const std::string& msg, LoggingSeverity severity); |
| 196 | #endif |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 197 | |
| 198 | // The ostream that buffers the formatted message before output |
| 199 | std::ostringstream print_stream_; |
| 200 | |
| 201 | // The severity level of this message |
| 202 | LoggingSeverity severity_; |
| 203 | |
Tommi | 9ecdcdf | 2018-02-24 15:52:11 +0100 | [diff] [blame^] | 204 | #if defined(WEBRTC_ANDROID) |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 205 | // The Android debug output tag. |
Tommi | 9ecdcdf | 2018-02-24 15:52:11 +0100 | [diff] [blame^] | 206 | const char* tag_ = "libjingle"; |
| 207 | #endif |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 208 | |
| 209 | // String data generated in the constructor, that should be appended to |
| 210 | // the message before output. |
| 211 | std::string extra_; |
| 212 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 213 | // The output streams and their associated severities |
| 214 | static StreamList streams_; |
| 215 | |
| 216 | // Flags for formatting options |
| 217 | static bool thread_, timestamp_; |
| 218 | |
| 219 | // Determines if logs will be directed to stderr in debug mode. |
| 220 | static bool log_to_stderr_; |
| 221 | |
| 222 | RTC_DISALLOW_COPY_AND_ASSIGN(LogMessage); |
| 223 | }; |
| 224 | |
| 225 | ////////////////////////////////////////////////////////////////////// |
| 226 | // Logging Helpers |
| 227 | ////////////////////////////////////////////////////////////////////// |
| 228 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 229 | // The following non-obvious technique for implementation of a |
| 230 | // conditional log stream was stolen from google3/base/logging.h. |
| 231 | |
| 232 | // This class is used to explicitly ignore values in the conditional |
| 233 | // logging macros. This avoids compiler warnings like "value computed |
| 234 | // is not used" and "statement has no effect". |
| 235 | |
| 236 | class LogMessageVoidify { |
| 237 | public: |
| 238 | LogMessageVoidify() { } |
| 239 | // This has to be an operator with a precedence lower than << but |
| 240 | // higher than ?: |
| 241 | void operator&(std::ostream&) { } |
| 242 | }; |
| 243 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 244 | #define RTC_LOG_SEVERITY_PRECONDITION(sev) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 245 | !(rtc::LogMessage::Loggable(sev)) \ |
| 246 | ? (void) 0 \ |
| 247 | : rtc::LogMessageVoidify() & |
| 248 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 249 | #define RTC_LOG(sev) \ |
| 250 | RTC_LOG_SEVERITY_PRECONDITION(rtc::sev) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 251 | rtc::LogMessage(__FILE__, __LINE__, rtc::sev).stream() |
| 252 | |
| 253 | // The _V version is for when a variable is passed in. It doesn't do the |
Jonas Olsson | 24ea822 | 2018-01-25 10:14:29 +0100 | [diff] [blame] | 254 | // namespace concatenation. |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 255 | #define RTC_LOG_V(sev) \ |
| 256 | RTC_LOG_SEVERITY_PRECONDITION(sev) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 257 | rtc::LogMessage(__FILE__, __LINE__, sev).stream() |
| 258 | |
| 259 | // The _F version prefixes the message with the current function name. |
| 260 | #if (defined(__GNUC__) && !defined(NDEBUG)) || defined(WANT_PRETTY_LOG_F) |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 261 | #define RTC_LOG_F(sev) RTC_LOG(sev) << __PRETTY_FUNCTION__ << ": " |
Patrik Höglund | c296255 | 2017-11-17 13:40:22 +0000 | [diff] [blame] | 262 | #define RTC_LOG_T_F(sev) RTC_LOG(sev) << this << ": " \ |
| 263 | << __PRETTY_FUNCTION__ << ": " |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 264 | #else |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 265 | #define RTC_LOG_F(sev) RTC_LOG(sev) << __FUNCTION__ << ": " |
Patrik Höglund | c296255 | 2017-11-17 13:40:22 +0000 | [diff] [blame] | 266 | #define RTC_LOG_T_F(sev) RTC_LOG(sev) << this << ": " << __FUNCTION__ << ": " |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 267 | #endif |
| 268 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 269 | #define RTC_LOG_CHECK_LEVEL(sev) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 270 | rtc::LogCheckLevel(rtc::sev) |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 271 | #define RTC_LOG_CHECK_LEVEL_V(sev) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 272 | rtc::LogCheckLevel(sev) |
| 273 | |
| 274 | inline bool LogCheckLevel(LoggingSeverity sev) { |
| 275 | return (LogMessage::GetMinLogSeverity() <= sev); |
| 276 | } |
| 277 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 278 | #define RTC_LOG_E(sev, ctx, err, ...) \ |
| 279 | RTC_LOG_SEVERITY_PRECONDITION(rtc::sev) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 280 | rtc::LogMessage(__FILE__, __LINE__, rtc::sev, \ |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 281 | rtc::ERRCTX_ ## ctx, err , ##__VA_ARGS__) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 282 | .stream() |
| 283 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 284 | #define RTC_LOG_T(sev) RTC_LOG(sev) << this << ": " |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 285 | |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 286 | #define RTC_LOG_ERRNO_EX(sev, err) \ |
| 287 | RTC_LOG_E(sev, ERRNO, err) |
| 288 | #define RTC_LOG_ERRNO(sev) \ |
| 289 | RTC_LOG_ERRNO_EX(sev, errno) |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 290 | |
| 291 | #if defined(WEBRTC_WIN) |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 292 | #define RTC_LOG_GLE_EX(sev, err) \ |
| 293 | RTC_LOG_E(sev, HRESULT, err) |
| 294 | #define RTC_LOG_GLE(sev) \ |
| 295 | RTC_LOG_GLE_EX(sev, GetLastError()) |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 296 | #define RTC_LOG_ERR_EX(sev, err) \ |
| 297 | RTC_LOG_GLE_EX(sev, err) |
| 298 | #define RTC_LOG_ERR(sev) \ |
| 299 | RTC_LOG_GLE(sev) |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 300 | #elif defined(__native_client__) && __native_client__ |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 301 | #define RTC_LOG_ERR_EX(sev, err) \ |
| 302 | RTC_LOG(sev) |
| 303 | #define RTC_LOG_ERR(sev) \ |
| 304 | RTC_LOG(sev) |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 305 | #elif defined(WEBRTC_POSIX) |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 306 | #define RTC_LOG_ERR_EX(sev, err) \ |
| 307 | RTC_LOG_ERRNO_EX(sev, err) |
| 308 | #define RTC_LOG_ERR(sev) \ |
| 309 | RTC_LOG_ERRNO(sev) |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 310 | #endif // WEBRTC_WIN |
| 311 | |
Tommi | 9ecdcdf | 2018-02-24 15:52:11 +0100 | [diff] [blame^] | 312 | #if defined(WEBRTC_ANDROID) |
Mirko Bonadei | 8ed8e56 | 2017-10-27 09:43:53 +0200 | [diff] [blame] | 313 | #define RTC_LOG_TAG(sev, tag) \ |
| 314 | RTC_LOG_SEVERITY_PRECONDITION(sev) \ |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 315 | rtc::LogMessage(nullptr, 0, sev, tag).stream() |
Tommi | 9ecdcdf | 2018-02-24 15:52:11 +0100 | [diff] [blame^] | 316 | #endif |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 317 | |
Fredrik Solenberg | b3d7cac | 2017-11-17 15:22:37 +0100 | [diff] [blame] | 318 | // The RTC_DLOG macros are equivalent to their RTC_LOG counterparts except that |
| 319 | // they only generate code in debug builds. |
| 320 | #if RTC_DLOG_IS_ON |
| 321 | #define RTC_DLOG(sev) RTC_LOG(sev) |
| 322 | #define RTC_DLOG_V(sev) RTC_LOG_V(sev) |
| 323 | #define RTC_DLOG_F(sev) RTC_LOG_F(sev) |
| 324 | #else |
| 325 | #define RTC_DLOG_EAT_STREAM_PARAMS(sev) \ |
Jonas Olsson | 24ea822 | 2018-01-25 10:14:29 +0100 | [diff] [blame] | 326 | (true ? true : ((void)(sev), true)) \ |
| 327 | ? static_cast<void>(0) \ |
| 328 | : rtc::LogMessageVoidify() & \ |
| 329 | rtc::LogMessage(__FILE__, __LINE__, sev).stream() |
| 330 | #define RTC_DLOG(sev) RTC_DLOG_EAT_STREAM_PARAMS(rtc::sev) |
Fredrik Solenberg | b3d7cac | 2017-11-17 15:22:37 +0100 | [diff] [blame] | 331 | #define RTC_DLOG_V(sev) RTC_DLOG_EAT_STREAM_PARAMS(sev) |
Jonas Olsson | 24ea822 | 2018-01-25 10:14:29 +0100 | [diff] [blame] | 332 | #define RTC_DLOG_F(sev) RTC_DLOG_EAT_STREAM_PARAMS(rtc::sev) |
Fredrik Solenberg | b3d7cac | 2017-11-17 15:22:37 +0100 | [diff] [blame] | 333 | #endif |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 334 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 335 | } // namespace rtc |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 336 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 337 | #endif // RTC_BASE_LOGGING_H_ |