Skip to content

Commit

Permalink
Use LOG4CXX_ABI_VERSION macro to automate the transition to a new ABI…
Browse files Browse the repository at this point in the history
… version
  • Loading branch information
stephen-webb committed Dec 27, 2023
1 parent 2819df0 commit 8f7ac4c
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 28 deletions.
4 changes: 0 additions & 4 deletions src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

# Options
option(LOG4CXX_ABI_CHECK "Check for ABI changes" OFF)
option(LOG4CXX_ABI_15_COMPATIBILITY "Compatibility for legacy 15 ABI, with some global symbols" ON)

# Build the log4cxx library
add_library(log4cxx)
Expand Down Expand Up @@ -60,9 +59,6 @@ if(LOG4CXX_MULTIPROCESS_ROLLING_FILE_APPENDER)
multiprocessrollingfileappender.cpp
)
endif()
if(LOG4CXX_ABI_15_COMPATIBILITY)
target_compile_definitions(log4cxx PRIVATE LOG4CXX_ABI_15_COMPATIBILITY)
endif()

if(${ENABLE_FMT_LAYOUT})
list(APPEND extra_classes
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/aprinitializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void tlsDestructImpl(void* ptr)
}
}

#if LOG4CXX_ABI_15_COMPATIBILITY
#if LOG4CXX_ABI_VERSION <= 15
extern "C" void tlsDestruct(void* ptr)
{
return tlsDestructImpl(ptr);
Expand Down
4 changes: 2 additions & 2 deletions src/main/cpp/asyncappender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using namespace LOG4CXX_NS;
using namespace LOG4CXX_NS::helpers;
using namespace LOG4CXX_NS::spi;

#if !LOG4CXX_ABI_15_COMPATIBILITY
#if 15 < LOG4CXX_ABI_VERSION
namespace
{
#endif
Expand Down Expand Up @@ -92,7 +92,7 @@ class DiscardSummary

typedef std::map<LogString, DiscardSummary> DiscardMap;

#if !LOG4CXX_ABI_15_COMPATIBILITY
#if 15 < LOG4CXX_ABI_VERSION
}
#endif

Expand Down
13 changes: 5 additions & 8 deletions src/main/cpp/class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,17 @@ using namespace LOG4CXX_NS::rolling;

namespace LOG4CXX_NS
{
// This function defined in log4cxx.h
#if LOG4CXX_ABI_VERSION <= 15
LOG4CXX_EXPORT uint32_t libraryVersion()
#else
uint32_t libraryVersion()
#endif
{
// This function defined in log4cxx.h
return LOG4CXX_VERSION;
}
}

#if LOG4CXX_ABI_15_COMPATIBILITY
LOG4CXX_EXPORT uint32_t libraryVersion()
{
return LOG4CXX_NS::libraryVersion();
}
#endif

Class::Class()
{
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/cpp/logmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,12 @@ void LogManager::resetConfiguration()

bool LogManager::removeLogger(const LogString& name, bool ifNotUsed)
{
#if LOG4CXX_ABI_VERSION <= 15
bool result = false;
if (auto r = dynamic_cast<Hierarchy*>(getLoggerRepository().get()))
result = r->removeLogger(name, ifNotUsed);
return result;
#else
return getLoggerRepository()->removeLogger(name, ifNotUsed);
#endif
}
28 changes: 17 additions & 11 deletions src/main/include/log4cxx/hierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ class LOG4CXX_EXPORT Hierarchy : public spi::LoggerRepository

void addHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener) override;

/**
* Remove a previously added HierarchyEventListener.
*
* ABI TODO: Make virtual and add to LoggerRepository.
*/
void removeHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener);

/**
* Remove a previously added HierarchyEventListener.
*
*/
#if LOG4CXX_ABI_VERSION <= 15
void removeHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener);
#else
void removeHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener) override;
#endif
/**
* Call \c configurator if not yet configured.
*/
Expand Down Expand Up @@ -115,12 +117,12 @@ class LOG4CXX_EXPORT Hierarchy : public spi::LoggerRepository
void setThreshold(const LogString& levelStr) override;

/**
Enable logging for logging requests with level <code>l</code> or
Enable logging for logging requests with level <code>newLevel</code> or
higher. By default all levels are enabled.
@param l The minimum level for which logging requests are sent to
their appenders. */
void setThreshold(const LevelPtr& l) override;
@param newLevel The minimum level of logging requests that are sent to appenders.
*/
void setThreshold(const LevelPtr& newLevel) override;

void fireAddAppenderEvent(const Logger* logger, const Appender* appender) override;

Expand Down Expand Up @@ -239,7 +241,11 @@ class LOG4CXX_EXPORT Hierarchy : public spi::LoggerRepository
@param ifNotUsed If true and use_count() indicates there are other references, do not remove the Logger and return false.
@returns true if \c name Logger was removed from the hierarchy.
*/
#if LOG4CXX_ABI_VERSION <= 15
bool removeLogger(const LogString& name, bool ifNotUsed = true);
#else
bool removeLogger(const LogString& name, bool ifNotUsed = true) override;
#endif

private:

Expand Down
1 change: 1 addition & 0 deletions src/main/include/log4cxx/log4cxx.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/


#define LOG4CXX_ABI_VERSION @log4cxx_ABI_VER@
#define LOG4CXX_VERSION_MAJOR @log4cxx_VERSION_MAJOR@
#define LOG4CXX_VERSION_MINOR @log4cxx_VERSION_MINOR@
#define LOG4CXX_VERSION_PATCH @log4cxx_VERSION_PATCH@
Expand Down
38 changes: 37 additions & 1 deletion src/main/include/log4cxx/spi/loggerrepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,19 @@ class LOG4CXX_EXPORT LoggerRepository : public virtual helpers::Object

/**
Add a {@link spi::HierarchyEventListener HierarchyEventListener}
event to the repository.
event to the repository.
*/
virtual void addHierarchyEventListener(const HierarchyEventListenerPtr&
listener) = 0;

#if 15 < LOG4CXX_ABI_VERSION
/**
* Remove a previously added HierarchyEventListener.
*
*/
virtual void removeHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener) = 0;
#endif

/**
* Call \c configurator if not yet configured.
*/
Expand Down Expand Up @@ -84,11 +92,39 @@ class LOG4CXX_EXPORT LoggerRepository : public virtual helpers::Object
*/
virtual LevelPtr getThreshold() const = 0;

/**
Retrieve the \c name Logger instance
*/
virtual LoggerPtr getLogger(const LogString& name) = 0;

/**
Retrieve the \c name Logger instance
If a logger of that name already exists, then it will be
returned. Otherwise, a new logger will be instantiated by the
provided <code>factory</code>.
@param name The name of the logger to retrieve.
@param factory The factory that will make the new logger instance.
*/
virtual LoggerPtr getLogger(const LogString& name,
const spi::LoggerFactoryPtr& factory) = 0;

#if 15 < LOG4CXX_ABI_VERSION
/**
Remove the \c name Logger from the hierarchy.
Note: The \c name Logger must be retrieved from the hierarchy
\b after any subsequent configuration file change
for the newly loaded settings to be used.
@param name The logger to remove.
@param ifNotUsed If true and use_count() indicates there are other references, do not remove the Logger and return false.
@returns true if \c name Logger was removed from the hierarchy.
*/
virtual bool removeLogger(const LogString& name, bool ifNotUsed = true) = 0;
#endif

virtual LoggerPtr getRootLogger() const = 0;

virtual LoggerPtr exists(const LogString& name) = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/site/doxy/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,8 @@ INCLUDE_FILE_PATTERNS =
PREDEFINED = LOG4CXX_NS=log4cxx \
LOG4CXX_WCHAR_T_API \
LOG4CXX_UNICHAR_API \
LOG4CXX_CFSTRING_API
LOG4CXX_CFSTRING_API \
LOG4CXX_ABI_VERSION=@log4cxx_ABI_VER@

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
Expand Down

0 comments on commit 8f7ac4c

Please sign in to comment.