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

rmiddleton pushed a commit to branch LOGCXX-518
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


The following commit(s) were added to refs/heads/LOGCXX-518 by this push:
     new 4bb7a172 made the multiprocessrollingfileappender optional
4bb7a172 is described below

commit 4bb7a1722dd49f2bc6d6449427601a5e280d8718
Author: Robert Middleton <[email protected]>
AuthorDate: Sun Oct 23 13:10:31 2022 -0400

    made the multiprocessrollingfileappender optional
---
 CMakeLists.txt                                     |  1 +
 src/main/cpp/CMakeLists.txt                        | 15 +++++---
 src/main/cpp/timebasedrollingpolicy.cpp            | 43 +++++++++++++++++++---
 src/main/include/CMakeLists.txt                    |  7 ++++
 src/main/include/log4cxx/log4cxx.h.in              |  1 +
 .../log4cxx/rolling/timebasedrollingpolicy.h       |  1 -
 6 files changed, 57 insertions(+), 11 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f67d1c6b..2dc1f16b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -288,3 +288,4 @@ message(STATUS "  OutputDebugStringAppender ....... : 
${LOG4CXX_NETWORKING_SUPPO
 message(STATUS "  ConsoleAppender ................. : ON")
 message(STATUS "  FileAppender .................... : ON")
 message(STATUS "  RollingFileAppender ............. : ON")
+message(STATUS "  MultiprocessRollingFileAppender . : 
${LOG4CXX_MULTIPROCESS_ROLLING_FILE_APPENDER}")
diff --git a/src/main/cpp/CMakeLists.txt b/src/main/cpp/CMakeLists.txt
index 4460144c..99066a10 100644
--- a/src/main/cpp/CMakeLists.txt
+++ b/src/main/cpp/CMakeLists.txt
@@ -27,8 +27,10 @@ else()
 endif()
 add_dependencies(log4cxx configure_log4cxx)
 
+set(extra_classes "")
+
 if(LOG4CXX_NETWORKING_SUPPORT)
-    set(networking_classes
+    set(extra_classes ${extra_classes}
        datagrampacket.cpp
        datagramsocket.cpp
        aprdatagramsocket.cpp
@@ -44,8 +46,12 @@ if(LOG4CXX_NETWORKING_SUPPORT)
        syslogwriter.cpp
        syslogappender.cpp
        )
-else()
-    set(networking_classes "")
+endif()
+
+if()
+    set(extra_classes ${extra_classes}
+       multiprocessrollingfileappender.cpp
+       )
 endif()
 
 target_sources(log4cxx
@@ -128,7 +134,6 @@ target_sources(log4cxx
   messagebuffer.cpp
   messagepatternconverter.cpp
   methodlocationpatternconverter.cpp
-  multiprocessrollingfileappender.cpp
   nameabbreviator.cpp
   namepatternconverter.cpp
   ndc.cpp
@@ -186,7 +191,7 @@ target_sources(log4cxx
   writerappender.cpp
   xmllayout.cpp
   zipcompressaction.cpp
-  ${networking_classes}
+  ${extra_classes}
 )
 set_target_properties(log4cxx PROPERTIES
   VERSION ${LIBLOG4CXX_LIB_VERSION}
diff --git a/src/main/cpp/timebasedrollingpolicy.cpp 
b/src/main/cpp/timebasedrollingpolicy.cpp
index 15ca7563..1d13d93b 100644
--- a/src/main/cpp/timebasedrollingpolicy.cpp
+++ b/src/main/cpp/timebasedrollingpolicy.cpp
@@ -18,6 +18,7 @@
        #pragma warning ( disable: 4231 4251 4275 4786 )
 #endif
 
+#include <log4cxx/log4cxx.h>
 #include <log4cxx/logstring.h>
 #include <log4cxx/rolling/timebasedrollingpolicy.h>
 #include <log4cxx/pattern/filedatepatternconverter.h>
@@ -32,6 +33,7 @@
 #include <log4cxx/fileappender.h>
 #include <log4cxx/boost-std-configuration.h>
 #include <iostream>
+#include <apr_mmap.h>
 
 using namespace log4cxx;
 using namespace log4cxx::rolling;
@@ -41,12 +43,16 @@ using namespace log4cxx::pattern;
 IMPLEMENT_LOG4CXX_OBJECT(TimeBasedRollingPolicy)
 
 struct TimeBasedRollingPolicy::TimeBasedRollingPolicyPrivate{
+#if LOG4CXX_HAS_MULTIPROCESS_ROLLING_FILE_APPENDER
        TimeBasedRollingPolicyPrivate() :
                _mmap(nullptr),
                _file_map(nullptr),
                _lock_file(nullptr),
                bAlreadyInitialized(false),
                bRefreshCurFile(false){}
+#else
+       TimeBasedRollingPolicyPrivate(){}
+#endif
 
                /**
                 * Time for next determination if time for rollover.
@@ -58,6 +64,11 @@ struct TimeBasedRollingPolicy::TimeBasedRollingPolicyPrivate{
                 */
                LogString lastFileName;
 
+               /**
+                * Length of any file type suffix (.gz, .zip).
+                */
+               int suffixLength;
+
                /**
                 * mmap pointer
                 */
@@ -103,11 +114,6 @@ struct 
TimeBasedRollingPolicy::TimeBasedRollingPolicyPrivate{
                 * */
                LogString _fileNamePattern;
 
-               /**
-                * Length of any file type suffix (.gz, .zip).
-                */
-               int suffixLength;
-
                bool multiprocess = false;
 };
 
@@ -116,6 +122,7 @@ struct 
TimeBasedRollingPolicy::TimeBasedRollingPolicyPrivate{
 #define LOCK_FILE_SUFFIX ".maplck"
 #define MAX_FILE_LEN 2048
 
+#if LOG4CXX_HAS_MULTIPROCESS_ROLLING_FILE_APPENDER
 bool TimeBasedRollingPolicy::isMapFileEmpty(log4cxx::helpers::Pool& pool)
 {
        apr_finfo_t finfo;
@@ -235,6 +242,29 @@ int TimeBasedRollingPolicy::unLockMMapFile()
 
        return stat;
 }
+#else
+int TimeBasedRollingPolicy::createMMapFile(const std::string&, 
log4cxx::helpers::Pool&) {
+       return 0;
+}
+
+bool TimeBasedRollingPolicy::isMapFileEmpty(log4cxx::helpers::Pool&){
+       return true;
+}
+
+void TimeBasedRollingPolicy::initMMapFile(const LogString&, 
log4cxx::helpers::Pool&){}
+
+int TimeBasedRollingPolicy::lockMMapFile(int){
+       return 0;
+}
+
+int TimeBasedRollingPolicy::unLockMMapFile(){
+       return 0;
+}
+
+const std::string TimeBasedRollingPolicy::createFile(const std::string&, const 
std::string&, log4cxx::helpers::Pool&){
+       return "";
+}
+#endif
 
 TimeBasedRollingPolicy::TimeBasedRollingPolicy() :
        m_priv(std::make_unique<TimeBasedRollingPolicyPrivate>())
@@ -483,5 +513,8 @@ bool TimeBasedRollingPolicy::isTriggeringEvent(
 }
 
 void TimeBasedRollingPolicy::setMultiprocess(bool multiprocess){
+#if LOG4CXX_HAS_MULTIPROCESS_ROLLING_FILE_APPENDER
+       // If we don't have the multiprocess stuff, disregard any attempt to 
set this value
        m_priv->multiprocess = multiprocess;
+#endif
 }
diff --git a/src/main/include/CMakeLists.txt b/src/main/include/CMakeLists.txt
index dc168818..06dabcf4 100644
--- a/src/main/include/CMakeLists.txt
+++ b/src/main/include/CMakeLists.txt
@@ -65,6 +65,13 @@ else()
     set(NETWORKING_SUPPORT 0)
 endif()
 
+option(LOG4CXX_MULTIPROCESS_ROLLING_FILE_APPENDER "Support multiple processes 
logging to the same file" OFF)
+if(LOG4CXX_MULTIPROCESS_ROLLING_FILE_APPENDER)
+    set(MULTIPROCESS_RFA 1)
+else()
+    set(MULTIPROCESS_RFA 0)
+endif()
+
 # Configure log4cxx_private.h
 set(LOG4CXX_CHARSET "locale" CACHE STRING "LogString characters, choice of 
locale (default), utf-8, ISO-8859-1, US-ASCII, EBCDIC")
 set_property(CACHE LOG4CXX_CHARSET PROPERTY STRINGS "locale" "utf-8" 
"ISO-8859-1" "US-ASCII" "EBCDIC")
diff --git a/src/main/include/log4cxx/log4cxx.h.in 
b/src/main/include/log4cxx/log4cxx.h.in
index 663157a6..88470937 100644
--- a/src/main/include/log4cxx/log4cxx.h.in
+++ b/src/main/include/log4cxx/log4cxx.h.in
@@ -49,6 +49,7 @@
 #define LOG4CXX_UNICHAR_API @UNICHAR_API@
 #define LOG4CXX_CFSTRING_API @CFSTRING_API@
 #define LOG4CXX_HAS_NETWORKING @NETWORKING_SUPPORT@
+#define LOG4CXX_HAS_MULTIPROCESS_ROLLING_FILE_APPENDER @MULTIPROCESS_RFA@
 
 typedef long long log4cxx_int64_t;
 #define LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE 0
diff --git a/src/main/include/log4cxx/rolling/timebasedrollingpolicy.h 
b/src/main/include/log4cxx/rolling/timebasedrollingpolicy.h
index db60fb0d..6809bbe6 100755
--- a/src/main/include/log4cxx/rolling/timebasedrollingpolicy.h
+++ b/src/main/include/log4cxx/rolling/timebasedrollingpolicy.h
@@ -23,7 +23,6 @@
 #include <log4cxx/rolling/triggeringpolicy.h>
 #include <log4cxx/writerappender.h>
 #include <log4cxx/helpers/outputstream.h>
-#include <apr_mmap.h>
 #include <functional>
 
 #if defined(_MSC_VER)

Reply via email to