You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rm...@apache.org on 2022/10/22 13:34:56 UTC

[logging-log4cxx] branch LOGCXX-518 updated (f4efd85d -> 1649a225)

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

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


    from f4efd85d Broke out the multiprocess part of the rollingfileappender into a separate class
     new ebb9170a Directly tell the TimeBasedRollingPolicy if it is for multiprocess
     new 1649a225 Use std::filesystem

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 CMakeLists.txt                                     |  2 ++
 src/cmake/boost-fallback/boost-fallback.cmake      | 13 +++++++++++
 .../boost-fallback/boost-std-configuration.h.cmake | 18 ++++++++++++++++
 src/cmake/boost-fallback/test-boostfilesystem.cpp  |  6 ++++++
 src/cmake/boost-fallback/test-stdfilesystem.cpp    |  5 +++++
 src/main/cpp/CMakeLists.txt                        |  4 ++++
 src/main/cpp/multiprocessrollingfileappender.cpp   |  6 ++++++
 src/main/cpp/timebasedrollingpolicy.cpp            | 25 +++++++++++-----------
 src/main/include/CMakeLists.txt                    |  8 +++++++
 .../log4cxx/rolling/timebasedrollingpolicy.h       |  3 +--
 10 files changed, 75 insertions(+), 15 deletions(-)
 create mode 100644 src/cmake/boost-fallback/test-boostfilesystem.cpp
 create mode 100644 src/cmake/boost-fallback/test-stdfilesystem.cpp


[logging-log4cxx] 01/02: Directly tell the TimeBasedRollingPolicy if it is for multiprocess

Posted by rm...@apache.org.
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

commit ebb9170ab0316f9e167dd3cb4d4cd8d3561407a8
Author: Robert Middleton <ro...@rm5248.com>
AuthorDate: Wed Oct 19 09:17:14 2022 -0400

    Directly tell the TimeBasedRollingPolicy if it is for multiprocess
---
 src/main/cpp/multiprocessrollingfileappender.cpp          |  6 ++++++
 src/main/cpp/timebasedrollingpolicy.cpp                   | 12 ++----------
 src/main/include/log4cxx/rolling/timebasedrollingpolicy.h |  3 +--
 3 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/src/main/cpp/multiprocessrollingfileappender.cpp b/src/main/cpp/multiprocessrollingfileappender.cpp
index 5185ab67..6afe6a1f 100644
--- a/src/main/cpp/multiprocessrollingfileappender.cpp
+++ b/src/main/cpp/multiprocessrollingfileappender.cpp
@@ -40,6 +40,7 @@
 #include <log4cxx/rolling/manualtriggeringpolicy.h>
 #include <log4cxx/helpers/transcoder.h>
 #include <log4cxx/private/fileappender_priv.h>
+#include <log4cxx/rolling/timebasedrollingpolicy.h>
 #include <mutex>
 
 using namespace log4cxx;
@@ -560,6 +561,11 @@ TriggeringPolicyPtr MultiprocessRollingFileAppender::getTriggeringPolicy() const
 void MultiprocessRollingFileAppender::setRollingPolicy(const RollingPolicyPtr& policy)
 {
 	_priv->rollingPolicy = policy;
+
+	TimeBasedRollingPolicyPtr timeBased = log4cxx::cast<TimeBasedRollingPolicy>(policy);
+	if( timeBased ){
+		timeBased->setMultiprocess(true);
+	}
 }
 
 /**
diff --git a/src/main/cpp/timebasedrollingpolicy.cpp b/src/main/cpp/timebasedrollingpolicy.cpp
index cf32329d..ec2d6a64 100644
--- a/src/main/cpp/timebasedrollingpolicy.cpp
+++ b/src/main/cpp/timebasedrollingpolicy.cpp
@@ -475,14 +475,6 @@ bool TimeBasedRollingPolicy::isTriggeringEvent(
 	return Date::currentTime() > m_priv->nextCheck;
 }
 
-void TimeBasedRollingPolicy::setOption(const LogString& option,
-									   const LogString& value){
-	if (StringHelper::equalsIgnoreCase(option,
-			LOG4CXX_STR("MULTIPROCESS"),
-			LOG4CXX_STR("multiprocess")))
-	{
-		m_priv->multiprocess = OptionConverter::toBoolean(value, false);
-	}
-
-	RollingPolicyBase::setOption(option, value);
+void TimeBasedRollingPolicy::setMultiprocess(bool multiprocess){
+	m_priv->multiprocess = multiprocess;
 }
diff --git a/src/main/include/log4cxx/rolling/timebasedrollingpolicy.h b/src/main/include/log4cxx/rolling/timebasedrollingpolicy.h
index 8aaf60a7..db60fb0d 100755
--- a/src/main/include/log4cxx/rolling/timebasedrollingpolicy.h
+++ b/src/main/include/log4cxx/rolling/timebasedrollingpolicy.h
@@ -161,8 +161,7 @@ class LOG4CXX_EXPORT TimeBasedRollingPolicy : public RollingPolicyBase,
 		virtual ~TimeBasedRollingPolicy();
 		void activateOptions(log4cxx::helpers::Pool& );
 
-		void setOption(const LogString& option,
-					const LogString& value);
+		void setMultiprocess(bool multiprocess);
 
 		/**
 		 * {@inheritDoc}


[logging-log4cxx] 02/02: Use std::filesystem

Posted by rm...@apache.org.
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

commit 1649a22595f2bb4b13d4658efe2e2fc8741be970
Author: Robert Middleton <ro...@rm5248.com>
AuthorDate: Sat Oct 22 09:34:49 2022 -0400

    Use std::filesystem
---
 CMakeLists.txt                                         |  2 ++
 src/cmake/boost-fallback/boost-fallback.cmake          | 13 +++++++++++++
 .../boost-fallback/boost-std-configuration.h.cmake     | 18 ++++++++++++++++++
 src/cmake/boost-fallback/test-boostfilesystem.cpp      |  6 ++++++
 src/cmake/boost-fallback/test-stdfilesystem.cpp        |  5 +++++
 src/main/cpp/CMakeLists.txt                            |  4 ++++
 src/main/cpp/timebasedrollingpolicy.cpp                | 13 ++++++++++---
 src/main/include/CMakeLists.txt                        |  8 ++++++++
 8 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7accac18..f67d1c6b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -186,6 +186,7 @@ get_directory_property( SMART_PTR_IMPL DIRECTORY src/main/include DEFINITION SMA
 get_directory_property( MUTEX_IMPL DIRECTORY src/main/include DEFINITION MUTEX_IMPL )
 get_directory_property( SHARED_MUTEX_IMPL DIRECTORY src/main/include DEFINITION SHARED_MUTEX_IMPL )
 get_directory_property( ATOMIC_IMPL DIRECTORY src/main/include DEFINITION ATOMIC_IMPL )
+get_directory_property( FILESYSTEM_IMPL DIRECTORY src/main/include DEFINITION FILESYSTEM_IMPL )
 
 foreach(varName HAS_STD_LOCALE  HAS_ODBC  HAS_MBSRTOWCS  HAS_WCSTOMBS  HAS_FWIDE  HAS_LIBESMTP  HAS_SYSLOG)
   if(${varName} EQUAL 0)
@@ -265,6 +266,7 @@ message(STATUS "  mutex implementation ............ : ${MUTEX_IMPL}")
 message(STATUS "  shared_ptr implementation ....... : ${SMART_PTR_IMPL}")
 message(STATUS "  shared_mutex implementation ..... : ${SHARED_MUTEX_IMPL}")
 message(STATUS "  atomic implementation ........... : ${ATOMIC_IMPL}")
+message(STATUS "  filesystem implementation ....... : ${FILESYSTEM_IMPL}")
 
 if(BUILD_TESTING)
 message(STATUS "Applications required for tests:")
diff --git a/src/cmake/boost-fallback/boost-fallback.cmake b/src/cmake/boost-fallback/boost-fallback.cmake
index 7454c016..3a71c929 100644
--- a/src/cmake/boost-fallback/boost-fallback.cmake
+++ b/src/cmake/boost-fallback/boost-fallback.cmake
@@ -7,6 +7,7 @@
 # thread
 # mutex
 # shared_mutex
+# filesystem
 #
 # Variables set:
 # ${prefix}_
@@ -41,6 +42,10 @@
 # Smart pointer variables set:
 # STD_SHARED_PTR_FOUND - if std::shared_ptr is found
 # Boost_SHARED_PTR_FOUND - if boost::shared_ptr is found
+#
+# Filesystem variables set:
+# STD_FILESYSTEM_FOUND - if std::filesystem is found
+# Boost_FILESYSTEM_FOUND - if boost::filesystem is found
 
 include(FindThreads)
 
@@ -54,6 +59,8 @@ try_compile(STD_SHARED_PTR_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tes
     "${CMAKE_CURRENT_LIST_DIR}/test-stdsharedptr.cpp")
 try_compile(STD_ATOMIC_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
     "${CMAKE_CURRENT_LIST_DIR}/test-stdatomic.cpp")
+try_compile(STD_FILESYSTEM_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
+    "${CMAKE_CURRENT_LIST_DIR}/test-stdfilesystem.cpp")
 
 # We need to have all three boost components in order to run our tests
 # Boost thread requires chrono and atomic to work
@@ -70,6 +77,12 @@ if( ${Boost_FOUND} )
         "${CMAKE_CURRENT_LIST_DIR}/test-boostatomic.cpp")
 endif( ${Boost_FOUND} )
 
+find_package(Boost COMPONENTS filesystem)
+if( ${Boost_FOUND} )
+    try_compile(Boost_FILESYSTEM_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
+        "${CMAKE_CURRENT_LIST_DIR}/test-boostfilesystem.cpp")
+endif( ${Boost_FOUND} )
+
 # Link the target with the appropriate boost libraries(if required)
 function(boostfallback_link target)
     if(NOT ${STD_THREAD_FOUND})
diff --git a/src/cmake/boost-fallback/boost-std-configuration.h.cmake b/src/cmake/boost-fallback/boost-std-configuration.h.cmake
index cd0d8f7c..1e5dcf5a 100644
--- a/src/cmake/boost-fallback/boost-std-configuration.h.cmake
+++ b/src/cmake/boost-fallback/boost-std-configuration.h.cmake
@@ -3,6 +3,8 @@
 
 #cmakedefine01 STD_SHARED_MUTEX_FOUND
 #cmakedefine01 Boost_SHARED_MUTEX_FOUND
+#cmakedefine01 STD_FILESYSTEM_FOUND
+#cmakedefine01 Boost_FILESYSTEM_FOUND
 
 #if STD_SHARED_MUTEX_FOUND
 #include <shared_mutex>
@@ -20,4 +22,20 @@ namespace ${NAMESPACE_ALIAS} {
 }
 #endif
 
+#if STD_FILESYSTEM_FOUND
+#include <filesystem>
+namespace ${NAMESPACE_ALIAS} {
+namespace filesystem {
+    typedef std::filesystem::path path;
+}
+}
+#elif Boost_FILESYSTEM_FOUND
+#include <boost/filesystem.hpp>
+namespace ${NAMESPACE_ALIAS} {
+namespace filesystem {
+    typedef boost::filesystem::path path;
+}
+}
+#endif
+
 #endif /* BOOST_STD_CONFIGURATION_H */
diff --git a/src/cmake/boost-fallback/test-boostfilesystem.cpp b/src/cmake/boost-fallback/test-boostfilesystem.cpp
new file mode 100644
index 00000000..137f8c96
--- /dev/null
+++ b/src/cmake/boost-fallback/test-boostfilesystem.cpp
@@ -0,0 +1,6 @@
+#include <boost/filesystem.hpp>
+
+int main(int argc, char** argv){
+	boost::filesystem::path p;
+}
+
diff --git a/src/cmake/boost-fallback/test-stdfilesystem.cpp b/src/cmake/boost-fallback/test-stdfilesystem.cpp
new file mode 100644
index 00000000..6c45325f
--- /dev/null
+++ b/src/cmake/boost-fallback/test-stdfilesystem.cpp
@@ -0,0 +1,5 @@
+#include <filesystem>
+
+int main(int argc, char** argv){
+	std::filesystem::path p;
+}
diff --git a/src/main/cpp/CMakeLists.txt b/src/main/cpp/CMakeLists.txt
index 8837f1da..e1fa6ba4 100644
--- a/src/main/cpp/CMakeLists.txt
+++ b/src/main/cpp/CMakeLists.txt
@@ -193,6 +193,10 @@ set_target_properties(log4cxx PROPERTIES
   SOVERSION ${LIBLOG4CXX_LIB_SOVERSION}
 )
 boostfallback_link(log4cxx)
+get_directory_property( FILESYSTEM_IMPL DIRECTORY "${CMAKE_SOURCE_DIR}/src/main/include" DEFINITION FILESYSTEM_IMPL )
+if("${FILESYSTEM_IMPL}" STREQUAL "std::filesystem" )
+  target_link_libraries(log4cxx PUBLIC $<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.0>>:stdc++fs>)
+endif()
 
 if(LOG4CXX_ABI_CHECK)
     message("Getting dependencies for ABI compatability check...")
diff --git a/src/main/cpp/timebasedrollingpolicy.cpp b/src/main/cpp/timebasedrollingpolicy.cpp
index ec2d6a64..15ca7563 100644
--- a/src/main/cpp/timebasedrollingpolicy.cpp
+++ b/src/main/cpp/timebasedrollingpolicy.cpp
@@ -30,8 +30,8 @@
 #include <log4cxx/helpers/stringhelper.h>
 #include <log4cxx/helpers/optionconverter.h>
 #include <log4cxx/fileappender.h>
+#include <log4cxx/boost-std-configuration.h>
 #include <iostream>
-#include <libgen.h>
 
 using namespace log4cxx;
 using namespace log4cxx::rolling;
@@ -169,8 +169,10 @@ const std::string TimeBasedRollingPolicy::createFile(const std::string& fileName
 		snprintf(szUid, MAX_FILE_LEN, "%u", uid);
 	}
 
-	// TODO this should probably be using boost::filesystem or std::filesystem
-	return std::string(::dirname(szDirName)) + "/." + ::basename(szBaseName) + szUid + suffix;
+	log4cxx::filesystem::path path(fileName);
+	std::string newFilename = path.filename().string() + szUid + suffix;
+	log4cxx::filesystem::path retval = path.parent_path() / newFilename;
+	return retval.string();
 }
 
 int TimeBasedRollingPolicy::createMMapFile(const std::string& fileName, log4cxx::helpers::Pool& pool)
@@ -218,7 +220,10 @@ int TimeBasedRollingPolicy::lockMMapFile(int type)
 	{
 		LogLog::warn(LOG4CXX_STR("apr_file_lock for mmap failed."));
 	}
+
+	return stat;
 }
+
 int TimeBasedRollingPolicy::unLockMMapFile()
 {
 	apr_status_t stat = apr_file_unlock(m_priv->_lock_file);
@@ -227,6 +232,8 @@ int TimeBasedRollingPolicy::unLockMMapFile()
 	{
 		LogLog::warn(LOG4CXX_STR("apr_file_unlock for mmap failed."));
 	}
+
+	return stat;
 }
 
 TimeBasedRollingPolicy::TimeBasedRollingPolicy() :
diff --git a/src/main/include/CMakeLists.txt b/src/main/include/CMakeLists.txt
index caba4629..499ef852 100644
--- a/src/main/include/CMakeLists.txt
+++ b/src/main/include/CMakeLists.txt
@@ -206,6 +206,14 @@ else()
     set( ATOMIC_IMPL "NONE" )
 endif()
 
+if( ${STD_FILESYSTEM_FOUND} AND NOT ${PREFER_BOOST} )
+	set( FILESYSTEM_IMPL "std::filesystem" )
+elseif( ${Boost_FILESYSTEM_FOUND} )
+	set( FILESYSTEM_IMPL "boost::filesystem" )
+else()
+	set( FILESYSTEM_IMPL "NONE" )
+endif()
+
 # Configure both our private header and our public header
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/log4cxx/private/log4cxx_private.h.in
                ${CMAKE_CURRENT_BINARY_DIR}/log4cxx/private/log4cxx_private.h