Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinitelifetime #271

Merged
merged 6 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ src/test/cpp/Testing/
src/test/resources/org/
src/test/resources/output/
target/

*.user
4 changes: 2 additions & 2 deletions src/main/cpp/aprinitializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ void APRInitializer::unregisterAll()

APRInitializer& APRInitializer::getInstance()
{
static apr_environment env;
static APRInitializer init;
static WideLife<apr_environment> env;
static WideLife<APRInitializer> init;
return init;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/cpp/basicconfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <log4cxx/consoleappender.h>
#include <log4cxx/logmanager.h>
#include <log4cxx/logger.h>
#include <log4cxx/helpers/widelife.h>

using namespace log4cxx;

Expand All @@ -29,7 +30,7 @@ void BasicConfigurator::configure(const LayoutPtr& layoutArg)
auto layout = layoutArg;
if (!layout)
{
static const LogString TTCC_CONVERSION_PATTERN(LOG4CXX_STR("%r [%t] %p %c %x - %m%n"));
static const helpers::WideLife<LogString> TTCC_CONVERSION_PATTERN(LOG4CXX_STR("%r [%t] %p %c %x - %m%n"));
layout = std::make_shared<PatternLayout>(TTCC_CONVERSION_PATTERN);
}
auto appender = std::make_shared<ConsoleAppender>(layout);
Expand Down
8 changes: 4 additions & 4 deletions src/main/cpp/charsetdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,14 @@ CharsetDecoder* CharsetDecoder::createDefaultDecoder()

CharsetDecoderPtr CharsetDecoder::getDefaultDecoder()
{
static CharsetDecoderPtr decoder(createDefaultDecoder());
static WideLife<CharsetDecoderPtr> decoder(createDefaultDecoder());

//
// if invoked after static variable destruction
// (if logging is called in the destructor of a static object)
// then create a new decoder.
//
if (decoder == 0)
if (decoder.value() == 0)
{
return CharsetDecoderPtr( createDefaultDecoder() );
}
Expand All @@ -529,14 +529,14 @@ CharsetDecoderPtr CharsetDecoder::getDefaultDecoder()

CharsetDecoderPtr CharsetDecoder::getUTF8Decoder()
{
static CharsetDecoderPtr decoder(new UTF8CharsetDecoder());
static WideLife<CharsetDecoderPtr> decoder(new UTF8CharsetDecoder());

//
// if invoked after static variable destruction
// (if logging is called in the destructor of a static object)
// then create a new decoder.
//
if (decoder == 0)
if (decoder.value() == 0)
{
return std::make_shared<UTF8CharsetDecoder>();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/cpp/charsetencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,14 +513,14 @@ CharsetEncoder::~CharsetEncoder()

CharsetEncoderPtr CharsetEncoder::getDefaultEncoder()
{
static CharsetEncoderPtr encoder(createDefaultEncoder());
static WideLife<CharsetEncoderPtr> encoder(createDefaultEncoder());

//
// if invoked after static variable destruction
// (if logging is called in the destructor of a static object)
// then create a new decoder.
//
if (encoder == 0)
if (encoder.value() == 0)
{
return CharsetEncoderPtr( createDefaultEncoder() );
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Object* Class::newInstance() const

Class::ClassMap& Class::getRegistry()
{
static ClassMap registry;
static WideLife<ClassMap> registry;
return registry;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/classnamepatternconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ PatternConverterPtr ClassNamePatternConverter::newInstance(
{
if (options.size() == 0)
{
static PatternConverterPtr def = std::make_shared<ClassNamePatternConverter>(options);
static WideLife<PatternConverterPtr> def = std::make_shared<ClassNamePatternConverter>(options);
return def;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/colorendpatternconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ColorEndPatternConverter::ColorEndPatternConverter() :
PatternConverterPtr ColorEndPatternConverter::newInstance(
const std::vector<LogString>& /* options */)
{
static PatternConverterPtr instance = std::make_shared<ColorEndPatternConverter>();
static WideLife<PatternConverterPtr> instance = std::make_shared<ColorEndPatternConverter>();
return instance;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/colorstartpatternconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ ColorStartPatternConverter::ColorStartPatternConverter() :
PatternConverterPtr ColorStartPatternConverter::newInstance(
const std::vector<LogString>& /* options */)
{
static PatternConverterPtr instance = std::make_shared<ColorStartPatternConverter>();
static WideLife<PatternConverterPtr> instance = std::make_shared<ColorStartPatternConverter>();
return instance;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/cpp/consoleappender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ ConsoleAppender::~ConsoleAppender()

const LogString& ConsoleAppender::getSystemOut()
{
static const LogString name(LOG4CXX_STR("System.out"));
static const WideLife<LogString> name(LOG4CXX_STR("System.out"));
return name;
}

const LogString& ConsoleAppender::getSystemErr()
{
static const LogString name(LOG4CXX_STR("System.err"));
static const WideLife<LogString> name(LOG4CXX_STR("System.err"));
return name;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/cpp/defaultconfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ const LogString DefaultConfigurator::getConfiguratorClass()

const LogString DefaultConfigurator::getConfigurationFileName()
{
static const LogString LOG4CXX_DEFAULT_CONFIGURATION_KEY(LOG4CXX_STR("LOG4CXX_CONFIGURATION"));
static const LogString LOG4J_DEFAULT_CONFIGURATION_KEY(LOG4CXX_STR("log4j.configuration"));
static const WideLife<LogString> LOG4CXX_DEFAULT_CONFIGURATION_KEY(LOG4CXX_STR("LOG4CXX_CONFIGURATION"));
static const WideLife<LogString> LOG4J_DEFAULT_CONFIGURATION_KEY(LOG4CXX_STR("log4j.configuration"));
const LogString log4jConfigurationFileName(
OptionConverter::getSystemProperty(LOG4J_DEFAULT_CONFIGURATION_KEY, LOG4CXX_STR("")));
const LogString configurationFileName(
Expand All @@ -149,7 +149,7 @@ const LogString DefaultConfigurator::getConfigurationFileName()

int DefaultConfigurator::getConfigurationWatchDelay()
{
static const LogString LOG4CXX_DEFAULT_CONFIGURATION_WATCH_KEY(LOG4CXX_STR("LOG4CXX_CONFIGURATION_WATCH_SECONDS"));
static const WideLife<LogString> LOG4CXX_DEFAULT_CONFIGURATION_WATCH_KEY(LOG4CXX_STR("LOG4CXX_CONFIGURATION_WATCH_SECONDS"));
LogString optionStr = OptionConverter::getSystemProperty(LOG4CXX_DEFAULT_CONFIGURATION_WATCH_KEY, LogString());
int milliseconds = 0;
if (!optionStr.empty())
Expand Down
10 changes: 5 additions & 5 deletions src/main/cpp/domconfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,12 +1037,12 @@ void DOMConfigurator::parse(

LogString debugAttrib = subst(getAttribute(utf8Decoder, element, INTERNAL_DEBUG_ATTR));

static const LogString NULL_STRING(LOG4CXX_STR("NULL"));
static const WideLife<LogString> NULL_STRING(LOG4CXX_STR("NULL"));
LogLog::debug(LOG4CXX_STR("debug attribute= \"") + debugAttrib + LOG4CXX_STR("\"."));

// if the log4j.dtd is not specified in the XML file, then the
// "debug" attribute is returned as the empty string.
if (!debugAttrib.empty() && debugAttrib != NULL_STRING)
if (!debugAttrib.empty() && debugAttrib != NULL_STRING.value())
{
LogLog::setInternalDebugging(OptionConverter::toBoolean(debugAttrib, true));
}
Expand All @@ -1054,7 +1054,7 @@ void DOMConfigurator::parse(

LogString confDebug = subst(getAttribute(utf8Decoder, element, CONFIG_DEBUG_ATTR));

if (!confDebug.empty() && confDebug != NULL_STRING)
if (!confDebug.empty() && confDebug != NULL_STRING.value())
{
LogLog::warn(LOG4CXX_STR("The \"configDebug\" attribute is deprecated."));
LogLog::warn(LOG4CXX_STR("Use the \"internalDebug\" attribute instead."));
Expand All @@ -1064,14 +1064,14 @@ void DOMConfigurator::parse(
LogString thresholdStr = subst(getAttribute(utf8Decoder, element, THRESHOLD_ATTR));
LogLog::debug(LOG4CXX_STR("Threshold =\"") + thresholdStr + LOG4CXX_STR("\"."));

if (!thresholdStr.empty() && thresholdStr != NULL_STRING)
if (!thresholdStr.empty() && thresholdStr != NULL_STRING.value())
{
m_priv->repository->setThreshold(thresholdStr);
}

LogString threadSignalValue = subst(getAttribute(utf8Decoder, element, THREAD_CONFIG_ATTR));

if ( !threadSignalValue.empty() && threadSignalValue != NULL_STRING )
if ( !threadSignalValue.empty() && threadSignalValue != NULL_STRING.value() )
{
if ( threadSignalValue == LOG4CXX_STR("NoConfiguration") )
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/filelocationpatternconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ FileLocationPatternConverter::FileLocationPatternConverter() :
PatternConverterPtr FileLocationPatternConverter::newInstance(
const std::vector<LogString>& /* options */ )
{
static PatternConverterPtr instance = std::make_shared<FileLocationPatternConverter>();
static WideLife<PatternConverterPtr> instance = std::make_shared<FileLocationPatternConverter>();
return instance;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/formattinginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ FormattingInfo::~FormattingInfo() {}
*/
FormattingInfoPtr FormattingInfo::getDefault()
{
static FormattingInfoPtr def= std::make_shared<FormattingInfo>(false, 0, INT_MAX);
static helpers::WideLife<FormattingInfoPtr> def= std::make_shared<FormattingInfo>(false, 0, INT_MAX);
return def;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/fulllocationpatternconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ FullLocationPatternConverter::FullLocationPatternConverter() :
PatternConverterPtr FullLocationPatternConverter::newInstance(
const std::vector<LogString>& /* options */)
{
static PatternConverterPtr instance = std::make_shared<FullLocationPatternConverter>();
static WideLife<PatternConverterPtr> instance = std::make_shared<FullLocationPatternConverter>();
return instance;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/hierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ LevelPtr Hierarchy::getThreshold() const

LoggerPtr Hierarchy::getLogger(const LogString& name)
{
static spi::LoggerFactoryPtr defaultFactory = std::make_shared<DefaultLoggerFactory>();
static WideLife<spi::LoggerFactoryPtr> defaultFactory = std::make_shared<DefaultLoggerFactory>();
return getLogger(name, defaultFactory);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/integerpatternconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ IntegerPatternConverter::IntegerPatternConverter() :
PatternConverterPtr IntegerPatternConverter::newInstance(
const std::vector<LogString>& /* options */)
{
static PatternConverterPtr instance = std::make_shared<IntegerPatternConverter>();
static WideLife<PatternConverterPtr> instance = std::make_shared<IntegerPatternConverter>();
return instance;
}

Expand Down
16 changes: 8 additions & 8 deletions src/main/cpp/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,50 @@ IMPLEMENT_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(Level, LevelClass)

LevelPtr Level::getOff()
{
static LevelPtr offLevel = std::make_shared<Level>(Level::OFF_INT, LOG4CXX_STR("OFF"), 0);
static WideLife<LevelPtr> offLevel = std::make_shared<Level>(Level::OFF_INT, LOG4CXX_STR("OFF"), 0);
return offLevel;
}

LevelPtr Level::getFatal()
{
static LevelPtr fatalLevel = std::make_shared<Level>(Level::FATAL_INT, LOG4CXX_STR("FATAL"), 0);
static WideLife<LevelPtr> fatalLevel = std::make_shared<Level>(Level::FATAL_INT, LOG4CXX_STR("FATAL"), 0);
return fatalLevel;
}

LevelPtr Level::getError()
{
static LevelPtr errorLevel = std::make_shared<Level>(Level::ERROR_INT, LOG4CXX_STR("ERROR"), 3);
static WideLife<LevelPtr> errorLevel = std::make_shared<Level>(Level::ERROR_INT, LOG4CXX_STR("ERROR"), 3);
return errorLevel;
}

LevelPtr Level::getWarn()
{
static LevelPtr warnLevel = std::make_shared<Level>(Level::WARN_INT, LOG4CXX_STR("WARN"), 4);
static WideLife<LevelPtr> warnLevel = std::make_shared<Level>(Level::WARN_INT, LOG4CXX_STR("WARN"), 4);
return warnLevel;
}

LevelPtr Level::getInfo()
{
static LevelPtr infoLevel = std::make_shared<Level>(Level::INFO_INT, LOG4CXX_STR("INFO"), 6);
static WideLife<LevelPtr> infoLevel = std::make_shared<Level>(Level::INFO_INT, LOG4CXX_STR("INFO"), 6);
return infoLevel;
}

LevelPtr Level::getDebug()
{
static LevelPtr debugLevel = std::make_shared<Level>(Level::DEBUG_INT, LOG4CXX_STR("DEBUG"), 7);
static WideLife<LevelPtr> debugLevel = std::make_shared<Level>(Level::DEBUG_INT, LOG4CXX_STR("DEBUG"), 7);
return debugLevel;
}

LevelPtr Level::getTrace()
{
static LevelPtr traceLevel = std::make_shared<Level>(Level::TRACE_INT, LOG4CXX_STR("TRACE"), 7);
static WideLife<LevelPtr> traceLevel = std::make_shared<Level>(Level::TRACE_INT, LOG4CXX_STR("TRACE"), 7);
return traceLevel;
}


LevelPtr Level::getAll()
{
static LevelPtr allLevel = std::make_shared<Level>(Level::ALL_INT, LOG4CXX_STR("ALL"), 7);
static WideLife<LevelPtr> allLevel = std::make_shared<Level>(Level::ALL_INT, LOG4CXX_STR("ALL"), 7);
return allLevel;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/levelpatternconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ LevelPatternConverter::LevelPatternConverter() :
PatternConverterPtr LevelPatternConverter::newInstance(
const std::vector<LogString>& /* options */)
{
static PatternConverterPtr def = std::make_shared<LevelPatternConverter>();
static WideLife<PatternConverterPtr> def = std::make_shared<LevelPatternConverter>();
return def;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/linelocationpatternconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ LineLocationPatternConverter::LineLocationPatternConverter() :
PatternConverterPtr LineLocationPatternConverter::newInstance(
const std::vector<LogString>& /* options */)
{
static PatternConverterPtr instance = std::make_shared<LineLocationPatternConverter>();
static WideLife<PatternConverterPtr> instance = std::make_shared<LineLocationPatternConverter>();
return instance;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/lineseparatorpatternconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ LineSeparatorPatternConverter::LineSeparatorPatternConverter() :
PatternConverterPtr LineSeparatorPatternConverter::newInstance(
const std::vector<LogString>& /* options */)
{
static PatternConverterPtr instance = std::make_shared<LineSeparatorPatternConverter>();
static WideLife<PatternConverterPtr> instance = std::make_shared<LineSeparatorPatternConverter>();
return instance;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/literalpatternconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ PatternConverterPtr LiteralPatternConverter::newInstance(
{
if (literal.length() == 1 && literal[0] == 0x20 /* ' ' */)
{
static PatternConverterPtr blank = std::make_shared<LiteralPatternConverter>(literal);
static WideLife<PatternConverterPtr> blank = std::make_shared<LiteralPatternConverter>(literal);
return blank;
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/cpp/locationinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <log4cxx/spi/location/locationinfo.h>
#include <log4cxx/helpers/pool.h>
#include <log4cxx/helpers/widelife.h>

using namespace ::log4cxx::spi;
using namespace log4cxx::helpers;
Expand All @@ -30,7 +31,7 @@ const char* const LocationInfo::NA_METHOD = "?::?";

const LocationInfo& LocationInfo::getLocationUnavailable()
{
static const LocationInfo unavailable;
static const WideLife<LocationInfo> unavailable;
return unavailable;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/loggerpatternconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ PatternConverterPtr LoggerPatternConverter::newInstance(
{
if (options.size() == 0)
{
static PatternConverterPtr def = std::make_shared<LoggerPatternConverter>(options);
static WideLife<PatternConverterPtr> def = std::make_shared<LoggerPatternConverter>(options);
return def;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/cpp/loggingevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ const LogString& LoggingEvent::getCurrentThreadName()
thread_local LogString thread_id_string;
#else
using ListItem = std::pair<ThreadIdType, LogString>;
static std::list<ListItem> thread_id_map;
static std::mutex mutex;
static WideLife<std::list<ListItem>> thread_id_map;
static WideLife<std::mutex> mutex;
std::lock_guard<std::mutex> lock(mutex);
auto pThreadId = std::find_if(thread_id_map.begin(), thread_id_map.end()
, [threadId](const ListItem& item) { return threadId == item.first; });
Expand Down Expand Up @@ -392,7 +392,7 @@ const LogString& LoggingEvent::getCurrentThreadUserName()
#if LOG4CXX_HAS_THREAD_LOCAL
thread_local LogString thread_name;
#else
static LogString thread_name = LOG4CXX_STR("(noname)");
static WideLife<LogString> thread_name = LOG4CXX_STR("(noname)");
#endif
if( !thread_name.empty() ){
return thread_name;
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/loglog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ LogLog::~LogLog(){}

LogLog& LogLog::getInstance()
{
static LogLog internalLogger;
static WideLife<LogLog> internalLogger;

return internalLogger;
}
Expand Down
Loading
Loading