resource: Disable logging if not enabled
authorPhilippe Coval <philippe.coval@osg.samsung.com>
Mon, 13 Mar 2017 08:39:46 +0000 (09:39 +0100)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Mon, 27 Mar 2017 21:38:01 +0000 (21:38 +0000)
Curently without logging (LOGGING=False or undefined)
some trace messages are appearing:

  0:
  In entity handler wrapper:

Now with this change those log lines are sent to null stream.

Change-Id: I26892c7ca6efca025c24e762305d59589ca26543
Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17869
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
resource/oc_logger/cpp/oc_ostream_logger.cpp
resource/src/OCApi.cpp

index 8134940..270a4c1 100644 (file)
@@ -67,7 +67,14 @@ try
  auto *target = reinterpret_cast<std::ostream *>(world);
 
  if(nullptr == world)
+ {
+#ifdef TB_LOG
   target = &std::cout;
+#else
+  static std::ostream nullstream(0);
+  target = &nullstream;
+#endif
+ }
 
  oc_ostream_logger_ctx *my_ctx = new oc_ostream_logger_ctx(target);
 
index 529573f..bc5c969 100644 (file)
@@ -28,7 +28,12 @@ namespace OC
 {
     std::ostream& oclog()
     {
+#ifdef TB_LOG
         return std::cout;
+#else
+        static std::ostream nullstream(0);
+        return nullstream;
+#endif
     }
 }
 #endif