This is an automated email from the ASF dual-hosted git repository.

mkevo pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 932a64f  GEODE-8364: Change log level at runtime (#629)
932a64f is described below

commit 932a64fd019b4049b910424249598e76c5f7c742
Author: Alberto Bustamante Reyes <alb3rt...@users.noreply.github.com>
AuthorDate: Tue Aug 18 09:38:09 2020 +0200

    GEODE-8364: Change log level at runtime (#629)
    
    * GEODE-8364: Change log level at runtime
    
    * Change log level in system properties
---
 cppcache/include/geode/Cache.hpp            | 13 +++++++++++++
 cppcache/include/geode/SystemProperties.hpp |  5 +++++
 cppcache/src/Cache.cpp                      |  7 +++++++
 cppcache/test/CacheTest.cpp                 |  8 ++++++++
 4 files changed, 33 insertions(+)

diff --git a/cppcache/include/geode/Cache.hpp b/cppcache/include/geode/Cache.hpp
index dd6399c..5ffdc45 100644
--- a/cppcache/include/geode/Cache.hpp
+++ b/cppcache/include/geode/Cache.hpp
@@ -22,6 +22,8 @@
 
 #include <string>
 
+#include <geode/util/LogLevel.hpp>
+
 #include "GeodeCache.hpp"
 #include "internal/geode_globals.hpp"
 
@@ -239,6 +241,17 @@ class APACHE_GEODE_EXPORT Cache : public GeodeCache {
 
   SystemProperties& getSystemProperties() const override;
 
+  /**
+   * Changes the current log level to newLogLevel.
+   */
+  void setLogLevel(LogLevel newLevel);
+
+  /**
+   * Returns the current log level.
+   * @return the current log level.
+   */
+  LogLevel getLogLevel();
+
   Cache() = delete;
   virtual ~Cache();
   Cache(const Cache& other) = delete;
diff --git a/cppcache/include/geode/SystemProperties.hpp 
b/cppcache/include/geode/SystemProperties.hpp
index b116122..a2f9c35 100644
--- a/cppcache/include/geode/SystemProperties.hpp
+++ b/cppcache/include/geode/SystemProperties.hpp
@@ -127,6 +127,11 @@ class APACHE_GEODE_EXPORT SystemProperties {
   LogLevel logLevel() const { return m_logLevel; }
 
   /**
+   * Changes the current log level to newLogLevel.
+   */
+  void setLogLevel(LogLevel newLogLevel) { m_logLevel = newLogLevel; }
+
+  /**
    * Returns a boolean that specifies if heapLRULimit has been enabled for the
    * process. If enabled, the HeapLRULimit specifies the maximum amount of
    * memory
diff --git a/cppcache/src/Cache.cpp b/cppcache/src/Cache.cpp
index 512c8fe..c3bba33 100644
--- a/cppcache/src/Cache.cpp
+++ b/cppcache/src/Cache.cpp
@@ -144,6 +144,13 @@ bool Cache::getPdxReadSerialized() const {
   return m_cacheImpl->getPdxReadSerialized();
 }
 
+void Cache::setLogLevel(LogLevel newLevel) {
+  Log::setLogLevel(newLevel);
+  this->getSystemProperties().setLogLevel(newLevel);
+}
+
+LogLevel Cache::getLogLevel() { return Log::logLevel(); }
+
 PdxInstanceFactory Cache::createPdxInstanceFactory(
     const std::string& className) const {
   return m_cacheImpl->createPdxInstanceFactory(className);
diff --git a/cppcache/test/CacheTest.cpp b/cppcache/test/CacheTest.cpp
index 7b51843..bd1fa8e 100644
--- a/cppcache/test/CacheTest.cpp
+++ b/cppcache/test/CacheTest.cpp
@@ -25,6 +25,7 @@
 
 using apache::geode::client::CacheClosedException;
 using apache::geode::client::CacheFactory;
+using apache::geode::client::LogLevel;
 using apache::geode::client::RegionShortcut;
 
 /**
@@ -61,3 +62,10 @@ TEST(CacheTest, close) {
   EXPECT_THROW(cache.readyForEvents(), CacheClosedException);
   EXPECT_THROW(cache.rootRegions(), CacheClosedException);
 }
+
+TEST(CacheTest, changeLogLevel) {
+  auto cache = CacheFactory{}.set("log-level", "info").create();
+  ASSERT_EQ(cache.getLogLevel(), LogLevel::Info);
+  cache.setLogLevel(LogLevel::Debug);
+  ASSERT_EQ(cache.getLogLevel(), LogLevel::Debug);
+}

Reply via email to