Revert "Some cleanup for the logging code:"
This reverts commit 9ecdcdf2b527bdb1d097782d92817c9866d6d18b.
Reason for revert: Breaks downstream project.
Original change's description:
> Some cleanup for the logging code:
>
> * Only include 'tag' for Android. Before there was an
> extra std::string variable per log statement for all
> platforms.
> * Remove unused logging macro for Windows and 'module' ctor argument.
> * Move httpcommon code out of logging and to where it's used.
>
> Change-Id: I347805d3df2cee2840c0d2eef5bfefaff1cdbf37
> Bug: webrtc:8928
> Reviewed-on: https://webrtc-review.googlesource.com/57183
> Reviewed-by: Jonas Olsson <jonasolsson@webrtc.org>
> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> Commit-Queue: Tommi <tommi@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#22184}
TBR=kwiberg@webrtc.org,tommi@webrtc.org,jonasolsson@webrtc.org
Change-Id: I37a13d766fbdee2adb7f45231cf8be6b2b456bec
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8928
Reviewed-on: https://webrtc-review.googlesource.com/57720
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Commit-Queue: Philip Eliasson <philipel@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22187}
diff --git a/rtc_base/logging.h b/rtc_base/logging.h
index d91db9a..0865379 100644
--- a/rtc_base/logging.h
+++ b/rtc_base/logging.h
@@ -26,8 +26,9 @@
// RTC_LOG_F(sev) Like RTC_LOG(), but includes the name of the current function.
// RTC_LOG_T(sev) Like RTC_LOG(), but includes the this pointer.
// RTC_LOG_T_F(sev) Like RTC_LOG_F(), but includes the this pointer.
-// RTC_LOG_GLE(sev [, mod]) attempt to add a string description of the
-// HRESULT returned by GetLastError.
+// RTC_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.
// RTC_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.
@@ -67,6 +68,29 @@
namespace rtc {
+///////////////////////////////////////////////////////////////////////////////
+// ConstantLabel can be used to easily generate string names from constant
+// values. This can be useful for logging descriptive names of error messages.
+// Usage:
+// const ConstantLabel LIBRARY_ERRORS[] = {
+// KLABEL(SOME_ERROR),
+// KLABEL(SOME_OTHER_ERROR),
+// ...
+// LASTLABEL
+// }
+//
+// int err = LibraryFunc();
+// LOG(LS_ERROR) << "LibraryFunc returned: "
+// << ErrorName(err, LIBRARY_ERRORS);
+
+struct ConstantLabel { int value; const char * label; };
+#define KLABEL(x) { x, #x }
+#define TLABEL(x, y) { x, y }
+#define LASTLABEL { 0, 0 }
+
+const char* FindLabel(int value, const ConstantLabel entries[]);
+std::string ErrorName(int err, const ConstantLabel* err_table);
+
#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
// Returns a UTF8 description from an OS X Status error.
std::string DescriptionFromOSStatus(OSStatus err);
@@ -124,11 +148,13 @@
int line,
LoggingSeverity sev,
LogErrorContext err_ctx = ERRCTX_NONE,
- int err = 0);
+ int err = 0,
+ const char* module = nullptr);
-#if defined(WEBRTC_ANDROID)
- LogMessage(const char* file, int line, LoggingSeverity sev, const char* tag);
-#endif
+ LogMessage(const char* file,
+ int line,
+ LoggingSeverity sev,
+ const std::string& tag);
~LogMessage();
@@ -187,13 +213,9 @@
static void UpdateMinLogSeverity();
// These write out the actual log messages.
-#if defined(WEBRTC_ANDROID)
static void OutputToDebug(const std::string& msg,
LoggingSeverity severity,
- const char* tag);
-#else
- static void OutputToDebug(const std::string& msg, LoggingSeverity severity);
-#endif
+ const std::string& tag);
// The ostream that buffers the formatted message before output
std::ostringstream print_stream_;
@@ -201,10 +223,8 @@
// The severity level of this message
LoggingSeverity severity_;
-#if defined(WEBRTC_ANDROID)
// The Android debug output tag.
- const char* tag_ = "libjingle";
-#endif
+ std::string tag_;
// String data generated in the constructor, that should be appended to
// the message before output.
@@ -293,6 +313,8 @@
RTC_LOG_E(sev, HRESULT, err)
#define RTC_LOG_GLE(sev) \
RTC_LOG_GLE_EX(sev, GetLastError())
+#define RTC_LOG_GLEM(sev, mod) \
+ RTC_LOG_E(sev, HRESULT, GetLastError(), mod)
#define RTC_LOG_ERR_EX(sev, err) \
RTC_LOG_GLE_EX(sev, err)
#define RTC_LOG_ERR(sev) \
@@ -309,11 +331,9 @@
RTC_LOG_ERRNO(sev)
#endif // WEBRTC_WIN
-#if defined(WEBRTC_ANDROID)
#define RTC_LOG_TAG(sev, tag) \
RTC_LOG_SEVERITY_PRECONDITION(sev) \
rtc::LogMessage(nullptr, 0, sev, tag).stream()
-#endif
// The RTC_DLOG macros are equivalent to their RTC_LOG counterparts except that
// they only generate code in debug builds.