Skip to content

Commit

Permalink
Remove APR pool from Logger constructor in next ABI version (#392)
Browse files Browse the repository at this point in the history
* Remove class DefaultLoggerFactory in the next ABI
  • Loading branch information
swebb2066 authored Jul 16, 2024
1 parent 4dc3469 commit 30e64ee
Show file tree
Hide file tree
Showing 18 changed files with 156 additions and 79 deletions.
10 changes: 5 additions & 5 deletions src/main/cpp/appenderattachableimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,12 @@
* 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;
using namespace LOG4CXX_NS::helpers;
using namespace LOG4CXX_NS::spi;

IMPLEMENT_LOG4CXX_OBJECT(AppenderAttachableImpl)

Expand All @@ -35,11 +30,16 @@ struct AppenderAttachableImpl::priv_data
mutable std::mutex m_mutex;
};

AppenderAttachableImpl::AppenderAttachableImpl()
{
}

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

AppenderAttachableImpl::~AppenderAttachableImpl()
{
Expand Down
1 change: 0 additions & 1 deletion src/main/cpp/asyncappender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ struct AsyncAppender::AsyncAppenderPriv : public AppenderSkeleton::AppenderSkele
AppenderSkeletonPrivate(),
buffer(DEFAULT_BUFFER_SIZE),
bufferSize(DEFAULT_BUFFER_SIZE),
appenders(pool),
dispatcher(),
locationInfo(false),
blocking(true)
Expand Down
20 changes: 16 additions & 4 deletions src/main/cpp/defaultloggerfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <log4cxx/logstring.h>

#if LOG4CXX_ABI_VERSION <= 15
#include <log4cxx/defaultloggerfactory.h>
#include <log4cxx/logger.h>
#else
#include <log4cxx/spi/loggerfactory.h>
#endif

using namespace LOG4CXX_NS;
using namespace spi;

#if LOG4CXX_ABI_VERSION <= 15
IMPLEMENT_LOG4CXX_OBJECT(DefaultLoggerFactory)

LoggerPtr DefaultLoggerFactory::makeNewLoggerInstance(
LOG4CXX_NS::helpers::Pool& pool,
helpers::Pool& pool,
const LogString& name) const
{
return std::make_shared<Logger>(pool, name);
return std::make_shared<Logger>(name);
}
#endif

LoggerPtr LoggerFactory::makeNewLoggerInstance(const LogString& name) const
{
return std::make_shared<Logger>(name);
}

8 changes: 8 additions & 0 deletions src/main/cpp/domconfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
#include <log4cxx/config/propertysetter.h>
#include <log4cxx/spi/errorhandler.h>
#include <log4cxx/spi/loggerfactory.h>
#if LOG4CXX_ABI_VERSION <= 15
#include <log4cxx/defaultloggerfactory.h>
#else
#include <log4cxx/spi/loggerfactory.h>
#endif
#include <log4cxx/helpers/filewatchdog.h>
#include <log4cxx/spi/loggerrepository.h>
#include <log4cxx/spi/loggingevent.h>
Expand Down Expand Up @@ -819,7 +823,11 @@ spi::ConfigurationStatus DOMConfigurator::doConfigure(const File& filename, spi:
LogLog::debug(msg);
}

#if LOG4CXX_ABI_VERSION <= 15
m_priv->loggerFactory = std::make_shared<DefaultLoggerFactory>();
#else
m_priv->loggerFactory = std::make_shared<LoggerFactory>();
#endif

Pool p;
apr_file_t* fd;
Expand Down
26 changes: 14 additions & 12 deletions src/main/cpp/hierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,18 @@
* limitations under the License.
*/

#include <log4cxx/logstring.h>
#include <log4cxx/spi/loggerfactory.h>
#include <log4cxx/hierarchy.h>
#if LOG4CXX_ABI_VERSION <= 15
#include <log4cxx/defaultloggerfactory.h>
#include <log4cxx/logger.h>
#include <log4cxx/spi/hierarchyeventlistener.h>
#include <log4cxx/level.h>
#include <algorithm>
#endif
#include <log4cxx/helpers/loglog.h>
#include <log4cxx/appender.h>
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/stringhelper.h>
#if !defined(LOG4CXX)
#define LOG4CXX 1
#endif
#include <log4cxx/spi/rootlogger.h>
#include <algorithm>
#include <map>
#include <mutex>
#include "assert.h"
#include <vector>


using namespace LOG4CXX_NS;
Expand Down Expand Up @@ -227,7 +221,11 @@ LevelPtr Hierarchy::getThreshold() const

LoggerPtr Hierarchy::getLogger(const LogString& name)
{
#if LOG4CXX_ABI_VERSION <= 15
static WideLife<spi::LoggerFactoryPtr> defaultFactory = std::make_shared<DefaultLoggerFactory>();
#else
static WideLife<spi::LoggerFactoryPtr> defaultFactory = std::make_shared<LoggerFactory>();
#endif
return getLogger(name, defaultFactory);
}

Expand All @@ -246,7 +244,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 Expand Up @@ -283,7 +285,7 @@ LoggerPtr Hierarchy::getRootLogger() const
std::lock_guard<std::recursive_mutex> lock(m_priv->mutex);
if (!m_priv->root)
{
m_priv->root = std::make_shared<RootLogger>(m_priv->pool, Level::getDebug());
m_priv->root = std::make_shared<RootLogger>(Level::getDebug());
m_priv->root->setHierarchy(const_cast<Hierarchy*>(this));
}

Expand Down
28 changes: 16 additions & 12 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,12 @@ 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(const LogString& name1)
: name(name1)
, repositoryRaw(0)
, additive(true)
, levelData(Level::getData())
{}

/**
The name of this logger.
Expand All @@ -71,7 +68,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,12 +86,19 @@ struct Logger::LoggerPrivate

IMPLEMENT_LOG4CXX_OBJECT(Logger)

Logger::Logger(Pool& p, const LogString& name1)
: m_priv(std::make_unique<LoggerPrivate>(p, name1))
Logger::Logger(const LogString& name1)
: m_priv(std::make_unique<LoggerPrivate>(name1))
, m_threshold(0)
{
}

#if LOG4CXX_ABI_VERSION <= 15
Logger::Logger(Pool& p, const LogString& name)
: Logger(name)
{
}
#endif

Logger::~Logger()
{
}
Expand Down
15 changes: 10 additions & 5 deletions src/main/cpp/propertyconfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@

#include <log4cxx/logstring.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/spi/loggerfactory.h>
#include <log4cxx/helpers/properties.h>
#include <log4cxx/helpers/loglog.h>
#include <log4cxx/helpers/exception.h>
#include <log4cxx/logmanager.h>
#include <log4cxx/helpers/optionconverter.h>
#include <log4cxx/level.h>
#if LOG4CXX_ABI_VERSION <= 15
#include <log4cxx/defaultloggerfactory.h>
#else
#include <log4cxx/spi/loggerfactory.h>
#endif
#include <log4cxx/helpers/stringhelper.h>
#include <log4cxx/appender.h>
#include <log4cxx/logger.h>
#include <log4cxx/layout.h>
#include <log4cxx/config/propertysetter.h>
#include <log4cxx/spi/loggerrepository.h>
#include <log4cxx/helpers/stringtokenizer.h>
#include <log4cxx/helpers/transcoder.h>
#include <log4cxx/helpers/fileinputstream.h>
Expand Down Expand Up @@ -75,7 +75,12 @@ PropertyWatchdog* PropertyConfigurator::pdog = NULL;
IMPLEMENT_LOG4CXX_OBJECT(PropertyConfigurator)

PropertyConfigurator::PropertyConfigurator()
: registry(new std::map<LogString, AppenderPtr>()), loggerFactory(new DefaultLoggerFactory())
: registry(new std::map<LogString, AppenderPtr>())
#if LOG4CXX_ABI_VERSION <= 15
, loggerFactory(new DefaultLoggerFactory())
#else
, loggerFactory(new LoggerFactory())
#endif
{
}

Expand Down
11 changes: 9 additions & 2 deletions src/main/cpp/rootlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@ using namespace LOG4CXX_NS;
using namespace LOG4CXX_NS::spi;
using namespace LOG4CXX_NS::helpers;

RootLogger::RootLogger(Pool& pool, const LevelPtr level1) :
Logger(pool, LOG4CXX_STR("root"))
RootLogger::RootLogger(const LevelPtr& level1)
: Logger(LOG4CXX_STR("root"))
{
setLevel(level1);
}

#if LOG4CXX_ABI_VERSION <= 15
RootLogger::RootLogger(Pool&, const LevelPtr level)
: RootLogger(level)
{
}
#endif

const LevelPtr& RootLogger::getEffectiveLevel() const
{
return getLevel();
Expand Down
3 changes: 3 additions & 0 deletions src/main/include/log4cxx/defaultloggerfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace LOG4CXX_NS
class Logger;
typedef std::shared_ptr<Logger> LoggerPtr;

#if LOG4CXX_ABI_VERSION <= 15
class LOG4CXX_EXPORT DefaultLoggerFactory :
public virtual spi::LoggerFactory,
public virtual helpers::Object
Expand All @@ -36,8 +37,10 @@ class LOG4CXX_EXPORT DefaultLoggerFactory :
LOG4CXX_CAST_ENTRY(spi::LoggerFactory)
END_LOG4CXX_CAST_MAP()

[[ deprecated( "Pool is no longer required" ) ]]
LoggerPtr makeNewLoggerInstance(helpers::Pool& pool, const LogString& name) const override;
};
#endif
} // namespace log4cxx

#endif //_LOG4CXX_DEFAULT_LOGGER_FACTORY_H
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.
*/
AppenderAttachableImpl();
#if LOG4CXX_ABI_VERSION <= 15
[[ deprecated( "Pool is no longer required" ) ]]
AppenderAttachableImpl(Pool& pool);

#endif
~AppenderAttachableImpl();

DECLARE_ABSTRACT_LOG4CXX_OBJECT(AppenderAttachableImpl)
Expand Down
4 changes: 0 additions & 4 deletions src/main/include/log4cxx/hierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@

#include <log4cxx/spi/loggerrepository.h>
#include <log4cxx/spi/loggerfactory.h>
#include <vector>
#include <map>
#include <log4cxx/provisionnode.h>
#include <log4cxx/helpers/object.h>
#include <log4cxx/spi/hierarchyeventlistener.h>
#include <log4cxx/helpers/pool.h>

namespace LOG4CXX_NS
{
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.
*/
Logger(const LogString& name);
#if LOG4CXX_ABI_VERSION <= 15
[[ deprecated( "Pool is no longer required" ) ]]
Logger(helpers::Pool& pool, 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
Loading

0 comments on commit 30e64ee

Please sign in to comment.