etch-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vei...@apache.org
Subject svn commit: r1578866 - in /etch/trunk/binding-cpp/runtime: CMakeLists.txt include/support/EtchRuntime.h include/util/EtchLogger.h src/main/support/EtchRuntime.cpp src/test/support/EtchRuntimeTest.cpp
Date Tue, 18 Mar 2014 13:22:21 GMT
Author: veithm
Date: Tue Mar 18 13:22:21 2014
New Revision: 1578866

URL: http://svn.apache.org/r1578866
Log:
ETCH-282 Runtime accepts now log configuration

A new constructor for the EtchRuntime has been added.
It enables the client/server to register a different log appender for
different log levels.
This is especially useful if you e.g. would like to log errors to your console,
but log info and debug messages to a file.

Change-Id: I0952b4019ef8dc9c5a227fa18a60cc3f5e428058

Modified:
    etch/trunk/binding-cpp/runtime/CMakeLists.txt
    etch/trunk/binding-cpp/runtime/include/support/EtchRuntime.h
    etch/trunk/binding-cpp/runtime/include/util/EtchLogger.h
    etch/trunk/binding-cpp/runtime/src/main/support/EtchRuntime.cpp
    etch/trunk/binding-cpp/runtime/src/test/support/EtchRuntimeTest.cpp

Modified: etch/trunk/binding-cpp/runtime/CMakeLists.txt
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/CMakeLists.txt?rev=1578866&r1=1578865&r2=1578866&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/CMakeLists.txt (original)
+++ etch/trunk/binding-cpp/runtime/CMakeLists.txt Tue Mar 18 13:22:21 2014
@@ -41,12 +41,12 @@ ENDIF (NOT CMAKE_TOOLCHAIN_FILE)
 #VLD
 SET(VLD ${ETCH_EXTERNAL_DEPENDS}/vld/1.9h)
 
-# GTest
-SET(GTEST ${ETCH_EXTERNAL_DEPENDS}/gtest/1.6.0)
-
 # GMock
 SET(GMOCK ${ETCH_EXTERNAL_DEPENDS}/gmock/1.6.0)
 
+# GTest
+SET(GTEST ${GMOCK}/gtest)
+
 #Build external CAPU project (OS Abstraction)
 set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
 find_package(Capu)

Modified: etch/trunk/binding-cpp/runtime/include/support/EtchRuntime.h
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/include/support/EtchRuntime.h?rev=1578866&r1=1578865&r2=1578866&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/include/support/EtchRuntime.h (original)
+++ etch/trunk/binding-cpp/runtime/include/support/EtchRuntime.h Tue Mar 18 13:22:21 2014
@@ -43,10 +43,18 @@ public:
 
   /**
    * Create a new instance of the EtchRuntime class
+   * It uses the default Console Log Appender for logging.
    */
   EtchRuntime();
 
   /**
+   * Create a new instance of the EtchRuntime class
+   * @param logAppender the log appender
+   * @param logLevel the log level
+   */
+  EtchRuntime(IEtchLogAppender& logAppender, EtchLogLevel logLevel);
+
+  /**
    * Destructor
    */
   virtual ~EtchRuntime();
@@ -94,12 +102,18 @@ public:
 private:
   capu::bool_t mIsClosed;
   EtchLogger mLogger;
-  EtchConsoleLogAppender mLogAppender;
+  EtchConsoleLogAppender mDefaultLogAppender;
   static capu::uint64_t sId;
   capu::uint64_t mId;
   capu::Mutex mMutex;
   capu::List<EtchRuntimeListener*> mListeners;
 
+
+  /**
+   * Assigns an unique id to the runtime
+   */
+  void generateRuntimeId();
+
   /**
    * Return the next id
    */

Modified: etch/trunk/binding-cpp/runtime/include/util/EtchLogger.h
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/include/util/EtchLogger.h?rev=1578866&r1=1578865&r2=1578866&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/include/util/EtchLogger.h (original)
+++ etch/trunk/binding-cpp/runtime/include/util/EtchLogger.h Tue Mar 18 13:22:21 2014
@@ -25,6 +25,7 @@
 #include "capu/util/ILogAppender.h"
 
 typedef capu::ILogAppender IEtchLogAppender;
+typedef capu::ELogLevel EtchLogLevel;
 typedef capu::ConsoleLogAppender EtchConsoleLogAppender;
 typedef capu::LogContext EtchLogContext;
 
@@ -82,14 +83,14 @@ public:
     return mRuntimeContext;
   }
 private:
-  EtchLogContext mSerializerContext;
-  EtchLogContext mDeliveryServiceContext;
-  EtchLogContext mTransportContext;
-  EtchLogContext mPacketizerContext;
-  EtchLogContext mMessagizerContext;
-  EtchLogContext mValidatorContext;
-  EtchLogContext mMailboxContext;
-  EtchLogContext mRuntimeContext;
+  EtchLogContext& mSerializerContext;
+  EtchLogContext& mDeliveryServiceContext;
+  EtchLogContext& mTransportContext;
+  EtchLogContext& mPacketizerContext;
+  EtchLogContext& mMessagizerContext;
+  EtchLogContext& mValidatorContext;
+  EtchLogContext& mMailboxContext;
+  EtchLogContext& mRuntimeContext;
 
 };
 

Modified: etch/trunk/binding-cpp/runtime/src/main/support/EtchRuntime.cpp
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/main/support/EtchRuntime.cpp?rev=1578866&r1=1578865&r2=1578866&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/src/main/support/EtchRuntime.cpp (original)
+++ etch/trunk/binding-cpp/runtime/src/main/support/EtchRuntime.cpp Tue Mar 18 13:22:21 2014
@@ -23,13 +23,24 @@
 
 EtchRuntime::EtchRuntime()
   :   mIsClosed(false)
-    , mLogger(mLogAppender)
+    , mLogger(mDefaultLogAppender)
 {
-  mMutex.lock();
-  mId = getNextId();
-  mMutex.unlock();
+  //Default log level is WARN
+  mLogger.setLogLevel(capu::LL_WARN);
 
-  mLogger.setLogLevel(capu::LL_ALL);
+  //assign a unique id to this runtime
+  generateRuntimeId();
+}
+
+EtchRuntime::EtchRuntime(IEtchLogAppender& logAppender, EtchLogLevel logLevel)
+  :   mIsClosed(false)
+    , mLogger(logAppender)
+{
+  //Default log level is WARN
+  mLogger.setLogLevel(logLevel);
+
+  //assign a unique id to this runtime
+  generateRuntimeId();
 }
 
 EtchRuntime::~EtchRuntime() {
@@ -94,6 +105,12 @@ status_t EtchRuntime::fireOnRuntimeChang
   return ETCH_OK;
 }
 
+void EtchRuntime::generateRuntimeId() {
+  mMutex.lock();
+  mId = getNextId();
+  mMutex.unlock();
+}
+
 capu::uint64_t EtchRuntime::getNextId() {
   static capu::uint64_t sId = 0;
   return sId++;

Modified: etch/trunk/binding-cpp/runtime/src/test/support/EtchRuntimeTest.cpp
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/test/support/EtchRuntimeTest.cpp?rev=1578866&r1=1578865&r2=1578866&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/src/test/support/EtchRuntimeTest.cpp (original)
+++ etch/trunk/binding-cpp/runtime/src/test/support/EtchRuntimeTest.cpp Tue Mar 18 13:22:21
2014
@@ -18,6 +18,12 @@
 #include "gtest/gtest.h"
 #include "gmock/gmock.h"
 #include "support/EtchRuntime.h"
+#include "capu/util/LogMessage.h"
+
+class MockLogAppender : public IEtchLogAppender {
+public:
+  MOCK_METHOD1(log, void(const capu::LogMessage& message));
+};
 
 capu::uint64_t currentIdCount;
 
@@ -27,13 +33,30 @@ TEST(EtchRuntime, Default) {
   delete runtime;
 }
 
-TEST(EtchRuntime, getId) {
-  EtchRuntime* runtime = new EtchRuntime(); //ID = 1
-  EXPECT_EQ(currentIdCount + 1, runtime->getId());
+TEST(EtchRuntime, Logging) {
+  MockLogAppender* logAppender = new MockLogAppender();
+
+  EtchRuntime* runtime = new EtchRuntime(*logAppender, capu::LL_ALL); //ID = 2
+
+  EXPECT_CALL(*logAppender, log(::testing::_)).Times(2);
+
+  EtchLogContext testContext = runtime->getLogger().createContext("testcontext");
+  testContext.setLogLevel(capu::LL_ALL);
+
+  ETCH_LOG_DEBUG(runtime->getLogger(), testContext, "test log message for runtime " <<
runtime->getId());
+  ETCH_LOG_DEBUG(runtime->getLogger(), runtime->getLogger().getMessagizerContext(),
"test log message for runtime " << runtime->getId());
+
   delete runtime;
-  runtime = new EtchRuntime(); //ID = 2
+  delete logAppender;
+}
+
+TEST(EtchRuntime, getId) {
+  EtchRuntime* runtime = new EtchRuntime(); //ID = 3
   EXPECT_EQ(currentIdCount + 2, runtime->getId());
   delete runtime;
+  runtime = new EtchRuntime(); //ID = 4
+  EXPECT_EQ(currentIdCount + 3, runtime->getId());
+  delete runtime;
 }
 
 TEST(EtchRuntime, isClosed) {



Mime
View raw message