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