Skip to content

Commit

Permalink
another scheme, without ABI-15 breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
vopl committed Nov 6, 2023
1 parent 4ee62a2 commit 38c9d9f
Show file tree
Hide file tree
Showing 31 changed files with 59 additions and 163 deletions.
2 changes: 0 additions & 2 deletions src/examples/cpp/custom-appender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class NullWriterAppender : public log4cxx::AppenderSkeleton {
return false;
}

void flushBuffers() override{}

void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p) override {
// This gets called whenever there is a valid event for our appender.
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ target_sources(log4cxx
${extra_classes}
)

if(LOG4CXX_EVENTS_AT_EXIT)
target_sources(log4cxx
PRIVATE atexitregistry.cpp
)
endif(WIN32)

if(WIN32)
target_sources(log4cxx
PRIVATE visualstudio.natvis
Expand Down
6 changes: 0 additions & 6 deletions src/main/cpp/appenderattachableimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,4 @@ void AppenderAttachableImpl::removeAppender(const LogString& name)
}
}

void AppenderAttachableImpl::flushBuffers()
{
std::lock_guard<std::recursive_mutex> lock( m_priv->m_mutex );
for(const AppenderPtr& appender : m_priv->appenderList)
appender->flushBuffers();
}

33 changes: 24 additions & 9 deletions src/main/cpp/asyncappender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#include <log4cxx/helpers/threadutility.h>
#include <log4cxx/private/appenderskeleton_priv.h>

#if LOG4CXX_EVENTS_AT_EXIT
#include <log4cxx/private/atexitregistry.h>
#endif

using namespace LOG4CXX_NS;
using namespace LOG4CXX_NS::helpers;
using namespace LOG4CXX_NS::spi;
Expand Down Expand Up @@ -103,7 +107,22 @@ struct AsyncAppender::AsyncAppenderPriv : public AppenderSkeleton::AppenderSkele
appenders(std::make_shared<AppenderAttachableImpl>(pool)),
dispatcher(),
locationInfo(false),
blocking(true) {}
blocking(true)
#if LOG4CXX_EVENTS_AT_EXIT
, atExitRegistryRaii([this]{atExitActivated();})
#endif
{
}

#if LOG4CXX_EVENTS_AT_EXIT
void atExitActivated()
{
std::unique_lock<std::mutex> lock(bufferMutex);
bufferNotFull.wait(lock, [this]() -> bool
{ return buffer.empty() || closed; }
);
}
#endif

/**
* Event buffer.
Expand Down Expand Up @@ -157,6 +176,10 @@ struct AsyncAppender::AsyncAppenderPriv : public AppenderSkeleton::AppenderSkele
* Does appender block when buffer is full.
*/
bool blocking;

#if LOG4CXX_EVENTS_AT_EXIT
helpers::AtExitRegistry::Raii atExitRegistryRaii;
#endif
};


Expand Down Expand Up @@ -341,14 +364,6 @@ bool AsyncAppender::requiresLayout() const
return false;
}

void AsyncAppender::flushBuffers()
{
std::unique_lock<std::mutex> lock(priv->bufferMutex);
priv->bufferNotFull.wait(lock, [this]() -> bool
{ return priv->buffer.empty() || priv->closed; }
);
}

void AsyncAppender::removeAllAppenders()
{
priv->appenders->removeAllAppenders();
Expand Down
10 changes: 0 additions & 10 deletions src/main/cpp/hierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,16 +474,6 @@ bool Hierarchy::isConfigured()
return m_priv->configured;
}

void Hierarchy::flushBuffers()
{
std::unique_lock<std::mutex> lock(m_priv->mutex);
for (auto& item : m_priv->loggers)
if (auto& pLogger = item.second)
pLogger->flushBuffers();
if (m_priv->root)
m_priv->root->flushBuffers();
}

HierarchyPtr Hierarchy::create()
{
HierarchyPtr ret(new Hierarchy);
Expand Down
5 changes: 0 additions & 5 deletions src/main/cpp/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,6 @@ void Logger::removeAppender(const LogString& name1)
m_priv->aai.removeAppender(name1);
}

void Logger::flushBuffers()
{
m_priv->aai.flushBuffers();
}

void Logger::removeHierarchy()
{
m_priv->repositoryRaw = 0;
Expand Down
19 changes: 0 additions & 19 deletions src/main/cpp/logmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,25 +200,6 @@ LoggerList LogManager::getCurrentLoggers()
return getLoggerRepository()->getCurrentLoggers();
}

void LogManager::flushBuffers()
{
getLoggerRepository()->flushBuffers();
}

#if LOG4CXX_EVENTS_AT_EXIT
// initiate buffers flush at static deinitialization phase
namespace
{
struct FlushBuffersAtExit
{
~FlushBuffersAtExit()
{
LogManager::flushBuffers();
}
} s_flushBuffersAtExit;
}
#endif

void LogManager::shutdown()
{
APRInitializer::unregisterAll();
Expand Down
5 changes: 0 additions & 5 deletions src/main/cpp/smtpappender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,6 @@ bool SMTPAppender::requiresLayout() const
return true;
}

void SMTPAppender::flushBuffers()
{
sendBuffer(_priv->pool);
}

LogString SMTPAppender::getFrom() const
{
return _priv->from;
Expand Down
6 changes: 0 additions & 6 deletions src/main/cpp/writerappender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,6 @@ bool WriterAppender::requiresLayout() const
return true;
}

void WriterAppender::flushBuffers()
{
if (_priv->layout != NULL)
_priv->writer->flush(_priv->pool);
}

void WriterAppender::setOption(const LogString& option, const LogString& value)
{
if (StringHelper::equalsIgnoreCase(option, LOG4CXX_STR("ENCODING"), LOG4CXX_STR("encoding")))
Expand Down
5 changes: 0 additions & 5 deletions src/main/include/log4cxx/appender.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ class LOG4CXX_EXPORT Appender :
the appender should return <code>true</code>.
*/
virtual bool requiresLayout() const = 0;

/**
Flush all buffered data if present.
*/
virtual void flushBuffers() = 0;
};

LOG4CXX_PTR_DEF(Appender);
Expand Down
5 changes: 0 additions & 5 deletions src/main/include/log4cxx/asyncappender.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ class LOG4CXX_EXPORT AsyncAppender :

bool requiresLayout() const override;

/**
* Flush all buffered data if present.
*/
void flushBuffers() override;

/**
* Removes and closes all attached appenders.
*/
Expand Down
5 changes: 0 additions & 5 deletions src/main/include/log4cxx/db/dbappender.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,6 @@ class LOG4CXX_EXPORT DBAppender : public AppenderSkeleton
return false;
}

/**
* There are no bufferred data here, no action required
* */
void flushBuffers() override {}

/**
* Set pre-formated statement eg: insert into LogTable (msg) values (?)
*/
Expand Down
7 changes: 0 additions & 7 deletions src/main/include/log4cxx/db/odbcappender.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,6 @@ class LOG4CXX_EXPORT ODBCAppender : public AppenderSkeleton
* */
bool requiresLayout() const override;

/**
* There are no bufferred data here, no action required
* */
void flushBuffers() override
{
}

/**
* Set pre-formated statement eg: insert into LogTable (msg) values ("%m")
*/
Expand Down
5 changes: 0 additions & 5 deletions src/main/include/log4cxx/helpers/appenderattachableimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ class LOG4CXX_EXPORT AppenderAttachableImpl :
*/
void removeAppender(const LogString& name) override;

/**
* Flush all buffered data if present.
*/
void flushBuffers() override;

private:
LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(priv_data, m_priv)

Expand Down
5 changes: 0 additions & 5 deletions src/main/include/log4cxx/hierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,6 @@ class LOG4CXX_EXPORT Hierarchy : public spi::LoggerRepository
virtual bool isConfigured() override;
virtual void setConfigured(bool configured) override;

/**
Flush all buffered data in all appenders if present.
*/
void flushBuffers() override;

/**
Refresh the threshold in children of parent
*/
Expand Down
5 changes: 0 additions & 5 deletions src/main/include/log4cxx/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -1652,11 +1652,6 @@ class LOG4CXX_EXPORT Logger :
*/
void removeAppender(const LogString& name) override;

/**
Flush all buffered data in all downstream appenders if present.
*/
void flushBuffers() override;

/**
Set the additivity flag for this logger.
*/
Expand Down
5 changes: 0 additions & 5 deletions src/main/include/log4cxx/logmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,6 @@ class LOG4CXX_EXPORT LogManager

static LoggerList getCurrentLoggers();

/**
Flush all buffered data in all loggers/appenders if present.
*/
static void flushBuffers();

/**
Safely close and remove all appenders in all loggers including
the root logger.
Expand Down
5 changes: 0 additions & 5 deletions src/main/include/log4cxx/net/smtpappender.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,6 @@ class LOG4CXX_EXPORT SMTPAppender : public AppenderSkeleton
*/
bool requiresLayout() const override;

/**
Flush all buffered data if present.
*/
void flushBuffers() override;

/**
Send the contents of the cyclic buffer as an e-mail message.
*/
Expand Down
7 changes: 0 additions & 7 deletions src/main/include/log4cxx/net/socketappenderskeleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ class LOG4CXX_EXPORT SocketAppenderSkeleton : public AppenderSkeleton
return false;
}

/**
* There are no bufferred data here, no action required
* */
void flushBuffers() override
{
}

/**
* The <b>RemoteHost</b> option takes a string value which should be
* the host name of the server where a
Expand Down
7 changes: 0 additions & 7 deletions src/main/include/log4cxx/net/syslogappender.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ class LOG4CXX_EXPORT SyslogAppender : public AppenderSkeleton
return true;
}

/**
* There are no bufferred data here, no action required
* */
void flushBuffers() override
{
}

/**
The <b>SyslogHost</b> option is the name of the the syslog host
where log output should go.
Expand Down
7 changes: 0 additions & 7 deletions src/main/include/log4cxx/net/telnetappender.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ class LOG4CXX_EXPORT TelnetAppender : public AppenderSkeleton
return true;
}

/**
* There are no bufferred data here, no action required
* */
void flushBuffers() override
{
}

/**
The current encoding value.
Expand Down
5 changes: 0 additions & 5 deletions src/main/include/log4cxx/nt/nteventlogappender.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ class LOG4CXX_EXPORT NTEventLogAppender : public AppenderSkeleton
return true;
}

/**
* There are no bufferred data here, no action required
* */
void flushBuffers() override {}

void setSource(const LogString& source);

const LogString& getSource() const;
Expand Down
2 changes: 0 additions & 2 deletions src/main/include/log4cxx/nt/outputdebugstringappender.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class LOG4CXX_EXPORT OutputDebugStringAppender : public AppenderSkeleton
void close() override {}

void append(const spi::LoggingEventPtr& event, helpers::Pool& p) override;

void flushBuffers() override {}
};
}
}
Expand Down
Loading

0 comments on commit 38c9d9f

Please sign in to comment.