[ 
https://issues.apache.org/jira/browse/GEODE-8806?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17262706#comment-17262706
 ] 

ASF GitHub Bot commented on GEODE-8806:
---------------------------------------

pdxcodemonkey commented on a change in pull request #718:
URL: https://github.com/apache/geode-native/pull/718#discussion_r555109762



##########
File path: cppcache/test/LoggingTest.cpp
##########
@@ -0,0 +1,759 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <map>
+#include <string>
+#include <util/Log.hpp>
+
+#include <boost/filesystem.hpp>
+#include <boost/regex.hpp>
+
+#include <gtest/gtest.h>
+
+#include <geode/AuthenticatedView.hpp>
+#include <geode/Cache.hpp>
+#include <geode/PoolManager.hpp>
+#include <geode/RegionFactory.hpp>
+#include <geode/RegionShortcut.hpp>
+
+using apache::geode::client::CacheClosedException;
+using apache::geode::client::CacheFactory;
+using apache::geode::client::LogLevel;
+using apache::geode::client::RegionShortcut;
+
+namespace {
+
+const auto __1K__ = 1024;
+const auto __4K__ = 4 * __1K__;
+const auto __1M__ = (__1K__ * __1K__);
+const auto __1G__ = (__1K__ * __1K__ * __1K__);
+
+const auto LENGTH_OF_BANNER = 16;
+
+auto testLogFileName = std::string("LoggingTest.log");
+
+const char* __1KStringLiteral =
+    "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
+    "AA"
+    "AA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
+
+class LoggingTest : public testing::Test {
+  void scrubTestLogFiles() {
+    // Close logger, just in case
+    apache::geode::client::Log::close();
+
+    if (boost::filesystem::exists(testLogFileName)) {
+      boost::filesystem::remove(testLogFileName);
+    }
+
+    std::map<int32_t, boost::filesystem::path> rolledFiles;
+    LoggingTest::findRolledFiles(boost::filesystem::current_path().string(),
+                                 rolledFiles);
+    for (auto& item : rolledFiles) {
+      boost::filesystem::remove(item.second);
+    }
+  }
+
+  virtual void SetUp() { scrubTestLogFiles(); }
+
+  virtual void TearDown() { scrubTestLogFiles(); }
+
+ public:
+  static void writeRolledLogFile(const boost::filesystem::path& logdir,
+                                 int32_t rollIndex) {
+    auto rolledPath =
+        logdir / boost::filesystem::path("LoggingTest-" +
+                                         std::to_string(rollIndex) + ".log");
+    auto rolledFile = fopen(rolledPath.string().c_str(), "w");
+    fwrite("Test", 1, 4, rolledFile);
+    fclose(rolledFile);
+  }
+
+  static int numOfLinesInFile(const char* fname) {
+    char line[2048];
+    char* read;
+    int ln_cnt = 0;
+    FILE* fp = fopen(fname, "r");
+    if (fp == nullptr) {
+      return 0;
+    }
+    while (!!(read = fgets(line, sizeof line, fp))) {
+      ++ln_cnt;
+    }
+
+    if (!feof(fp)) {
+      fclose(fp);
+      return -2;
+    }
+    fclose(fp);
+    return ln_cnt;
+  }
+
+  static int expected(LogLevel level) {
+    int expected = static_cast<int>(level);
+    if (level >= LogLevel::Default) {
+      expected--;
+    }
+    return expected;
+  }
+
+  static int expectedWithBanner(LogLevel level) {
+    int expected = LoggingTest::expected(level);
+    if (level != LogLevel::None) {
+      expected += LENGTH_OF_BANNER;
+    }
+    return expected;
+  }
+
+  static void verifyLineCountAtLevel(LogLevel level) {
+    apache::geode::client::Log::init(level, testLogFileName);
+
+    apache::geode::client::Log::error("Error Message");
+    apache::geode::client::Log::warning("Warning Message");
+    apache::geode::client::Log::info("Info Message");
+    apache::geode::client::Log::config("Config Message");
+    apache::geode::client::Log::fine("Fine Message");
+    apache::geode::client::Log::finer("Finer Message");
+    apache::geode::client::Log::finest("Finest Message");
+    apache::geode::client::Log::debug("Debug Message");
+
+    int lines = LoggingTest::numOfLinesInFile(testLogFileName.c_str());
+
+    ASSERT_TRUE(lines == LoggingTest::expectedWithBanner(level));
+
+    apache::geode::client::Log::close();
+    boost::filesystem::remove(testLogFileName.c_str());
+  }
+
+  static void findRolledFiles(
+      const std::string& logFilePath,
+      std::map<int32_t, boost::filesystem::path>& rolledFiles) {
+    const auto basePath =
+        boost::filesystem::absolute(boost::filesystem::path(logFilePath)) /
+        testLogFileName;
+    const auto filterstring = basePath.stem().string() + "-(\\d+)\\.log$";
+    const boost::regex my_filter(filterstring);
+
+    rolledFiles.clear();
+
+    boost::filesystem::directory_iterator end_itr;
+    for (boost::filesystem::directory_iterator i(
+             basePath.parent_path().string());
+         i != end_itr; ++i) {
+      if (boost::filesystem::is_regular_file(i->status())) {
+        std::string filename = i->path().filename().string();
+        boost::regex testPattern(filterstring);
+        boost::match_results<std::string::const_iterator> testMatches;
+        if (boost::regex_search(std::string::const_iterator(filename.begin()),
+                                filename.cend(), testMatches, testPattern)) {
+          auto index = std::atoi(
+              std::string(testMatches[1].first, 
testMatches[1].second).c_str());
+          rolledFiles[index] = i->path();
+        }
+      }
+    }
+  }
+
+  void testLogFnError() {
+#ifdef WIN32

Review comment:
       Removed it.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Native client does not honor log-file-size-limit properly
> ---------------------------------------------------------
>
>                 Key: GEODE-8806
>                 URL: https://issues.apache.org/jira/browse/GEODE-8806
>             Project: Geode
>          Issue Type: Bug
>          Components: native client
>            Reporter: Blake Bender
>            Priority: Major
>              Labels: pull-request-available
>
> As a user, I need to be able to limit the size of my log files and the amount 
> of disk space used by geode-native.  Unfortunately, the 10.x native client 
> doesn't appear to "roll" log files correctly.  
>  
> repro steps:
> i. In a client application, set `log-file-size-limit` to 1 (for 1MB), 
> `log-level` to `debug`, and `log-file` to something convenient like 
> `native_app.log`
> ii. Run a long operation in the client that will generate a huge amount of 
> logging, like 100,000 puts to a region
>  
> expected behavior:
>  * when native_app.log grows to > 1MB in size, it is followed by 
> native_app-1.log, native_app-2.log, etc, each of which is ~1MB in size
> actual behavior:
>  * native_app.log grows to > 1MB, then geode-native stops logging



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to