Reland "Some cleanup for the logging code:"
This is a reland of 9ecdcdf2b527bdb1d097782d92817c9866d6d18b.
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}
Bug: webrtc:8928
Change-Id: Id062a5b61917e66561f6c8441c2defd525e38f16
Reviewed-on: https://webrtc-review.googlesource.com/57880
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22191}
diff --git a/rtc_base/logging.h b/rtc_base/logging.h
index 0865379..09554a7 100644
--- a/rtc_base/logging.h
+++ b/rtc_base/logging.h
@@ -26,9 +26,8 @@
// 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(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_GLE(sev [, mod]) attempt to add a string description of the
+// HRESULT returned by GetLastError.
// 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.
@@ -68,29 +67,6 @@
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);
@@ -148,13 +124,15 @@
int line,
LoggingSeverity sev,
LogErrorContext err_ctx = ERRCTX_NONE,
- int err = 0,
- const char* module = nullptr);
+ int err = 0);
- LogMessage(const char* file,
- int line,
- LoggingSeverity sev,
+#if defined(WEBRTC_ANDROID)
+ LogMessage(const char* file, int line, LoggingSeverity sev, const char* tag);
+#else
+ // DEPRECATED - DO NOT USE - PLEASE USE THE MACROS INSTEAD OF THE CLASS.
+ LogMessage(const char* file, int line, LoggingSeverity sev,
const std::string& tag);
+#endif
~LogMessage();
@@ -213,9 +191,13 @@
static void UpdateMinLogSeverity();
// These write out the actual log messages.
+#if defined(WEBRTC_ANDROID)
static void OutputToDebug(const std::string& msg,
LoggingSeverity severity,
- const std::string& tag);
+ const char* tag);
+#else
+ static void OutputToDebug(const std::string& msg, LoggingSeverity severity);
+#endif
// The ostream that buffers the formatted message before output
std::ostringstream print_stream_;
@@ -223,8 +205,10 @@
// The severity level of this message
LoggingSeverity severity_;
+#if defined(WEBRTC_ANDROID)
// The Android debug output tag.
- std::string tag_;
+ const char* tag_ = "libjingle";
+#endif
// String data generated in the constructor, that should be appended to
// the message before output.
@@ -313,8 +297,6 @@
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) \
@@ -331,9 +313,21 @@
RTC_LOG_ERRNO(sev)
#endif // WEBRTC_WIN
+#if defined(WEBRTC_ANDROID)
+namespace internal {
+// Inline adapters provided for backwards compatibility for downstream projects.
+inline const char* AdaptString(const std::string& str) { return str.c_str(); }
+inline const char* AdaptString(const char* str) { return str; }
+} // namespace internal
#define RTC_LOG_TAG(sev, tag) \
RTC_LOG_SEVERITY_PRECONDITION(sev) \
- rtc::LogMessage(nullptr, 0, sev, tag).stream()
+ rtc::LogMessage(nullptr, 0, sev, rtc::internal::AdaptString(tag)).stream()
+#else
+// DEPRECATED. This macro is only intended for Android.
+#define RTC_LOG_TAG(sev, tag) \
+ RTC_LOG_SEVERITY_PRECONDITION(sev) \
+ rtc::LogMessage(nullptr, 0, sev).stream()
+#endif
// The RTC_DLOG macros are equivalent to their RTC_LOG counterparts except that
// they only generate code in debug builds.