diff options
author | hellner@google.com <hellner@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-17 18:08:49 +0000 |
---|---|---|
committer | hellner@google.com <hellner@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-17 18:08:49 +0000 |
commit | 48fe88ff1ad52d9616b8bbb3b29a21d008731fc6 (patch) | |
tree | 2de1b39e90d44d01c6b01c769bcb5a834ae6aa4a /third_party/libjingle/overrides | |
parent | aaafb52bd0117abdde6c13bc2b4a048c338a0da5 (diff) | |
download | chromium_src-48fe88ff1ad52d9616b8bbb3b29a21d008731fc6.zip chromium_src-48fe88ff1ad52d9616b8bbb3b29a21d008731fc6.tar.gz chromium_src-48fe88ff1ad52d9616b8bbb3b29a21d008731fc6.tar.bz2 |
This change updates the libjingle logging so that it writes to chromiums VLOG instead of its own logging mechanism.
Review URL: http://codereview.chromium.org/8991010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117917 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/libjingle/overrides')
-rw-r--r-- | third_party/libjingle/overrides/talk/base/logging.cc | 242 | ||||
-rw-r--r-- | third_party/libjingle/overrides/talk/base/logging.h | 391 |
2 files changed, 347 insertions, 286 deletions
diff --git a/third_party/libjingle/overrides/talk/base/logging.cc b/third_party/libjingle/overrides/talk/base/logging.cc new file mode 100644 index 0000000..72e24e3 --- /dev/null +++ b/third_party/libjingle/overrides/talk/base/logging.cc @@ -0,0 +1,242 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "third_party/libjingle/overrides/talk/base/logging.h" + +#if defined(OS_MACOSX) +#include <CoreServices/CoreServices.h> +#endif // OS_MACOSX + +#include <iomanip> + +#include "base/string_util.h" +#include "third_party/libjingle/source/talk/base/stream.h" +#include "third_party/libjingle/source/talk/base/stringencode.h" +#include "third_party/libjingle/source/talk/base/stringutils.h" + +// LOG_E can't call VLOG directly like LOG_V can since VLOG expands into usage +// of the __FILE__ macro (for filtering) and the actual VLOG call from LOG_E +// happens inside LogEHelper. Note that the second parameter to the LAZY_STREAM +// macro is true since the filter check is already done for LOG_E. +#define LOG_E_BASE(file_name, line_number, sev) \ + LAZY_STREAM(logging::LogMessage(file_name, line_number, \ + -sev).stream(), true) + +namespace talk_base { + +///////////////////////////////////////////////////////////////////////////// +// Constant Labels +///////////////////////////////////////////////////////////////////////////// + +const char* FindLabel(int value, const ConstantLabel entries[]) { + for (int i = 0; entries[i].label; ++i) { + if (value == entries[i].value) return entries[i].label; + } + return 0; +} + +std::string ErrorName(int err, const ConstantLabel* err_table) { + if (err == 0) + return "No error"; + + if (err_table != 0) { + if (const char * value = FindLabel(err, err_table)) + return value; + } + + char buffer[16]; + base::snprintf(buffer, sizeof(buffer), "0x%08x", err); + return buffer; +} + +///////////////////////////////////////////////////////////////////////////// +// LogEHelper +///////////////////////////////////////////////////////////////////////////// + +// Summarizes LOG_E messages as strings. +static std::string GenerateExtra(LogErrorContext err_ctx, + int err, + const char* module) { + if (err_ctx != ERRCTX_NONE) { + std::ostringstream tmp; + tmp << ": "; + tmp << "[0x" << std::setfill('0') << std::hex << std::setw(8) << err << "]"; + switch (err_ctx) { + case ERRCTX_ERRNO: + tmp << " " << strerror(err); + break; +#if defined(OS_WIN) + case ERRCTX_HRESULT: { + char msgbuf[256]; + DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM; + HMODULE hmod = GetModuleHandleA(module); + if (hmod) + flags |= FORMAT_MESSAGE_FROM_HMODULE; + if (DWORD len = FormatMessageA( + flags, hmod, err, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + msgbuf, sizeof(msgbuf) / sizeof(msgbuf[0]), NULL)) { + while ((len > 0) && + isspace(static_cast<unsigned char>(msgbuf[len-1]))) { + msgbuf[--len] = 0; + } + tmp << " " << msgbuf; + } + break; + } +#endif // OS_WIN +#if defined(OS_MACOSX) + case ERRCTX_OSSTATUS: { + tmp << " " << nonnull(GetMacOSStatusErrorString(err), "Unknown error"); + if (const char* desc = GetMacOSStatusCommentString(err)) { + tmp << ": " << desc; + } + break; + } +#endif // OS_MACOSX + default: + break; + } + return tmp.str(); + } + return ""; +} + +LogEHelper::LogEHelper(const char* file, + int line, + LoggingSeverity severity, + LogErrorContext err_ctx, + int err, + const char* module) + : file_name_(file), + line_(line), + severity_(severity) { + extra_ = GenerateExtra(err_ctx, err, module); +} + +LogEHelper::~LogEHelper() { + print_stream_ << extra_; + const std::string& str = print_stream_.str(); + LOG_E_BASE(file_name_.c_str(), line_, severity_) << str; +} + +// Note: this function is a copy from the overriden libjingle implementation. +void LogMultiline(LoggingSeverity level, const char* label, bool input, + const void* data, size_t len, bool hex_mode, + LogMultilineState* state) { + if (!LOG_CHECK_LEVEL_V(level)) + return; + + const char * direction = (input ? " << " : " >> "); + + // NULL data means to flush our count of unprintable characters. + if (!data) { + if (state && state->unprintable_count_[input]) { + LOG_V(level) << label << direction << "## " + << state->unprintable_count_[input] + << " consecutive unprintable ##"; + state->unprintable_count_[input] = 0; + } + return; + } + + // The ctype classification functions want unsigned chars. + const unsigned char* udata = static_cast<const unsigned char*>(data); + + if (hex_mode) { + const size_t LINE_SIZE = 24; + char hex_line[LINE_SIZE * 9 / 4 + 2], asc_line[LINE_SIZE + 1]; + while (len > 0) { + memset(asc_line, ' ', sizeof(asc_line)); + memset(hex_line, ' ', sizeof(hex_line)); + size_t line_len = _min(len, LINE_SIZE); + for (size_t i = 0; i < line_len; ++i) { + unsigned char ch = udata[i]; + asc_line[i] = isprint(ch) ? ch : '.'; + hex_line[i*2 + i/4] = hex_encode(ch >> 4); + hex_line[i*2 + i/4 + 1] = hex_encode(ch & 0xf); + } + asc_line[sizeof(asc_line)-1] = 0; + hex_line[sizeof(hex_line)-1] = 0; + LOG_V(level) << label << direction + << asc_line << " " << hex_line << " "; + udata += line_len; + len -= line_len; + } + return; + } + + size_t consecutive_unprintable = state ? state->unprintable_count_[input] : 0; + + const unsigned char* end = udata + len; + while (udata < end) { + const unsigned char* line = udata; + const unsigned char* end_of_line = strchrn<unsigned char>(udata, + end - udata, + '\n'); + if (!end_of_line) { + udata = end_of_line = end; + } else { + udata = end_of_line + 1; + } + + bool is_printable = true; + + // If we are in unprintable mode, we need to see a line of at least + // kMinPrintableLine characters before we'll switch back. + const ptrdiff_t kMinPrintableLine = 4; + if (consecutive_unprintable && ((end_of_line - line) < kMinPrintableLine)) { + is_printable = false; + } else { + // Determine if the line contains only whitespace and printable + // characters. + bool is_entirely_whitespace = true; + for (const unsigned char* pos = line; pos < end_of_line; ++pos) { + if (isspace(*pos)) + continue; + is_entirely_whitespace = false; + if (!isprint(*pos)) { + is_printable = false; + break; + } + } + // Treat an empty line following unprintable data as unprintable. + if (consecutive_unprintable && is_entirely_whitespace) { + is_printable = false; + } + } + if (!is_printable) { + consecutive_unprintable += (udata - line); + continue; + } + // Print out the current line, but prefix with a count of prior unprintable + // characters. + if (consecutive_unprintable) { + LOG_V(level) << label << direction << "## " << consecutive_unprintable + << " consecutive unprintable ##"; + consecutive_unprintable = 0; + } + // Strip off trailing whitespace. + while ((end_of_line > line) && isspace(*(end_of_line-1))) { + --end_of_line; + } + // Filter out any private data + std::string substr(reinterpret_cast<const char*>(line), end_of_line - line); + std::string::size_type pos_private = substr.find("Email"); + if (pos_private == std::string::npos) { + pos_private = substr.find("Passwd"); + } + if (pos_private == std::string::npos) { + LOG_V(level) << label << direction << substr; + } else { + LOG_V(level) << label << direction << "## omitted for privacy ##"; + } + } + + if (state) { + state->unprintable_count_[input] = consecutive_unprintable; + } +} + +} // namespace talk_base diff --git a/third_party/libjingle/overrides/talk/base/logging.h b/third_party/libjingle/overrides/talk/base/logging.h index 1a865af..98ffa79 100644 --- a/third_party/libjingle/overrides/talk/base/logging.h +++ b/third_party/libjingle/overrides/talk/base/logging.h @@ -1,80 +1,34 @@ -/* - * libjingle - * Copyright 2004--2005, Google Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -// LOG(...) an ostream target that can be used to send formatted -// output to a variety of logging targets, such as debugger console, stderr, -// file, or any StreamInterface. -// The severity level passed as the first argument to the the LOGging -// functions is used as a filter, to limit the verbosity of the logging. -// Static members of LogMessage documented below are used to control the -// verbosity and target of the output. -// There are several variations on the LOG macro which facilitate logging -// of common error conditions, detailed below. - -// LOG(sev) logs the given stream at severity "sev", which must be a -// compile-time constant of the LoggingSeverity type, without the namespace -// prefix. -// LOG_V(sev) Like LOG(), but sev is a run-time variable of the LoggingSeverity -// type (basically, it just doesn't prepend the namespace). -// LOG_F(sev) Like LOG(), but includes the name of the current function. -// LOG_GLE(M)(sev [, mod]) attempt to add a string description of the -// HRESULT returned by GetLastError. The "M" variant allows searching of a -// DLL's string table for the error description. -// LOG_ERRNO(sev) attempts to add a string description of an errno-derived -// error. errno and associated facilities exist on both Windows and POSIX, -// but on Windows they only apply to the C/C++ runtime. -// LOG_ERR(sev) is an alias for the platform's normal error system, i.e. _GLE on -// Windows and _ERRNO on POSIX. -// (The above three also all have _EX versions that let you specify the error -// code, rather than using the last one.) -// LOG_E(sev, ctx, err, ...) logs a detailed error interpreted using the -// specified context. -// LOG_CHECK_LEVEL(sev) (and LOG_CHECK_LEVEL_V(sev)) can be used as a test -// before performing expensive or sensitive operations whose sole purpose is -// to output logging data at the desired level. -// Lastly, PLOG(sev, err) is an alias for LOG_ERR_EX. - -#ifndef TALK_BASE_LOGGING_H_ -#define TALK_BASE_LOGGING_H_ - -#ifdef HAVE_CONFIG_H -#include "config.h" // NOLINT -#endif +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file overrides the logging macros in libjingle (talk/base/logging.h). +// Instead of using libjingle's logging implementation, the libjingle macros are +// mapped to the corresponding base/logging.h macro (chromium's VLOG). +// If this file is included outside of libjingle (e.g. in wrapper code) it +// should be included after base/logging.h (if any) or compiler error or +// unexpected behavior may occur (macros that have the same name in libjingle as +// in chromium will use the libjingle definition if this file is included +// first). + +// Setting the LoggingSeverity (and lower) that should be written to file should +// be done via command line by specifying the flags: +// --vmodule or --v please see base/logging.h for details on how to use them. +// Specifying what file to write to is done using InitLogging also in +// base/logging.h. + +// The macros and classes declared in here are not described as they are +// NOT TO BE USED outside of libjingle. + +#ifndef THIRD_PARTY_LIBJINGLE_OVERRIDES_TALK_BASE_LOGGING_H_ +#define THIRD_PARTY_LIBJINGLE_OVERRIDES_TALK_BASE_LOGGING_H_ -#include <list> #include <sstream> #include <string> -#include <utility> -#include "talk/base/basictypes.h" -#include "talk/base/criticalsection.h" -namespace talk_base { +#include "base/logging.h" -class StreamInterface; +namespace talk_base { /////////////////////////////////////////////////////////////////////////////// // ConstantLabel can be used to easily generate string names from constant @@ -91,19 +45,17 @@ class StreamInterface; // LOG(LS_ERROR) << "LibraryFunc returned: " // << ErrorName(err, LIBRARY_ERRORS); -struct ConstantLabel { int value; const char * label; }; - -#if defined(SAFE_TO_DEFINE_TALK_BASE_LOGGING_MACROS) +struct ConstantLabel { + int value; + const char* label; +}; #define KLABEL(x) { x, #x } -#define TLABEL(x, y) { x, y } #define LASTLABEL { 0, 0 } -#endif // defined(SAFE_TO_DEFINE_TALK_BASE_LOGGING_MACROS) -const char * FindLabel(int value, const ConstantLabel entries[]); +const char* FindLabel(int value, const ConstantLabel entries[]); std::string ErrorName(int err, const ConstantLabel* err_table); ////////////////////////////////////////////////////////////////////// - // Note that the non-standard LoggingSeverity aliases exist because they are // still in broad use. The meanings of the levels are: // LS_SENSITIVE: Information which should only be logged with the consent @@ -114,7 +66,17 @@ std::string ErrorName(int err, const ConstantLabel* err_table); // in debug builds. // LS_WARNING: Something that may warrant investigation. // LS_ERROR: Something that should not have occurred. -enum LoggingSeverity { LS_SENSITIVE, LS_VERBOSE, LS_INFO, LS_WARNING, LS_ERROR, +// Note that LoggingSeverity is mapped over to chromiums verbosity levels where +// anything lower than or equal to the current verbosity level is written to +// file which is the opposite of logging severity in libjingle where higher +// severity numbers than or equal to the current severity level are written to +// file. Also, note that the values are explicitly defined here for convenience +// since the command line flag must be set using numerical values. +enum LoggingSeverity { LS_ERROR = 1, + LS_WARNING = 2, + LS_INFO = 3, + LS_VERBOSE = 4, + LS_SENSITIVE = 5, INFO = LS_INFO, WARNING = LS_WARNING, LERROR = LS_ERROR }; @@ -132,110 +94,35 @@ enum LogErrorContext { ERRCTX_OS = ERRCTX_OSSTATUS, // LOG_E(sev, OS, x) }; -class LogMessage { +// Class that makes it possible describe a LOG_E message as a single string. +// I.e. the format that VLOG is expecting. +class LogEHelper { public: - static const int NO_LOGGING; - - LogMessage(const char* file, int line, LoggingSeverity sev, - LogErrorContext err_ctx = ERRCTX_NONE, int err = 0, - const char* module = NULL); - ~LogMessage(); + LogEHelper(const char* file, int line, LoggingSeverity severity, + LogErrorContext err_ctx, int err, const char* module = NULL); + ~LogEHelper(); - static inline bool Loggable(LoggingSeverity sev) { return (sev >= min_sev_); } std::ostream& stream() { return print_stream_; } - // These are attributes which apply to all logging channels - // LogContext: Display the file and line number of the message - static void LogContext(int min_sev); - // LogThreads: Display the thread identifier of the current thread - static void LogThreads(bool on = true); - // LogTimestamps: Display the elapsed time of the program - static void LogTimestamps(bool on = true); - - // Timestamps begin with program execution, but can be reset with this - // function for measuring the duration of an activity, or to synchronize - // timestamps between multiple instances. - static void ResetTimestamps(); - - // These are the available logging channels - // Debug: Debug console on Windows, otherwise stderr - static void LogToDebug(int min_sev); - static int GetLogToDebug() { return dbg_sev_; } - - // Stream: Any non-blocking stream interface. LogMessage takes ownership of - // the stream. Multiple streams may be specified by using AddLogToStream. - // LogToStream is retained for backwards compatibility; when invoked, it - // will discard any previously set streams and install the specified stream. - // GetLogToStream gets the severity for the specified stream, of if none - // is specified, the minimum stream severity. - // RemoveLogToStream removes the specified stream, without destroying it. - static void LogToStream(StreamInterface* stream, int min_sev); - static int GetLogToStream(StreamInterface* stream = NULL); - static void AddLogToStream(StreamInterface* stream, int min_sev); - static void RemoveLogToStream(StreamInterface* stream); - - // Testing against MinLogSeverity allows code to avoid potentially expensive - // logging operations by pre-checking the logging level. - static int GetMinLogSeverity() { return min_sev_; } - - static void SetDiagnosticMode(bool f) { is_diagnostic_mode_ = f; } - static bool IsDiagnosticMode() { return is_diagnostic_mode_; } - - // Parses the provided parameter stream to configure the options above. - // Useful for configuring logging from the command line. If file logging - // is enabled, it is output to the specified filename. - static void ConfigureLogging(const char* params, const char* filename); - - // Convert the string to a LS_ value; also accept numeric values. - static int ParseLogSeverity(const std::string& value); - private: - typedef std::list<std::pair<StreamInterface*, int> > StreamList; - - // Updates min_sev_ appropriately when debug sinks change. - static void UpdateMinLogSeverity(); - - // These assist in formatting some parts of the debug output. - static const char* Describe(LoggingSeverity sev); - static const char* DescribeFile(const char* file); - - // These write out the actual log messages. - static void OutputToDebug(const std::string& msg, LoggingSeverity severity_); - static void OutputToStream(StreamInterface* stream, const std::string& msg); - - // The ostream that buffers the formatted message before output - std::ostringstream print_stream_; - - // The severity level of this message - LoggingSeverity severity_; + const std::string file_name_; + const int line_; - // String data generated in the constructor, that should be appended to - // the message before output. std::string extra_; + const LoggingSeverity severity_; - // Global lock for the logging subsystem - static CriticalSection crit_; - - // dbg_sev_ is the thresholds for those output targets - // min_sev_ is the minimum (most verbose) of those levels, and is used - // as a short-circuit in the logging macros to identify messages that won't - // be logged. - // ctx_sev_ is the minimum level at which file context is displayed - static int min_sev_, dbg_sev_, ctx_sev_; - - // The output streams and their associated severities - static StreamList streams_; - - // Flags for formatting options - static bool thread_, timestamp_; - - // The timestamp at which logging started. - static uint32 start_; - - // are we in diagnostic mode (as defined by the app)? - static bool is_diagnostic_mode_; + std::ostringstream print_stream_; +}; - DISALLOW_COPY_AND_ASSIGN(LogMessage); +// This class is used to explicitly ignore values in the conditional +// logging macros. This avoids compiler warnings like "value computed +// is not used" and "statement has no effect". +class LogMessageVoidify { + public: + LogMessageVoidify() { } + // This has to be an operator with a precedence lower than << but + // higher than ?: + void operator&(std::ostream&) { } }; ////////////////////////////////////////////////////////////////////// @@ -256,52 +143,21 @@ void LogMultiline(LoggingSeverity level, const char* label, bool input, const void* data, size_t len, bool hex_mode, LogMultilineState* state); +} // namespace talk_base + ////////////////////////////////////////////////////////////////////// -// Macros which automatically disable logging when LOGGING == 0 +// Libjingle macros which are mapped over to their VLOG equivalent in +// base/logging.h ////////////////////////////////////////////////////////////////////// -// If LOGGING is not explicitly defined, default to enabled in debug mode -#if defined(SAFE_TO_DEFINE_TALK_BASE_LOGGING_MACROS) -#if !defined(LOGGING) -#if defined(_DEBUG) && !defined(NDEBUG) && !defined(NO_LIBJINGLE_LOGGING) -#define LOGGING 1 -#else -#define LOGGING 0 -#endif -#endif // !defined(LOGGING) - -#ifndef LOG -#if LOGGING +#if defined(LOGGING_INSIDE_LIBJINGLE) -// The following non-obvious technique for implementation of a -// conditional log stream was stolen from google3/base/logging.h. +#define LOG_CHECK_LEVEL(sev) VLOG_IS_ON(talk_base::sev) +#define LOG_CHECK_LEVEL_V(sev) VLOG_IS_ON(sev) -// This class is used to explicitly ignore values in the conditional -// logging macros. This avoids compiler warnings like "value computed -// is not used" and "statement has no effect". - -class LogMessageVoidify { - public: - LogMessageVoidify() { } - // This has to be an operator with a precedence lower than << but - // higher than ?: - void operator&(std::ostream&) { } -}; - -#define LOG_SEVERITY_PRECONDITION(sev) \ - !(talk_base::LogMessage::Loggable(sev)) \ - ? (void) 0 \ - : talk_base::LogMessageVoidify() & - -#define LOG(sev) \ - LOG_SEVERITY_PRECONDITION(talk_base::sev) \ - talk_base::LogMessage(__FILE__, __LINE__, talk_base::sev).stream() - -// The _V version is for when a variable is passed in. It doesn't do the -// namespace concatination. -#define LOG_V(sev) \ - LOG_SEVERITY_PRECONDITION(sev) \ - talk_base::LogMessage(__FILE__, __LINE__, sev).stream() +#define LOG_V(sev) VLOG(sev) +#undef LOG +#define LOG(sev) LOG_V(talk_base::sev) // The _F version prefixes the message with the current function name. #if defined(__GNUC__) && defined(_DEBUG) @@ -310,77 +166,40 @@ class LogMessageVoidify { #define LOG_F(sev) LOG(sev) << __FUNCTION__ << ": " #endif -#define LOG_CHECK_LEVEL(sev) \ - talk_base::LogCheckLevel(talk_base::sev) -#define LOG_CHECK_LEVEL_V(sev) \ - talk_base::LogCheckLevel(sev) -inline bool LogCheckLevel(LoggingSeverity sev) { - return (LogMessage::GetMinLogSeverity() <= sev); -} - +// This macro wrapps the LAZY_STREAM macro from base/logging.h but flips the +// order of the parameters. This is necessary since some compilers will fail +// unless __VA_ARGS__ is at the end. +// TODO(hellner): find reference for this. +#define LAZY_STREAM_REVERSE(condition, stream) LAZY_STREAM(stream, condition) #define LOG_E(sev, ctx, err, ...) \ - LOG_SEVERITY_PRECONDITION(talk_base::sev) \ - talk_base::LogMessage(__FILE__, __LINE__, talk_base::sev, \ - talk_base::ERRCTX_ ## ctx, err , ##__VA_ARGS__) \ - .stream() - -#else // !LOGGING - -// Hopefully, the compiler will optimize away some of this code. -// Note: syntax of "1 ? (void)0 : LogMessage" was causing errors in g++, -// converted to "while (false)" -#define LOG(sev) \ - while (false)talk_base:: LogMessage(NULL, 0, talk_base::sev).stream() -#define LOG_V(sev) \ - while (false) talk_base::LogMessage(NULL, 0, sev).stream() -#define LOG_F(sev) LOG(sev) << __FUNCTION__ << ": " -#define LOG_CHECK_LEVEL(sev) \ - false -#define LOG_CHECK_LEVEL_V(sev) \ - false + LAZY_STREAM_REVERSE(LOG_CHECK_LEVEL_V(talk_base::sev), \ + talk_base::LogEHelper(__FILE__, __LINE__, \ + talk_base::sev, \ + talk_base::ERRCTX_ ## ctx, \ + err, \ + ##__VA_ARGS__).stream()) + +#undef LOG_ERRNO_EX +#define LOG_ERRNO_EX(sev, err) LOG_E(sev, ERRNO, err) +#undef LOG_ERRNO +#define LOG_ERRNO(sev) LOG_ERRNO_EX(sev, errno) + +#if defined(OS_WIN) +#define LOG_GLE_EX(sev, err) LOG_E(sev, HRESULT, err) +#define LOG_GLE(sev) LOG_GLE_EX(sev, GetLastError()) +#define LOG_GLEM(sev, mod) LOG_E(sev, HRESULT, GetLastError(), mod) +#define LOG_ERR_EX(sev, err) LOG_GLE_EX(sev, err) +#define LOG_ERR(sev) LOG_GLE(sev) +#define LAST_SYSTEM_ERROR (::GetLastError()) +#else +#define LOG_ERR_EX(sev, err) LOG_ERRNO_EX(sev, err) +#define LOG_ERR(sev) LOG_ERRNO(sev) +#define LAST_SYSTEM_ERROR (errno) +#endif // OS_WIN -#define LOG_E(sev, ctx, err, ...) \ - while (false) talk_base::LogMessage(__FILE__, __LINE__, talk_base::sev, \ - talk_base::ERRCTX_ ## ctx, err , ##__VA_ARGS__) \ - .stream() - -#endif // !LOGGING - -#define LOG_ERRNO_EX(sev, err) \ - LOG_E(sev, ERRNO, err) -#define LOG_ERRNO(sev) \ - LOG_ERRNO_EX(sev, errno) - -#ifdef WIN32 -#define LOG_GLE_EX(sev, err) \ - LOG_E(sev, HRESULT, err) -#define LOG_GLE(sev) \ - LOG_GLE_EX(sev, GetLastError()) -#define LOG_GLEM(sev, mod) \ - LOG_E(sev, HRESULT, GetLastError(), mod) -#define LOG_ERR_EX(sev, err) \ - LOG_GLE_EX(sev, err) -#define LOG_ERR(sev) \ - LOG_GLE(sev) -#define LAST_SYSTEM_ERROR \ - (::GetLastError()) -#elif POSIX -#define LOG_ERR_EX(sev, err) \ - LOG_ERRNO_EX(sev, err) -#define LOG_ERR(sev) \ - LOG_ERRNO(sev) -#define LAST_SYSTEM_ERROR \ - (errno) -#endif // WIN32 - -#define PLOG(sev, err) \ - LOG_ERR_EX(sev, err) - -// TODO(?): Add an "assert" wrapper that logs in the same manner. - -#endif // LOG -#endif // defined(SAFE_TO_DEFINE_TALK_BASE_LOGGING_MACROS) +#undef PLOG +#define PLOG(sev, err) LOG_ERR_EX(sev, err) -} // namespace talk_base +#endif // LOGGING_INSIDE_LIBJINGLE -#endif // TALK_BASE_LOGGING_H_ +#endif // THIRD_PARTY_LIBJINGLE_OVERRIDES_TALK_BASE_LOGGING_H_ |