Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 * libjingle | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 * Copyright 2004--2005, Google Inc. | 3 // found in the LICENSE file. |
| 4 * | |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | |
| 9 * this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
| 11 * this list of conditions and the following disclaimer in the documentation | |
| 12 * and/or other materials provided with the distribution. | |
| 13 * 3. The name of the author may not be used to endorse or promote products | |
| 14 * derived from this software without specific prior written permission. | |
| 15 * | |
| 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
| 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
| 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
| 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
| 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
| 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
| 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 26 */ | |
| 27 | 4 |
| 28 // LOG(...) an ostream target that can be used to send formatted | 5 // This file overrides the logging macros in libjingle (talk/base/logging.h). |
| 29 // output to a variety of logging targets, such as debugger console, stderr, | 6 // Instead of using libjingle's logging implementation, the libjingle macros are |
| 30 // file, or any StreamInterface. | 7 // mapped to the corresponding base/logging.h macro (chromium's VLOG). |
| 31 // The severity level passed as the first argument to the the LOGging | 8 // If this file is included outside of libjingle (e.g. in wrapper code) it |
| 32 // functions is used as a filter, to limit the verbosity of the logging. | 9 // should be included after base/logging.h (if any) or compiler error or |
| 33 // Static members of LogMessage documented below are used to control the | 10 // unexpected behavior may occur (macros that have the same name in libjingle as |
| 34 // verbosity and target of the output. | 11 // in chromium will use the libjingle definition if this file is included |
| 35 // There are several variations on the LOG macro which facilitate logging | 12 // first). |
| 36 // of common error conditions, detailed below. | |
| 37 | 13 |
| 38 // LOG(sev) logs the given stream at severity "sev", which must be a | 14 // Setting the LoggingSeverity (and lower) that should be written to file should |
| 39 // compile-time constant of the LoggingSeverity type, without the namespace | 15 // be done via command line by specifying the flags: |
| 40 // prefix. | 16 // --vmodule or --v please see base/logging.h for details on how to use them. |
| 41 // LOG_V(sev) Like LOG(), but sev is a run-time variable of the LoggingSeverity | 17 // Specifying what file to write to is done using InitLogging also in |
| 42 // type (basically, it just doesn't prepend the namespace). | 18 // base/logging.h. |
| 43 // LOG_F(sev) Like LOG(), but includes the name of the current function. | |
| 44 // LOG_GLE(M)(sev [, mod]) attempt to add a string description of the | |
| 45 // HRESULT returned by GetLastError. The "M" variant allows searching of a | |
| 46 // DLL's string table for the error description. | |
| 47 // LOG_ERRNO(sev) attempts to add a string description of an errno-derived | |
| 48 // error. errno and associated facilities exist on both Windows and POSIX, | |
| 49 // but on Windows they only apply to the C/C++ runtime. | |
| 50 // LOG_ERR(sev) is an alias for the platform's normal error system, i.e. _GLE on | |
| 51 // Windows and _ERRNO on POSIX. | |
| 52 // (The above three also all have _EX versions that let you specify the error | |
| 53 // code, rather than using the last one.) | |
| 54 // LOG_E(sev, ctx, err, ...) logs a detailed error interpreted using the | |
| 55 // specified context. | |
| 56 // LOG_CHECK_LEVEL(sev) (and LOG_CHECK_LEVEL_V(sev)) can be used as a test | |
| 57 // before performing expensive or sensitive operations whose sole purpose is | |
| 58 // to output logging data at the desired level. | |
| 59 // Lastly, PLOG(sev, err) is an alias for LOG_ERR_EX. | |
| 60 | 19 |
| 61 #ifndef TALK_BASE_LOGGING_H_ | 20 // The macros and classes declared in here are not described as they are |
| 62 #define TALK_BASE_LOGGING_H_ | 21 // NOT TO BE USED outside of libjingle. |
| 22 | |
| 23 #ifndef THIRD_PARTY_LIBJINGLE_OVERRIDES_TALK_BASE_LOGGING_H_ | |
| 24 #define THIRD_PARTY_LIBJINGLE_OVERRIDES_TALK_BASE_LOGGING_H_ | |
| 25 | |
| 26 #include <sstream> | |
| 27 #include <string> | |
| 28 | |
| 29 // Note that this works inside chromium because the include order is | |
| 30 // guaranteed/required as mentioned above. | |
| 31 #ifndef BASE_LOGGING_H_ // This is the include guard for the chromium logging. | |
| 32 #define LOGGING_INSIDE_LIBJINGLE | |
|
Sergey Ulanov
2011/12/28 02:38:15
Can we define this in the gyp in the same way SAFE
hellner
2012/01/10 23:31:28
Yes, doing this is an improvement since we no long
| |
| 33 #include "base/logging.h" | |
| 34 #endif // BASE_LOGGING_H_ | |
| 63 | 35 |
| 64 #ifdef HAVE_CONFIG_H | 36 #ifdef HAVE_CONFIG_H |
| 65 #include "config.h" // NOLINT | 37 #include "config.h" // NOLINT |
| 66 #endif | 38 #endif |
| 67 | 39 |
| 68 #include <list> | |
| 69 #include <sstream> | |
| 70 #include <string> | |
| 71 #include <utility> | |
| 72 #include "talk/base/basictypes.h" | |
| 73 #include "talk/base/criticalsection.h" | |
| 74 | |
| 75 namespace talk_base { | 40 namespace talk_base { |
| 76 | 41 |
| 77 class StreamInterface; | |
| 78 | |
| 79 /////////////////////////////////////////////////////////////////////////////// | 42 /////////////////////////////////////////////////////////////////////////////// |
| 80 // ConstantLabel can be used to easily generate string names from constant | 43 // ConstantLabel can be used to easily generate string names from constant |
| 81 // values. This can be useful for logging descriptive names of error messages. | 44 // values. This can be useful for logging descriptive names of error messages. |
| 82 // Usage: | 45 // Usage: |
| 83 // const ConstantLabel LIBRARY_ERRORS[] = { | 46 // const ConstantLabel LIBRARY_ERRORS[] = { |
| 84 // KLABEL(SOME_ERROR), | 47 // KLABEL(SOME_ERROR), |
| 85 // KLABEL(SOME_OTHER_ERROR), | 48 // KLABEL(SOME_OTHER_ERROR), |
| 86 // ... | 49 // ... |
| 87 // LASTLABEL | 50 // LASTLABEL |
| 88 // } | 51 // } |
| 89 // | 52 // |
| 90 // int err = LibraryFunc(); | 53 // int err = LibraryFunc(); |
| 91 // LOG(LS_ERROR) << "LibraryFunc returned: " | 54 // LOG(LS_ERROR) << "LibraryFunc returned: " |
| 92 // << ErrorName(err, LIBRARY_ERRORS); | 55 // << ErrorName(err, LIBRARY_ERRORS); |
| 93 | 56 |
| 94 struct ConstantLabel { int value; const char * label; }; | 57 struct ConstantLabel { |
| 95 | 58 int value; |
| 96 #if defined(SAFE_TO_DEFINE_TALK_BASE_LOGGING_MACROS) | 59 const char * label; |
| 60 }; | |
| 97 #define KLABEL(x) { x, #x } | 61 #define KLABEL(x) { x, #x } |
| 98 #define TLABEL(x, y) { x, y } | 62 #define TLABEL(x, y) { x, y } |
| 99 #define LASTLABEL { 0, 0 } | 63 #define LASTLABEL { 0, 0 } |
| 100 #endif // defined(SAFE_TO_DEFINE_TALK_BASE_LOGGING_MACROS) | |
| 101 | 64 |
| 102 const char * FindLabel(int value, const ConstantLabel entries[]); | 65 const char * FindLabel(int value, const ConstantLabel entries[]); |
| 103 std::string ErrorName(int err, const ConstantLabel* err_table); | 66 std::string ErrorName(int err, const ConstantLabel* err_table); |
| 104 | 67 |
| 105 ////////////////////////////////////////////////////////////////////// | 68 ////////////////////////////////////////////////////////////////////// |
| 106 | |
| 107 // Note that the non-standard LoggingSeverity aliases exist because they are | 69 // Note that the non-standard LoggingSeverity aliases exist because they are |
| 108 // still in broad use. The meanings of the levels are: | 70 // still in broad use. The meanings of the levels are: |
| 109 // LS_SENSITIVE: Information which should only be logged with the consent | 71 // LS_SENSITIVE: Information which should only be logged with the consent |
| 110 // of the user, due to privacy concerns. | 72 // of the user, due to privacy concerns. |
| 111 // LS_VERBOSE: This level is for data which we do not want to appear in the | 73 // LS_VERBOSE: This level is for data which we do not want to appear in the |
| 112 // normal debug log, but should appear in diagnostic logs. | 74 // normal debug log, but should appear in diagnostic logs. |
| 113 // LS_INFO: Chatty level used in debugging for all sorts of things, the default | 75 // LS_INFO: Chatty level used in debugging for all sorts of things, the default |
| 114 // in debug builds. | 76 // in debug builds. |
| 115 // LS_WARNING: Something that may warrant investigation. | 77 // LS_WARNING: Something that may warrant investigation. |
| 116 // LS_ERROR: Something that should not have occurred. | 78 // LS_ERROR: Something that should not have occurred. |
| 117 enum LoggingSeverity { LS_SENSITIVE, LS_VERBOSE, LS_INFO, LS_WARNING, LS_ERROR, | 79 // Note that LoggingSeverity is mapped over to chromiums verbosity levels where |
| 80 // anything lower than or equal to the current verbosity level is written to | |
| 81 // file which is the opposite of logging severity in libjingle where higher | |
| 82 // severity numbers than or equal to the current severity level are written to | |
| 83 // file. Also, note that the values are explicitly defined here for convenience | |
| 84 // since the command line flag must be set using numerical values. | |
| 85 enum LoggingSeverity { LS_ERROR = 1, | |
| 86 LS_WARNING = 2, | |
| 87 LS_INFO = 3, | |
| 88 LS_VERBOSE = 4, | |
| 89 LS_SENSITIVE = 5, | |
| 118 INFO = LS_INFO, | 90 INFO = LS_INFO, |
| 119 WARNING = LS_WARNING, | 91 WARNING = LS_WARNING, |
| 120 LERROR = LS_ERROR }; | 92 LERROR = LS_ERROR }; |
| 121 | 93 |
| 122 // LogErrorContext assists in interpreting the meaning of an error value. | 94 // LogErrorContext assists in interpreting the meaning of an error value. |
| 123 enum LogErrorContext { | 95 enum LogErrorContext { |
| 124 ERRCTX_NONE, | 96 ERRCTX_NONE, |
| 125 ERRCTX_ERRNO, // System-local errno | 97 ERRCTX_ERRNO, // System-local errno |
| 126 ERRCTX_HRESULT, // Windows HRESULT | 98 ERRCTX_HRESULT, // Windows HRESULT |
| 127 ERRCTX_OSSTATUS, // MacOS OSStatus | 99 ERRCTX_OSSTATUS, // MacOS OSStatus |
| 128 | 100 |
| 129 // Abbreviations for LOG_E macro | 101 // Abbreviations for LOG_E macro |
| 130 ERRCTX_EN = ERRCTX_ERRNO, // LOG_E(sev, EN, x) | 102 ERRCTX_EN = ERRCTX_ERRNO, // LOG_E(sev, EN, x) |
| 131 ERRCTX_HR = ERRCTX_HRESULT, // LOG_E(sev, HR, x) | 103 ERRCTX_HR = ERRCTX_HRESULT, // LOG_E(sev, HR, x) |
| 132 ERRCTX_OS = ERRCTX_OSSTATUS, // LOG_E(sev, OS, x) | 104 ERRCTX_OS = ERRCTX_OSSTATUS, // LOG_E(sev, OS, x) |
| 133 }; | 105 }; |
| 134 | 106 |
| 135 class LogMessage { | 107 // Class that makes it possible describe a LOG_E message as a single string. |
| 108 // I.e. the format that VLOG is expecting. | |
| 109 class LogEHelper { | |
| 136 public: | 110 public: |
| 137 static const int NO_LOGGING; | 111 LogEHelper(const char* file, int line, LoggingSeverity severity, |
| 112 const std::string extra); | |
| 113 ~LogEHelper(); | |
| 138 | 114 |
| 139 LogMessage(const char* file, int line, LoggingSeverity sev, | |
| 140 LogErrorContext err_ctx = ERRCTX_NONE, int err = 0, | |
| 141 const char* module = NULL); | |
| 142 ~LogMessage(); | |
| 143 | |
| 144 static inline bool Loggable(LoggingSeverity sev) { return (sev >= min_sev_); } | |
| 145 std::ostream& stream() { return print_stream_; } | 115 std::ostream& stream() { return print_stream_; } |
| 146 | 116 |
| 147 // These are attributes which apply to all logging channels | 117 private: |
| 148 // LogContext: Display the file and line number of the message | 118 const std::string file_name_; |
| 149 static void LogContext(int min_sev); | 119 const int line_; |
| 150 // LogThreads: Display the thread identifier of the current thread | |
| 151 static void LogThreads(bool on = true); | |
| 152 // LogTimestamps: Display the elapsed time of the program | |
| 153 static void LogTimestamps(bool on = true); | |
| 154 | 120 |
| 155 // Timestamps begin with program execution, but can be reset with this | 121 const std::string extra_; |
| 156 // function for measuring the duration of an activity, or to synchronize | 122 const LoggingSeverity severity_; |
| 157 // timestamps between multiple instances. | |
| 158 static void ResetTimestamps(); | |
| 159 | 123 |
| 160 // These are the available logging channels | 124 std::ostringstream print_stream_; |
| 161 // Debug: Debug console on Windows, otherwise stderr | 125 }; |
| 162 static void LogToDebug(int min_sev); | |
| 163 static int GetLogToDebug() { return dbg_sev_; } | |
| 164 | 126 |
| 165 // Stream: Any non-blocking stream interface. LogMessage takes ownership of | 127 // This class is used to explicitly ignore values in the conditional |
| 166 // the stream. Multiple streams may be specified by using AddLogToStream. | 128 // logging macros. This avoids compiler warnings like "value computed |
| 167 // LogToStream is retained for backwards compatibility; when invoked, it | 129 // is not used" and "statement has no effect". |
| 168 // will discard any previously set streams and install the specified stream. | 130 class LogMessageVoidify { |
| 169 // GetLogToStream gets the severity for the specified stream, of if none | 131 public: |
| 170 // is specified, the minimum stream severity. | 132 LogMessageVoidify() { } |
| 171 // RemoveLogToStream removes the specified stream, without destroying it. | 133 // This has to be an operator with a precedence lower than << but |
| 172 static void LogToStream(StreamInterface* stream, int min_sev); | 134 // higher than ?: |
| 173 static int GetLogToStream(StreamInterface* stream = NULL); | 135 void operator&(std::ostream&) { } |
| 174 static void AddLogToStream(StreamInterface* stream, int min_sev); | |
| 175 static void RemoveLogToStream(StreamInterface* stream); | |
| 176 | |
| 177 // Testing against MinLogSeverity allows code to avoid potentially expensive | |
| 178 // logging operations by pre-checking the logging level. | |
| 179 static int GetMinLogSeverity() { return min_sev_; } | |
| 180 | |
| 181 static void SetDiagnosticMode(bool f) { is_diagnostic_mode_ = f; } | |
| 182 static bool IsDiagnosticMode() { return is_diagnostic_mode_; } | |
| 183 | |
| 184 // Parses the provided parameter stream to configure the options above. | |
| 185 // Useful for configuring logging from the command line. If file logging | |
| 186 // is enabled, it is output to the specified filename. | |
| 187 static void ConfigureLogging(const char* params, const char* filename); | |
| 188 | |
| 189 // Convert the string to a LS_ value; also accept numeric values. | |
| 190 static int ParseLogSeverity(const std::string& value); | |
| 191 | |
| 192 private: | |
| 193 typedef std::list<std::pair<StreamInterface*, int> > StreamList; | |
| 194 | |
| 195 // Updates min_sev_ appropriately when debug sinks change. | |
| 196 static void UpdateMinLogSeverity(); | |
| 197 | |
| 198 // These assist in formatting some parts of the debug output. | |
| 199 static const char* Describe(LoggingSeverity sev); | |
| 200 static const char* DescribeFile(const char* file); | |
| 201 | |
| 202 // These write out the actual log messages. | |
| 203 static void OutputToDebug(const std::string& msg, LoggingSeverity severity_); | |
| 204 static void OutputToStream(StreamInterface* stream, const std::string& msg); | |
| 205 | |
| 206 // The ostream that buffers the formatted message before output | |
| 207 std::ostringstream print_stream_; | |
| 208 | |
| 209 // The severity level of this message | |
| 210 LoggingSeverity severity_; | |
| 211 | |
| 212 // String data generated in the constructor, that should be appended to | |
| 213 // the message before output. | |
| 214 std::string extra_; | |
| 215 | |
| 216 // Global lock for the logging subsystem | |
| 217 static CriticalSection crit_; | |
| 218 | |
| 219 // dbg_sev_ is the thresholds for those output targets | |
| 220 // min_sev_ is the minimum (most verbose) of those levels, and is used | |
| 221 // as a short-circuit in the logging macros to identify messages that won't | |
| 222 // be logged. | |
| 223 // ctx_sev_ is the minimum level at which file context is displayed | |
| 224 static int min_sev_, dbg_sev_, ctx_sev_; | |
| 225 | |
| 226 // The output streams and their associated severities | |
| 227 static StreamList streams_; | |
| 228 | |
| 229 // Flags for formatting options | |
| 230 static bool thread_, timestamp_; | |
| 231 | |
| 232 // The timestamp at which logging started. | |
| 233 static uint32 start_; | |
| 234 | |
| 235 // are we in diagnostic mode (as defined by the app)? | |
| 236 static bool is_diagnostic_mode_; | |
| 237 | |
| 238 DISALLOW_COPY_AND_ASSIGN(LogMessage); | |
| 239 }; | 136 }; |
| 240 | 137 |
| 241 ////////////////////////////////////////////////////////////////////// | 138 ////////////////////////////////////////////////////////////////////// |
| 242 // Logging Helpers | 139 // Logging Helpers |
| 243 ////////////////////////////////////////////////////////////////////// | 140 ////////////////////////////////////////////////////////////////////// |
| 244 | 141 |
| 142 // Summarizes LOG_E messages as strings. | |
| 143 std::string GenerateExtra(LogErrorContext err_ctx = ERRCTX_NONE, int err = 0, | |
| 144 const char* module = NULL); | |
| 145 | |
| 245 class LogMultilineState { | 146 class LogMultilineState { |
| 246 public: | 147 public: |
| 247 size_t unprintable_count_[2]; | 148 size_t unprintable_count_[2]; |
| 248 LogMultilineState() { | 149 LogMultilineState() { |
| 249 unprintable_count_[0] = unprintable_count_[1] = 0; | 150 unprintable_count_[0] = unprintable_count_[1] = 0; |
| 250 } | 151 } |
| 251 }; | 152 }; |
| 252 | 153 |
| 253 // When possible, pass optional state variable to track various data across | 154 // When possible, pass optional state variable to track various data across |
| 254 // multiple calls to LogMultiline. Otherwise, pass NULL. | 155 // multiple calls to LogMultiline. Otherwise, pass NULL. |
| 255 void LogMultiline(LoggingSeverity level, const char* label, bool input, | 156 void LogMultiline(LoggingSeverity level, const char* label, bool input, |
| 256 const void* data, size_t len, bool hex_mode, | 157 const void* data, size_t len, bool hex_mode, |
| 257 LogMultilineState* state); | 158 LogMultilineState* state); |
| 258 | 159 |
| 160 } // namespace talk_base | |
| 161 | |
| 259 ////////////////////////////////////////////////////////////////////// | 162 ////////////////////////////////////////////////////////////////////// |
| 260 // Macros which automatically disable logging when LOGGING == 0 | 163 // Libjingle macros which are mapped over to their VLOG equivalent in |
| 164 // base/logging.h | |
| 261 ////////////////////////////////////////////////////////////////////// | 165 ////////////////////////////////////////////////////////////////////// |
| 262 | 166 |
| 263 // If LOGGING is not explicitly defined, default to enabled in debug mode | 167 #ifdef LOGGING_INSIDE_LIBJINGLE |
| 264 #if defined(SAFE_TO_DEFINE_TALK_BASE_LOGGING_MACROS) | |
| 265 #if !defined(LOGGING) | |
| 266 #if defined(_DEBUG) && !defined(NDEBUG) && !defined(NO_LIBJINGLE_LOGGING) | |
| 267 #define LOGGING 1 | |
| 268 #else | |
| 269 #define LOGGING 0 | |
| 270 #endif | |
| 271 #endif // !defined(LOGGING) | |
| 272 | 168 |
| 273 #ifndef LOG | 169 #define LOG_CHECK_LEVEL(sev) \ |
| 274 #if LOGGING | 170 VLOG_IS_ON(talk_base::sev) |
| 171 #define LOG_CHECK_LEVEL_V(sev) \ | |
| 172 VLOG_IS_ON(sev) | |
| 275 | 173 |
| 276 // The following non-obvious technique for implementation of a | 174 #define LOG_V(sev) \ |
| 277 // conditional log stream was stolen from google3/base/logging.h. | 175 VLOG(sev) |
| 278 | 176 #undef LOG |
| 279 // This class is used to explicitly ignore values in the conditional | |
| 280 // logging macros. This avoids compiler warnings like "value computed | |
| 281 // is not used" and "statement has no effect". | |
| 282 | |
| 283 class LogMessageVoidify { | |
| 284 public: | |
| 285 LogMessageVoidify() { } | |
| 286 // This has to be an operator with a precedence lower than << but | |
| 287 // higher than ?: | |
| 288 void operator&(std::ostream&) { } | |
| 289 }; | |
| 290 | |
| 291 #define LOG_SEVERITY_PRECONDITION(sev) \ | |
| 292 !(talk_base::LogMessage::Loggable(sev)) \ | |
| 293 ? (void) 0 \ | |
| 294 : talk_base::LogMessageVoidify() & | |
| 295 | |
| 296 #define LOG(sev) \ | 177 #define LOG(sev) \ |
| 297 LOG_SEVERITY_PRECONDITION(talk_base::sev) \ | 178 LOG_V(talk_base::sev) |
| 298 talk_base::LogMessage(__FILE__, __LINE__, talk_base::sev).stream() | |
| 299 | |
| 300 // The _V version is for when a variable is passed in. It doesn't do the | |
| 301 // namespace concatination. | |
| 302 #define LOG_V(sev) \ | |
| 303 LOG_SEVERITY_PRECONDITION(sev) \ | |
| 304 talk_base::LogMessage(__FILE__, __LINE__, sev).stream() | |
| 305 | 179 |
| 306 // The _F version prefixes the message with the current function name. | 180 // The _F version prefixes the message with the current function name. |
| 307 #if defined(__GNUC__) && defined(_DEBUG) | 181 #if defined(__GNUC__) && defined(_DEBUG) |
| 308 #define LOG_F(sev) LOG(sev) << __PRETTY_FUNCTION__ << ": " | 182 #define LOG_F(sev) LOG(sev) << __PRETTY_FUNCTION__ << ": " |
| 309 #else | 183 #else |
| 310 #define LOG_F(sev) LOG(sev) << __FUNCTION__ << ": " | 184 #define LOG_F(sev) LOG(sev) << __FUNCTION__ << ": " |
| 311 #endif | 185 #endif |
| 312 | 186 |
| 313 #define LOG_CHECK_LEVEL(sev) \ | 187 // LOG_E can't call VLOG directly like LOG_V can since VLOG expands into usage |
| 314 talk_base::LogCheckLevel(talk_base::sev) | 188 // of the __FILE__ macro (for filtering) and the actual VLOG call from LOG_E |
| 315 #define LOG_CHECK_LEVEL_V(sev) \ | 189 // happens inside LogEHelper. Note that the second parameter to the LAZY_STREAM |
| 316 talk_base::LogCheckLevel(sev) | 190 // macro is true since the filter check is already done for LOG_E. |
| 317 inline bool LogCheckLevel(LoggingSeverity sev) { | 191 #define LOG_E_BASE(file_name, line_number, sev) \ |
| 318 return (LogMessage::GetMinLogSeverity() <= sev); | 192 LAZY_STREAM(logging::LogMessage(file_name, line_number, \ |
| 319 } | 193 -sev).stream(), \ |
| 194 true) | |
| 195 | |
| 196 #define LOG_SEVERITY_PRECONDITION(sev) \ | |
| 197 !(LOG_CHECK_LEVEL_V(sev)) \ | |
| 198 ? (void) 0 \ | |
| 199 : talk_base::LogMessageVoidify() & | |
| 320 | 200 |
| 321 #define LOG_E(sev, ctx, err, ...) \ | 201 #define LOG_E(sev, ctx, err, ...) \ |
| 322 LOG_SEVERITY_PRECONDITION(talk_base::sev) \ | 202 LOG_SEVERITY_PRECONDITION(talk_base::sev) \ |
| 323 talk_base::LogMessage(__FILE__, __LINE__, talk_base::sev, \ | 203 talk_base::LogEHelper( \ |
| 324 talk_base::ERRCTX_ ## ctx, err , ##__VA_ARGS__) \ | 204 __FILE__, __LINE__, talk_base::sev, \ |
| 325 .stream() | 205 talk_base::GenerateExtra( \ |
| 206 talk_base::ERRCTX_ ## ctx, err , ##__VA_ARGS__)).stream() | |
| 326 | 207 |
| 327 #else // !LOGGING | 208 #undef LOG_ERRNO_EX |
| 328 | |
| 329 // Hopefully, the compiler will optimize away some of this code. | |
| 330 // Note: syntax of "1 ? (void)0 : LogMessage" was causing errors in g++, | |
| 331 // converted to "while (false)" | |
| 332 #define LOG(sev) \ | |
| 333 while (false)talk_base:: LogMessage(NULL, 0, talk_base::sev).stream() | |
| 334 #define LOG_V(sev) \ | |
| 335 while (false) talk_base::LogMessage(NULL, 0, sev).stream() | |
| 336 #define LOG_F(sev) LOG(sev) << __FUNCTION__ << ": " | |
| 337 #define LOG_CHECK_LEVEL(sev) \ | |
| 338 false | |
| 339 #define LOG_CHECK_LEVEL_V(sev) \ | |
| 340 false | |
| 341 | |
| 342 #define LOG_E(sev, ctx, err, ...) \ | |
| 343 while (false) talk_base::LogMessage(__FILE__, __LINE__, talk_base::sev, \ | |
| 344 talk_base::ERRCTX_ ## ctx, err , ##__VA_ARGS__) \ | |
| 345 .stream() | |
| 346 | |
| 347 #endif // !LOGGING | |
| 348 | |
| 349 #define LOG_ERRNO_EX(sev, err) \ | 209 #define LOG_ERRNO_EX(sev, err) \ |
| 350 LOG_E(sev, ERRNO, err) | 210 LOG_E(sev, ERRNO, err) |
| 211 #undef LOG_ERRNO | |
| 351 #define LOG_ERRNO(sev) \ | 212 #define LOG_ERRNO(sev) \ |
| 352 LOG_ERRNO_EX(sev, errno) | 213 LOG_ERRNO_EX(sev, errno) |
| 353 | 214 |
| 354 #ifdef WIN32 | 215 #ifdef WIN32 |
| 355 #define LOG_GLE_EX(sev, err) \ | 216 #define LOG_GLE_EX(sev, err) \ |
| 356 LOG_E(sev, HRESULT, err) | 217 LOG_E(sev, HRESULT, err) |
| 357 #define LOG_GLE(sev) \ | 218 #define LOG_GLE(sev) \ |
| 358 LOG_GLE_EX(sev, GetLastError()) | 219 LOG_GLE_EX(sev, GetLastError()) |
| 359 #define LOG_GLEM(sev, mod) \ | 220 #define LOG_GLEM(sev, mod) \ |
| 360 LOG_E(sev, HRESULT, GetLastError(), mod) | 221 LOG_E(sev, HRESULT, GetLastError(), mod) |
| 361 #define LOG_ERR_EX(sev, err) \ | 222 #define LOG_ERR_EX(sev, err) \ |
| 362 LOG_GLE_EX(sev, err) | 223 LOG_GLE_EX(sev, err) |
| 363 #define LOG_ERR(sev) \ | 224 #define LOG_ERR(sev) \ |
| 364 LOG_GLE(sev) | 225 LOG_GLE(sev) |
| 365 #define LAST_SYSTEM_ERROR \ | 226 #define LAST_SYSTEM_ERROR \ |
| 366 (::GetLastError()) | 227 (::GetLastError()) |
| 367 #elif POSIX | 228 #elif POSIX |
| 368 #define LOG_ERR_EX(sev, err) \ | 229 #define LOG_ERR_EX(sev, err) \ |
| 369 LOG_ERRNO_EX(sev, err) | 230 LOG_ERRNO_EX(sev, err) |
| 370 #define LOG_ERR(sev) \ | 231 #define LOG_ERR(sev) \ |
| 371 LOG_ERRNO(sev) | 232 LOG_ERRNO(sev) |
| 372 #define LAST_SYSTEM_ERROR \ | 233 #define LAST_SYSTEM_ERROR \ |
| 373 (errno) | 234 (errno) |
| 374 #endif // WIN32 | 235 #endif // WIN32 |
| 375 | 236 |
| 237 #undef PLOG | |
| 376 #define PLOG(sev, err) \ | 238 #define PLOG(sev, err) \ |
| 377 LOG_ERR_EX(sev, err) | 239 LOG_ERR_EX(sev, err) |
| 378 | 240 |
| 379 // TODO(?): Add an "assert" wrapper that logs in the same manner. | 241 // TODO(?): Add an "assert" wrapper that logs in the same manner. |
| 380 | 242 |
| 381 #endif // LOG | 243 #endif // LOGGING_INSIDE_LIBJINGLE |
| 382 #endif // defined(SAFE_TO_DEFINE_TALK_BASE_LOGGING_MACROS) | |
| 383 | 244 |
| 384 } // namespace talk_base | 245 #endif // THIRD_PARTY_LIBJINGLE_OVERRIDES_TALK_BASE_LOGGING_H_ |
| 385 | |
| 386 #endif // TALK_BASE_LOGGING_H_ | |
| OLD | NEW |