Add a logging_no_op.cc when enable_tracing==0.

This should hopefully fix static initializer warnings when rolling webrtc
in Chromium.

TEST=logging_unittest succeeds with enable_tracing==1 and fails appropriately with enable_tracing==0.

Review URL: https://webrtc-codereview.appspot.com/939026

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3159 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/build/common.gypi b/webrtc/build/common.gypi
index dca62ea..0049d13 100644
--- a/webrtc/build/common.gypi
+++ b/webrtc/build/common.gypi
@@ -139,6 +139,9 @@
       #'WEBRTC_SVNREVISION="<!(python <(webrtc_root)/build/version.py)"',
     ],
     'conditions': [
+      ['enable_tracing==1', {
+        'defines': ['WEBRTC_LOGGING',],
+      }],
       ['build_with_mozilla==1', {
         'defines': [
           # Changes settings for Mozilla build.
diff --git a/webrtc/system_wrappers/interface/logging.h b/webrtc/system_wrappers/interface/logging.h
index c265245..1085fef 100644
--- a/webrtc/system_wrappers/interface/logging.h
+++ b/webrtc/system_wrappers/interface/logging.h
@@ -79,9 +79,6 @@
   std::ostream& stream() { return print_stream_; }
 
  private:
-  // These assist in formatting some parts of the debug output.
-  static const char* DescribeFile(const char* file);
-
   // The ostream that buffers the formatted message before output
   std::ostringstream print_stream_;
 
@@ -90,22 +87,11 @@
 };
 
 //////////////////////////////////////////////////////////////////////
-// Macros which automatically disable logging when LOGGING == 0
+// Macros which automatically disable logging when WEBRTC_LOGGING == 0
 //////////////////////////////////////////////////////////////////////
 
-// If LOGGING is not explicitly defined, default to enabled in debug mode
-// TODO(andrew): We explictly enable here; handle in gyp instead.
-#define LOGGING 1
-#if !defined(LOGGING)
-#if defined(_DEBUG) && !defined(NDEBUG)
-#define LOGGING 1
-#else
-#define LOGGING 0
-#endif
-#endif  // !defined(LOGGING)
-
 #ifndef LOG
-#if LOGGING
+#if defined(WEBRTC_LOGGING)
 
 // The following non-obvious technique for implementation of a
 // conditional log stream was stolen from google3/base/logging.h.
@@ -137,7 +123,7 @@
 #define LOG_F(sev) LOG(sev) << __FUNCTION__ << ": "
 #endif
 
-#else  // !LOGGING
+#else  // !defined(WEBRTC_LOGGING)
 
 // Hopefully, the compiler will optimize away some of this code.
 // Note: syntax of "1 ? (void)0 : LogMessage" was causing errors in g++,
@@ -148,7 +134,7 @@
   while (false) webrtc::LogMessage(NULL, 0, sev).stream()
 #define LOG_F(sev) LOG(sev) << __FUNCTION__ << ": "
 
-#endif  // !LOGGING
+#endif  // !defined(WEBRTC_LOGGING)
 
 #define LOG_API0() LOG_F(LS_VERBOSE)
 #define LOG_API1(v1) LOG_API0() << #v1 << "=" << v1
diff --git a/webrtc/system_wrappers/source/logging.cc b/webrtc/system_wrappers/source/logging.cc
index bb118fc..19c5cef 100644
--- a/webrtc/system_wrappers/source/logging.cc
+++ b/webrtc/system_wrappers/source/logging.cc
@@ -11,14 +11,15 @@
 #include "webrtc/system_wrappers/interface/logging.h"
 
 #include <string.h>
-#include <iostream>
+#include <sstream>
 
 #include "webrtc/common_types.h"
 #include "webrtc/system_wrappers/interface/trace.h"
 
 namespace webrtc {
+namespace {
 
-static TraceLevel WebRtcSeverity(LoggingSeverity sev) {
+TraceLevel WebRtcSeverity(LoggingSeverity sev) {
   switch (sev) {
     // TODO(andrew): SENSITIVE doesn't have a corresponding webrtc level.
     case LS_SENSITIVE:  return kTraceInfo;
@@ -30,6 +31,17 @@
   }
 }
 
+const char* DescribeFile(const char* file) {
+  const char* end1 = ::strrchr(file, '/');
+  const char* end2 = ::strrchr(file, '\\');
+  if (!end1 && !end2)
+    return file;
+  else
+    return (end1 > end2) ? end1 + 1 : end2 + 1;
+}
+
+}  // namespace
+
 LogMessage::LogMessage(const char* file, int line, LoggingSeverity sev)
     : severity_(sev) {
   print_stream_ << "(" << DescribeFile(file) << ":" << line << "): ";
@@ -40,13 +52,4 @@
   WEBRTC_TRACE(WebRtcSeverity(severity_), kTraceUndefined, 0, str.c_str());
 }
 
-const char* LogMessage::DescribeFile(const char* file) {
-  const char* end1 = ::strrchr(file, '/');
-  const char* end2 = ::strrchr(file, '\\');
-  if (!end1 && !end2)
-    return file;
-  else
-    return (end1 > end2) ? end1 + 1 : end2 + 1;
-}
-
 }  // namespace webrtc
diff --git a/webrtc/system_wrappers/source/logging_no_op.cc b/webrtc/system_wrappers/source/logging_no_op.cc
new file mode 100644
index 0000000..be0f799
--- /dev/null
+++ b/webrtc/system_wrappers/source/logging_no_op.cc
@@ -0,0 +1,23 @@
+/*
+ *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/system_wrappers/interface/logging.h"
+
+namespace webrtc {
+
+LogMessage::LogMessage(const char*, int, LoggingSeverity) {
+  // Avoid an unused-private-field warning.
+  (void)severity_;
+}
+
+LogMessage::~LogMessage() {
+}
+
+}  // namespace webrtc
diff --git a/webrtc/system_wrappers/source/logging_unittest.cc b/webrtc/system_wrappers/source/logging_unittest.cc
index 6f36aba..8d8a580 100644
--- a/webrtc/system_wrappers/source/logging_unittest.cc
+++ b/webrtc/system_wrappers/source/logging_unittest.cc
@@ -73,7 +73,7 @@
     std::string msg = "Important message";
     expected_log_ << "(logging_unittest.cc:" << __LINE__ + 1 << "): " << msg;
     LOG(LS_WARNING) << msg;
-    cv_->SleepCS(*crit_.get());
+    cv_->SleepCS(*crit_.get(), 2000);
   }
 }
 
@@ -86,7 +86,7 @@
     expected_log_ << "(logging_unittest.cc:" << __LINE__ + 2
                   << "): Foo failed: bar=" << bar << ", baz=" << baz;
     LOG_FERR2(LS_ERROR, Foo, bar, baz);
-    cv_->SleepCS(*crit_.get());
+    cv_->SleepCS(*crit_.get(), 2000);
   }
 }
 
diff --git a/webrtc/system_wrappers/source/system_wrappers.gyp b/webrtc/system_wrappers/source/system_wrappers.gyp
index 0a29d0e..4ce148b 100644
--- a/webrtc/system_wrappers/source/system_wrappers.gyp
+++ b/webrtc/system_wrappers/source/system_wrappers.gyp
@@ -85,6 +85,7 @@
         'file_impl.h',
         'list_no_stl.cc',
         'logging.cc',
+        'logging_no_op.cc',
         'map.cc',
         'rw_lock.cc',
         'rw_lock_generic.cc',
@@ -118,10 +119,12 @@
         },],
         ['enable_tracing==1', {
           'sources!': [
+            'logging_no_op.cc',
             'trace_impl_no_op.cc',
           ],
         }, {
           'sources!': [
+            'logging.cc',
             'trace_impl.cc',
             'trace_impl.h',
             'trace_posix.cc',