Skip to content

Commit

Permalink
Remove APR pool from Logger constructor in next ABI version
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-webb committed Jul 13, 2024
1 parent 4dc3469 commit 3670836
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 35 deletions.
8 changes: 4 additions & 4 deletions src/main/cpp/appenderattachableimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/appenderattachableimpl.h>
#include <log4cxx/appender.h>
#include <log4cxx/spi/loggingevent.h>
#include <algorithm>
#include <log4cxx/helpers/pool.h>
#include <mutex>

using namespace LOG4CXX_NS;
Expand All @@ -36,8 +32,12 @@ struct AppenderAttachableImpl::priv_data
};


#if LOG4CXX_ABI_VERSION <= 15
AppenderAttachableImpl::AppenderAttachableImpl(Pool& pool)
: m_priv()
#else
AppenderAttachableImpl::AppenderAttachableImpl()
#endif
{
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/cpp/asyncappender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ struct AsyncAppender::AsyncAppenderPriv : public AppenderSkeleton::AppenderSkele
AppenderSkeletonPrivate(),
buffer(DEFAULT_BUFFER_SIZE),
bufferSize(DEFAULT_BUFFER_SIZE),
#if LOG4CXX_ABI_VERSION <= 15
appenders(pool),
#endif
dispatcher(),
locationInfo(false),
blocking(true)
Expand Down
8 changes: 7 additions & 1 deletion src/main/cpp/defaultloggerfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ using namespace LOG4CXX_NS;
IMPLEMENT_LOG4CXX_OBJECT(DefaultLoggerFactory)

LoggerPtr DefaultLoggerFactory::makeNewLoggerInstance(
LOG4CXX_NS::helpers::Pool& pool,
#if LOG4CXX_ABI_VERSION <= 15
helpers::Pool& pool,
#endif
const LogString& name) const
{
#if LOG4CXX_ABI_VERSION <= 15
return std::make_shared<Logger>(pool, name);
#else
return std::make_shared<Logger>(name);
#endif
}
4 changes: 4 additions & 0 deletions src/main/cpp/hierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,11 @@ LoggerPtr Hierarchy::getLogger(const LogString& name,
}
if (!result && factory)
{
#if LOG4CXX_ABI_VERSION <= 15
LoggerPtr logger(factory->makeNewLoggerInstance(m_priv->pool, name));
#else
LoggerPtr logger(factory->makeNewLoggerInstance(name));
#endif
logger->setHierarchy(this);
m_priv->loggers.insert(LoggerMap::value_type(name, logger));

Expand Down
29 changes: 19 additions & 10 deletions src/main/cpp/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
* limitations under the License.
*/

#include <log4cxx/logstring.h>
#include <log4cxx/logger.h>
#include <log4cxx/spi/loggingevent.h>
#include <log4cxx/logmanager.h>
#include <log4cxx/spi/loggerfactory.h>
#include <log4cxx/appender.h>
#include <log4cxx/level.h>
#include <log4cxx/helpers/loglog.h>
#include <log4cxx/hierarchy.h>
#include <log4cxx/helpers/stringhelper.h>
#include <log4cxx/helpers/transcoder.h>
Expand All @@ -40,12 +37,19 @@ using namespace LOG4CXX_NS::spi;

struct Logger::LoggerPrivate
{
LoggerPrivate(Pool& p, const LogString& name1):
name(name1),
repositoryRaw(0),
aai(p),
additive(true),
levelData(Level::getData()) {}
LoggerPrivate(
#if LOG4CXX_ABI_VERSION <= 15
Pool& p,
#endif
const LogString& name1)
: name(name1)
, repositoryRaw(0)
#if LOG4CXX_ABI_VERSION <= 15
, aai(p)
#endif
, additive(true)
, levelData(Level::getData())
{}

/**
The name of this logger.
Expand All @@ -71,7 +75,7 @@ struct Logger::LoggerPrivate


// Loggers need to know what Hierarchy they are in
LOG4CXX_NS::spi::LoggerRepository* repositoryRaw;
spi::LoggerRepository* repositoryRaw;

helpers::AppenderAttachableImpl aai;

Expand All @@ -89,8 +93,13 @@ struct Logger::LoggerPrivate

IMPLEMENT_LOG4CXX_OBJECT(Logger)

#if LOG4CXX_ABI_VERSION <= 15
Logger::Logger(Pool& p, const LogString& name1)
: m_priv(std::make_unique<LoggerPrivate>(p, name1))
#else
Logger::Logger(const LogString& name1)
: m_priv(std::make_unique<LoggerPrivate>(name1))
#endif
, m_threshold(0)
{
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/cpp/rootlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ using namespace LOG4CXX_NS::spi;
using namespace LOG4CXX_NS::helpers;

RootLogger::RootLogger(Pool& pool, const LevelPtr level1) :
#if LOG4CXX_ABI_VERSION <= 15
Logger(pool, LOG4CXX_STR("root"))
#else
Logger(LOG4CXX_STR("root"))
#endif
{
setLevel(level1);
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/include/log4cxx/defaultloggerfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ class LOG4CXX_EXPORT DefaultLoggerFactory :
LOG4CXX_CAST_ENTRY(spi::LoggerFactory)
END_LOG4CXX_CAST_MAP()

LoggerPtr makeNewLoggerInstance(helpers::Pool& pool, const LogString& name) const override;
LoggerPtr makeNewLoggerInstance(
#if LOG4CXX_ABI_VERSION <= 15
helpers::Pool& pool,
#endif
const LogString& name) const override;
};
} // namespace log4cxx

Expand Down
8 changes: 4 additions & 4 deletions src/main/include/log4cxx/helpers/appenderattachableimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@


#include <log4cxx/spi/appenderattachable.h>
#include <log4cxx/helpers/object.h>
#include <log4cxx/helpers/pool.h>
#include <log4cxx/log4cxx.h>
#include <mutex>

namespace LOG4CXX_NS
{
Expand All @@ -45,10 +43,12 @@ class LOG4CXX_EXPORT AppenderAttachableImpl :
public:
/**
* Create new instance.
* @param pool pool, must be longer-lived than instance.
*/
#if LOG4CXX_ABI_VERSION <= 15
AppenderAttachableImpl(Pool& pool);

#else
AppenderAttachableImpl();
#endif
~AppenderAttachableImpl();

DECLARE_ABSTRACT_LOG4CXX_OBJECT(AppenderAttachableImpl)
Expand Down
16 changes: 8 additions & 8 deletions src/main/include/log4cxx/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#ifndef _LOG4CXX_LOGGER_H
#define _LOG4CXX_LOGGER_H

#include <log4cxx/helpers/appenderattachableimpl.h>
#include <log4cxx/spi/appenderattachable.h>
#include <log4cxx/level.h>
#include <log4cxx/helpers/pool.h>
#include <log4cxx/spi/location/locationinfo.h>
Expand Down Expand Up @@ -46,8 +46,8 @@ LOG4CXX_LIST_DEF(LoggerList, LoggerPtr);
This is the central class in the log4cxx package. Most logging
operations, except configuration, are done through this class.
*/
class LOG4CXX_EXPORT Logger :
public virtual LOG4CXX_NS::spi::AppenderAttachable
class LOG4CXX_EXPORT Logger
: public virtual spi::AppenderAttachable
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(Logger)
Expand All @@ -66,12 +66,12 @@ class LOG4CXX_EXPORT Logger :
sets its name.
<p>It is intended to be only used by factory-classes.
@param pool lifetime of pool must be longer than logger.
@param name The name of the logger.
*/
#if LOG4CXX_ABI_VERSION <= 15
Logger(helpers::Pool& pool, const LogString& name);

#else
Logger(const LogString& name);
#endif
~Logger();


Expand All @@ -97,7 +97,7 @@ class LOG4CXX_EXPORT Logger :
@param event the event to log.
@param p memory pool for any allocations needed to process request.
*/
void callAppenders(const LOG4CXX_NS::spi::LoggingEventPtr& event, LOG4CXX_NS::helpers::Pool& p) const;
void callAppenders(const spi::LoggingEventPtr& event, helpers::Pool& p) const;

/**
Close all attached appenders implementing the AppenderAttachable
Expand Down
1 change: 0 additions & 1 deletion src/main/include/log4cxx/spi/appenderattachable.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#define _LOG4CXX_SPI_APPENDER_ATTACHABLE_H_

#include <log4cxx/logstring.h>
#include <vector>
#include <log4cxx/helpers/object.h>
#include <log4cxx/appender.h>

Expand Down
6 changes: 5 additions & 1 deletion src/main/include/log4cxx/spi/loggerfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ class LOG4CXX_EXPORT LoggerFactory : public virtual helpers::Object
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(LoggerFactory)
virtual ~LoggerFactory() {}
virtual LoggerPtr makeNewLoggerInstance(helpers::Pool& pool, const LogString& name) const = 0;
virtual LoggerPtr makeNewLoggerInstance(
#if LOG4CXX_ABI_VERSION <= 15
helpers::Pool& pool,
#endif
const LogString& name) const = 0;
};


Expand Down
10 changes: 8 additions & 2 deletions src/test/cpp/customlogger/xlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,14 @@ XFactory::XFactory()
{
}

LoggerPtr XFactory::makeNewLoggerInstance(log4cxx::helpers::Pool& pool,
const LogString& name) const
#if LOG4CXX_ABI_VERSION <= 15
LoggerPtr XFactory::makeNewLoggerInstance(log4cxx::helpers::Pool& pool, const LogString& name) const
{
return LoggerPtr(new XLogger(pool, name));
}
#else
LoggerPtr XFactory::makeNewLoggerInstance(const LogString& name) const
{
return LoggerPtr(new XLogger(name));
}
#endif
10 changes: 7 additions & 3 deletions src/test/cpp/customlogger/xlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ class XFactory :

XFactory();
LoggerPtr makeNewLoggerInstance(
#if LOG4CXX_ABI_VERSION <= 15
log4cxx::helpers::Pool& pool,
#endif
const LogString& name) const override;
};

Expand Down Expand Up @@ -72,9 +74,11 @@ class XLogger : public Logger
/**
Just calls the parent constuctor.
*/
XLogger(log4cxx::helpers::Pool& pool,
const LogString& name1) : Logger(pool, name1) {}

#if LOG4CXX_ABI_VERSION <= 15
XLogger(log4cxx::helpers::Pool& pool, const LogString& name) : Logger(pool, name) {}
#else
XLogger(const LogString& name) : Logger(name) {}
#endif
/**
Nothing to activate.
*/
Expand Down

0 comments on commit 3670836

Please sign in to comment.