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

baodi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pulsar-client-cpp.git


The following commit(s) were added to refs/heads/main by this push:
     new a4ee89d  Remove log4cxx dependency and its specified configuration 
(#283)
a4ee89d is described below

commit a4ee89d5216dd48607a900de7a8b45bb894d5d39
Author: Yunze Xu <[email protected]>
AuthorDate: Tue Jun 13 22:17:01 2023 +0800

    Remove log4cxx dependency and its specified configuration (#283)
    
    * Remove log4cxx dependency and its specified configuration
    
    ### Motivation
    
    See https://github.com/apache/pulsar/pull/1827, which also marked the
    log4cxx configurations as deprecated.
    
    ### Modifications
    
    Remove all log4cxx related stuff. log4cxx users can implement their own
    `LoggerFactory` like the built-in implementation before this PR.
    
    * Fix Windows compilation error
---
 CMakeLists.txt                       |  40 +-------------
 README.md                            |   2 -
 include/pulsar/ClientConfiguration.h |  13 -----
 lib/ClientConfiguration.cc           |   7 ---
 lib/ClientConfigurationImpl.h        |   1 -
 lib/ClientImpl.cc                    |  14 -----
 lib/Log4CxxLogger.h                  |  39 --------------
 lib/Log4cxxLogger.cc                 | 100 -----------------------------------
 lib/LogUtils.cc                      |  14 -----
 lib/LogUtils.h                       |   2 -
 tests/BasicEndToEndTest.cc           |   2 -
 vcpkg.json                           |   1 -
 12 files changed, 1 insertion(+), 234 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index dedea25..64b7b0e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -74,9 +74,6 @@ MESSAGE(STATUS "BUILD_TESTS:  " ${BUILD_TESTS})
 option(BUILD_PERF_TOOLS "Build Pulsar CLI perf producer/consumer" OFF)
 MESSAGE(STATUS "BUILD_PERF_TOOLS:  " ${BUILD_PERF_TOOLS})
 
-option(USE_LOG4CXX "Build with Log4cxx support" OFF)
-MESSAGE(STATUS "USE_LOG4CXX:  " ${USE_LOG4CXX})
-
 IF (NOT CMAKE_BUILD_TYPE)
     set(CMAKE_BUILD_TYPE RelWithDebInfo)
 ENDIF ()
@@ -118,13 +115,7 @@ endif()
 
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 
-set(LOG_CATEGORY_NAME $ENV{LOG_CATEGORY_NAME})
-
-if (NOT LOG_CATEGORY_NAME)
-    set(LOG_CATEGORY_NAME "\"pulsar.\"")
-endif(NOT LOG_CATEGORY_NAME)
-
-add_definitions(-DLOG_CATEGORY_NAME=${LOG_CATEGORY_NAME} -DBUILDING_PULSAR 
-DBOOST_ALL_NO_LIB -DBOOST_ALLOW_DEPRECATED_HEADERS)
+add_definitions(-DBUILDING_PULSAR -DBOOST_ALL_NO_LIB 
-DBOOST_ALLOW_DEPRECATED_HEADERS)
 
 # For dependencies other than OpenSSL, dynamic libraries are forbidden to link 
when LINK_STATIC is ON
 if (LINK_STATIC)
@@ -178,24 +169,6 @@ if (LINK_STATIC AND NOT VCPKG_TRIPLET)
     find_library(LIB_SNAPPY NAMES libsnappy.a)
     message(STATUS "LIB_SNAPPY: ${LIB_SNAPPY}")
 
-    if (USE_LOG4CXX)
-        if (LOG4CXX_USE_DYNAMIC_LIBS)
-            find_library(LOG4CXX_LIBRARY_PATH log4cxx)
-        else ()
-            find_library(LOG4CXX_LIBRARY_PATH NAMES liblog4cxx.a)
-
-            # Libraries needed by log4cxx to link statically with
-            find_library(APR_LIBRARY_PATH NAMES libapr-1 PATHS /usr/lib 
/usr/local/apr/lib /usr/local/opt/apr/libexec/lib/)
-            find_library(APR_UTIL_LIBRARY_PATH NAMES libaprutil-1 PATHS 
/usr/lib /usr/local/apr/lib /usr/local/opt/apr-util/libexec/lib/)
-            find_library(EXPAT_LIBRARY_PATH NAMES libexpat expat)
-            if (APPLE)
-                find_library(ICONV_LIBRARY_PATH NAMES libiconv iconv)
-            else ()
-                set(ICONV_LIBRARY_PATH )
-            endif (APPLE)
-        endif (LOG4CXX_USE_DYNAMIC_LIBS)
-    endif (USE_LOG4CXX)
-
     if (MSVC)
         add_definitions(-DCURL_STATICLIB)
     endif()
@@ -241,11 +214,6 @@ else()
     else ()
         find_library(LIB_SNAPPY NAMES snappy libsnappy)
     endif ()
-
-    if (USE_LOG4CXX)
-        find_library(LOG4CXX_LIBRARY_PATH log4cxx)
-        find_path(LOG4CXX_INCLUDE_PATH log4cxx/logger.h)
-    endif (USE_LOG4CXX)
 endif ()
 
 if (Boost_MAJOR_VERSION EQUAL 1 AND Boost_MINOR_VERSION LESS 69)
@@ -280,11 +248,6 @@ if (BUILD_TESTS)
     find_path(GMOCK_INCLUDE_PATH gmock/gmock.h)
 endif ()
 
-if (USE_LOG4CXX)
-    set(CMAKE_CXX_FLAGS " -DUSE_LOG4CXX ${CMAKE_CXX_FLAGS}")
-    find_path(LOG4CXX_INCLUDE_PATH log4cxx/logger.h)
-endif (USE_LOG4CXX)
-
 if (NOT APPLE AND NOT MSVC)
     # Hide all non-exported symbols to avoid conflicts
     add_compile_options(-fvisibility=hidden) 
@@ -323,7 +286,6 @@ include_directories(
   ${ZLIB_INCLUDE_DIRS}
   ${CURL_INCLUDE_DIRS}
   ${Protobuf_INCLUDE_DIRS}
-  ${LOG4CXX_INCLUDE_PATH}
   ${GTEST_INCLUDE_PATH}
   ${GMOCK_INCLUDE_PATH}
 )
diff --git a/README.md b/README.md
index ffbc4e4..014055c 100644
--- a/README.md
+++ b/README.md
@@ -53,8 +53,6 @@ If you want to enable other compression types, you need to 
install:
 
 If you want to build and run the tests, you need to install 
[GTest](https://github.com/google/googletest). Otherwise, you need to add CMake 
option `-DBUILD_TESTS=OFF`.
 
-If you want to use `ClientConfiguration::setLogConfFilePath`, you need to 
install the [Log4CXX](https://logging.apache.org/log4cxx) and add CMake option 
`-DUSE_LOG4CXX=ON`.
-
 The [dependencies.yaml](./dependencies.yaml) file provides the recommended 
dependency versions, while you can still build from source with other 
dependency versions. If a dependency requires a higher C++ standard, e.g. 
C++14, you can specify the standard like:
 
 ```bash
diff --git a/include/pulsar/ClientConfiguration.h 
b/include/pulsar/ClientConfiguration.h
index 4cb49d0..4074d00 100644
--- a/include/pulsar/ClientConfiguration.h
+++ b/include/pulsar/ClientConfiguration.h
@@ -155,19 +155,6 @@ class PULSAR_PUBLIC ClientConfiguration {
      */
     int getMaxBackoffIntervalMs() const;
 
-    /**
-     * Initialize the log configuration
-     *
-     * @param logConfFilePath  path of the configuration file
-     * @deprecated
-     */
-    ClientConfiguration& setLogConfFilePath(const std::string& 
logConfFilePath);
-
-    /**
-     * Get the path of log configuration file (log4cpp)
-     */
-    const std::string& getLogConfFilePath() const;
-
     /**
      * Configure a custom logger backend to route of Pulsar client library
      * to a different logger implementation.
diff --git a/lib/ClientConfiguration.cc b/lib/ClientConfiguration.cc
index e8a6dcb..95779e6 100644
--- a/lib/ClientConfiguration.cc
+++ b/lib/ClientConfiguration.cc
@@ -146,13 +146,6 @@ ClientConfiguration& 
ClientConfiguration::setMaxBackoffIntervalMs(int maxBackoff
 
 int ClientConfiguration::getMaxBackoffIntervalMs() const { return 
impl_->maxBackoffIntervalMs; }
 
-ClientConfiguration& ClientConfiguration::setLogConfFilePath(const 
std::string& logConfFilePath) {
-    impl_->logConfFilePath = logConfFilePath;
-    return *this;
-}
-
-const std::string& ClientConfiguration::getLogConfFilePath() const { return 
impl_->logConfFilePath; }
-
 ClientConfiguration& ClientConfiguration::setLogger(LoggerFactory* 
loggerFactory) {
     impl_->loggerFactory.reset(loggerFactory);
     return *this;
diff --git a/lib/ClientConfigurationImpl.h b/lib/ClientConfigurationImpl.h
index 029b0e9..0f979bb 100644
--- a/lib/ClientConfigurationImpl.h
+++ b/lib/ClientConfigurationImpl.h
@@ -33,7 +33,6 @@ struct ClientConfigurationImpl {
     int maxLookupRedirects{20};
     int initialBackoffIntervalMs{100};
     int maxBackoffIntervalMs{60000};
-    std::string logConfFilePath;
     bool useTls{false};
     std::string tlsPrivateKeyFilePath;
     std::string tlsCertificateFilePath;
diff --git a/lib/ClientImpl.cc b/lib/ClientImpl.cc
index a8fc24c..e7b6aa4 100644
--- a/lib/ClientImpl.cc
+++ b/lib/ClientImpl.cc
@@ -43,10 +43,6 @@
 #include "TimeUtils.h"
 #include "TopicName.h"
 
-#ifdef USE_LOG4CXX
-#include "Log4CxxLogger.h"
-#endif
-
 #ifdef PULSAR_USE_BOOST_REGEX
 #include <boost/regex.hpp>
 #define PULSAR_REGEX_NAMESPACE boost
@@ -98,18 +94,8 @@ ClientImpl::ClientImpl(const std::string& serviceUrl, const 
ClientConfiguration&
       closingError(ResultOk) {
     std::unique_ptr<LoggerFactory> loggerFactory = 
clientConfiguration_.impl_->takeLogger();
     if (!loggerFactory) {
-#ifdef USE_LOG4CXX
-        if (!clientConfiguration_.getLogConfFilePath().empty()) {
-            // A log4cxx log file was passed through deprecated parameter. Use 
that to configure Log4CXX
-            loggerFactory = 
Log4CxxLoggerFactory::create(clientConfiguration_.getLogConfFilePath());
-        } else {
-            // Use default simple console logger
-            loggerFactory.reset(new ConsoleLoggerFactory);
-        }
-#else
         // Use default simple console logger
         loggerFactory.reset(new ConsoleLoggerFactory);
-#endif
     }
     LogUtils::setLoggerFactory(std::move(loggerFactory));
 
diff --git a/lib/Log4CxxLogger.h b/lib/Log4CxxLogger.h
deleted file mode 100644
index 2e3f819..0000000
--- a/lib/Log4CxxLogger.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.
- */
-
-#pragma once
-
-#include <pulsar/Logger.h>
-#include <pulsar/defines.h>
-
-#ifdef USE_LOG4CXX
-
-namespace pulsar {
-
-class PULSAR_PUBLIC Log4CxxLoggerFactory : public LoggerFactory {
-   public:
-    static std::unique_ptr<LoggerFactory> create();
-    static std::unique_ptr<LoggerFactory> create(const std::string& 
log4cxxConfFile);
-
-    Logger* getLogger(const std::string& fileName);
-};
-
-}  // namespace pulsar
-
-#endif
diff --git a/lib/Log4cxxLogger.cc b/lib/Log4cxxLogger.cc
deleted file mode 100644
index e937128..0000000
--- a/lib/Log4cxxLogger.cc
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * 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 "Log4CxxLogger.h"
-
-#include <iostream>
-
-#ifdef USE_LOG4CXX
-
-#include <log4cxx/consoleappender.h>
-#include <log4cxx/logger.h>
-#include <log4cxx/logmanager.h>
-#include <log4cxx/patternlayout.h>
-#include <log4cxx/propertyconfigurator.h>
-
-using namespace log4cxx;
-
-namespace pulsar {
-
-class Log4CxxLogger : public Logger {
-    std::string _fileName;
-    LoggerPtr _logger;
-
-   public:
-    Log4CxxLogger(const std::string &fileName)
-        : _fileName(fileName), 
_logger(log4cxx::Logger::getLogger(LOG_CATEGORY_NAME + fileName)) {}
-
-    bool isEnabled(Level level) { return 
_logger->isEnabledFor(getLevel(level)); }
-
-    void log(Level level, int line, const std::string &message) {
-        spi::LocationInfo location(_fileName.c_str(), "", line);
-        _logger->forcedLogLS(getLevel(level), message, location);
-    }
-
-   private:
-    static log4cxx::LevelPtr getLevel(Level level) {
-        switch (level) {
-            case LEVEL_DEBUG:
-                return log4cxx::Level::getDebug();
-            case LEVEL_INFO:
-                return log4cxx::Level::getInfo();
-            case LEVEL_WARN:
-                return log4cxx::Level::getWarn();
-            case LEVEL_ERROR:
-                return log4cxx::Level::getError();
-            default:
-                return log4cxx::Level::getInfo();
-        }
-    }
-};
-
-std::unique_ptr<LoggerFactory> Log4CxxLoggerFactory::create() {
-    if (!LogManager::getLoggerRepository()->isConfigured()) {
-        LogManager::getLoggerRepository()->setConfigured(true);
-        LoggerPtr root = log4cxx::Logger::getRootLogger();
-        static const LogString TTCC_CONVERSION_PATTERN(
-            LOG4CXX_STR("%d{yyyy-MM-dd HH:mm:ss,SSS Z} [%t] %-5p %l - %m%n"));
-        LayoutPtr layout(new PatternLayout(TTCC_CONVERSION_PATTERN));
-        AppenderPtr appender(new ConsoleAppender(layout));
-        root->setLevel(log4cxx::Level::getInfo());
-        root->addAppender(appender);
-    }
-
-    return std::unique_ptr<LoggerFactory>(new Log4CxxLoggerFactory());
-}
-
-std::unique_ptr<LoggerFactory> Log4CxxLoggerFactory::create(const std::string 
&log4cxxConfFile) {
-    try {
-        log4cxx::PropertyConfigurator::configure(log4cxxConfFile);
-    } catch (const std::exception &e) {
-        std::cerr << "exception caught while configuring log4cpp via '" << 
log4cxxConfFile
-                  << "': " << e.what() << std::endl;
-    } catch (...) {
-        std::cerr << "unknown exception while configuring log4cpp via '" << 
log4cxxConfFile << "'."
-                  << std::endl;
-    }
-
-    return std::unique_ptr<LoggerFactory>(new Log4CxxLoggerFactory());
-}
-
-Logger *Log4CxxLoggerFactory::getLogger(const std::string &fileName) { return 
new Log4CxxLogger(fileName); }
-}  // namespace pulsar
-
-#endif  // USE_LOG4CXX
diff --git a/lib/LogUtils.cc b/lib/LogUtils.cc
index 6e8a866..b210f1b 100644
--- a/lib/LogUtils.cc
+++ b/lib/LogUtils.cc
@@ -23,22 +23,8 @@
 #include <atomic>
 #include <iostream>
 
-#include "Log4CxxLogger.h"
-
 namespace pulsar {
 
-void LogUtils::init(const std::string& logfilePath) {
-    // If this is called explicitely, we fallback to Log4cxx config, if enabled
-
-#ifdef USE_LOG4CXX
-    if (!logfilePath.empty()) {
-        setLoggerFactory(Log4CxxLoggerFactory::create(logfilePath));
-    } else {
-        setLoggerFactory(Log4CxxLoggerFactory::create());
-    }
-#endif  // USE_LOG4CXX
-}
-
 static std::atomic<LoggerFactory*> s_loggerFactory(nullptr);
 
 void LogUtils::setLoggerFactory(std::unique_ptr<LoggerFactory> loggerFactory) {
diff --git a/lib/LogUtils.h b/lib/LogUtils.h
index 7cfad5b..c8abd13 100644
--- a/lib/LogUtils.h
+++ b/lib/LogUtils.h
@@ -84,8 +84,6 @@ namespace pulsar {
 
 class PULSAR_PUBLIC LogUtils {
    public:
-    static void init(const std::string& logConfFilePath);
-
     static void setLoggerFactory(std::unique_ptr<LoggerFactory> loggerFactory);
 
     static void resetLoggerFactory();
diff --git a/tests/BasicEndToEndTest.cc b/tests/BasicEndToEndTest.cc
index d9beccf..8599b92 100644
--- a/tests/BasicEndToEndTest.cc
+++ b/tests/BasicEndToEndTest.cc
@@ -681,7 +681,6 @@ TEST(BasicEndToEndTest, testConfigurationFile) {
     config1.setOperationTimeoutSeconds(100);
     config1.setIOThreads(10);
     config1.setMessageListenerThreads(1);
-    config1.setLogConfFilePath("/tmp/");
 
     ClientConfiguration config2 = config1;
     AuthenticationDataPtr authData;
@@ -689,7 +688,6 @@ TEST(BasicEndToEndTest, testConfigurationFile) {
     ASSERT_EQ(100, config2.getOperationTimeoutSeconds());
     ASSERT_EQ(10, config2.getIOThreads());
     ASSERT_EQ(1, config2.getMessageListenerThreads());
-    ASSERT_EQ(config2.getLogConfFilePath().compare("/tmp/"), 0);
 }
 
 TEST(BasicEndToEndTest, testSinglePartitionRoutingPolicy) {
diff --git a/vcpkg.json b/vcpkg.json
index 735507e..5cc3863 100644
--- a/vcpkg.json
+++ b/vcpkg.json
@@ -21,7 +21,6 @@
     "snappy",
     "zlib",
     "zstd",
-    "log4cxx",
     {
       "name": "dlfcn-win32",
       "platform": "windows"

Reply via email to