Skip to content

Commit

Permalink
using a logger with a custom namespace is simplified by the 'namespac…
Browse files Browse the repository at this point in the history
…e log4cxx=LOG4CXX_NS' alias introduced
  • Loading branch information
vopl committed Nov 1, 2023
1 parent 986274c commit 827f212
Show file tree
Hide file tree
Showing 125 changed files with 417 additions and 413 deletions.
6 changes: 1 addition & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ endif()

option(BUILD_EXAMPLES "Build log4cxx examples" ${BUILD_TESTING})
if(BUILD_EXAMPLES)
if("log4cxx" STREQUAL "${LOG4CXX_NS}")
add_subdirectory(examples/cpp)
else()
message(FATAL_ERROR "Examples can only be build if LOG4CXX_NS=log4cxx, but LOG4CXX_NS=${LOG4CXX_NS}.")
endif()
add_subdirectory(examples/cpp)
endif()

add_subdirectory(site)
2 changes: 1 addition & 1 deletion src/examples/cpp/custom-appender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <log4cxx/helpers/stringhelper.h>
#include <log4cxx/xml/domconfigurator.h>

namespace log4cxx {
namespace LOG4CXX_NS {

class NullWriterAppender : public log4cxx::AppenderSkeleton {
public:
Expand Down
4 changes: 4 additions & 0 deletions src/main/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ else()
endif()

set(LOG4CXX_NS "log4cxx" CACHE STRING "Root namespace name")
set(LOG4CXX_DECLARE_DEFAULT_NS_ALIAS 0)
if(NOT "log4cxx" STREQUAL "${LOG4CXX_NS}")
set(LOG4CXX_DECLARE_DEFAULT_NS_ALIAS 1)
endif()

# Configure log4cxx_private.h
set(LOG4CXX_CHARSET "utf-8" CACHE STRING "LogString characters, choice of utf-8 (default), ISO-8859-1, US-ASCII, EBCDIC, locale")
Expand Down
4 changes: 4 additions & 0 deletions src/main/include/log4cxx/log4cxx.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,8 @@ LOG4CXX_EXPORT uint32_t libraryVersion();

}

#if @LOG4CXX_DECLARE_DEFAULT_NS_ALIAS@
namespace log4cxx = LOG4CXX_NS;
#endif

#endif
4 changes: 2 additions & 2 deletions src/test/cpp/appenderskeletontestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include <log4cxx/appenderskeleton.h>


using namespace LOG4CXX_NS;
using namespace LOG4CXX_NS::helpers;
using namespace log4cxx;
using namespace log4cxx::helpers;


void AppenderSkeletonTestCase::testDefaultThreshold()
Expand Down
2 changes: 1 addition & 1 deletion src/test/cpp/appenderskeletontestcase.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ LOGUNIT_CLASS(AppenderSkeletonTestCase)
{

public:
virtual LOG4CXX_NS::AppenderSkeleton* createAppenderSkeleton() const = 0;
virtual log4cxx::AppenderSkeleton* createAppenderSkeleton() const = 0;

void testDefaultThreshold();

Expand Down
16 changes: 8 additions & 8 deletions src/test/cpp/asyncappendertestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
#include <log4cxx/xml/domconfigurator.h>
#include <log4cxx/file.h>

using namespace LOG4CXX_NS;
using namespace LOG4CXX_NS::helpers;
using namespace LOG4CXX_NS::spi;
using namespace log4cxx;
using namespace log4cxx::helpers;
using namespace log4cxx::spi;

class NullPointerAppender : public AppenderSkeleton
{
Expand All @@ -48,7 +48,7 @@ class NullPointerAppender : public AppenderSkeleton
/**
* @{inheritDoc}
*/
void append(const spi::LoggingEventPtr&, LOG4CXX_NS::helpers::Pool&) override
void append(const spi::LoggingEventPtr&, log4cxx::helpers::Pool&) override
{
throw NullPointerException(LOG4CXX_STR("Intentional NullPointerException"));
}
Expand Down Expand Up @@ -81,7 +81,7 @@ class BlockableVectorAppender : public VectorAppender
/**
* {@inheritDoc}
*/
void append(const spi::LoggingEventPtr& event, LOG4CXX_NS::helpers::Pool& p) override
void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p) override
{
std::unique_lock<std::mutex> lock( blocker );
VectorAppender::append(event, p);
Expand Down Expand Up @@ -285,14 +285,14 @@ class AsyncAppenderTestCase : public AppenderSkeletonTestCase
LoggingEventPtr discardEvent = events[events.size() - 1];
LOGUNIT_ASSERT(initialEvent->getMessage() == LOG4CXX_STR("Hello, World"));
LOGUNIT_ASSERT(discardEvent->getMessage().substr(0, 10) == LOG4CXX_STR("Discarded "));
LOGUNIT_ASSERT_EQUAL(LOG4CXX_NS::spi::LocationInfo::getLocationUnavailable().getClassName(),
LOGUNIT_ASSERT_EQUAL(log4cxx::spi::LocationInfo::getLocationUnavailable().getClassName(),
discardEvent->getLocationInformation().getClassName());
}

void testConfiguration()
{
LOG4CXX_NS::xml::DOMConfigurator::configure("input/xml/asyncAppender1.xml");
AsyncAppenderPtr asyncAppender = LOG4CXX_NS::cast<AsyncAppender>(Logger::getRootLogger()->getAppender(LOG4CXX_STR("ASYNC")));
log4cxx::xml::DOMConfigurator::configure("input/xml/asyncAppender1.xml");
AsyncAppenderPtr asyncAppender = log4cxx::cast<AsyncAppender>(Logger::getRootLogger()->getAppender(LOG4CXX_STR("ASYNC")));
LOGUNIT_ASSERT(!(asyncAppender == 0));
LOGUNIT_ASSERT_EQUAL(100, asyncAppender->getBufferSize());
LOGUNIT_ASSERT_EQUAL(false, asyncAppender->getBlocking());
Expand Down
2 changes: 1 addition & 1 deletion src/test/cpp/autoconfiguretestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
} \
} register ## testName ## ThreadTest

using namespace LOG4CXX_NS;
using namespace log4cxx;

LOGUNIT_CLASS(AutoConfigureTestCase)
{
Expand Down
6 changes: 3 additions & 3 deletions src/test/cpp/benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <benchmark/benchmark.h>
#include <thread>

using namespace LOG4CXX_NS;
using namespace log4cxx;

class NullWriterAppender : public AppenderSkeleton
{
Expand Down Expand Up @@ -49,8 +49,8 @@ IMPLEMENT_LOG4CXX_OBJECT(NullWriterAppender)
LOG4CXX_PTR_DEF(NullWriterAppender);
#else
#define LOG4CXX_HAS_FMT 0
template class LOG4CXX_NS::helpers::ObjectPtrT<NullWriterAppender>;
typedef LOG4CXX_NS::helpers::ObjectPtrT<NullWriterAppender> NullWriterAppenderPtr;
template class log4cxx::helpers::ObjectPtrT<NullWriterAppender>;
typedef log4cxx::helpers::ObjectPtrT<NullWriterAppender> NullWriterAppenderPtr;
#endif

class benchmarker : public ::benchmark::Fixture
Expand Down
6 changes: 3 additions & 3 deletions src/test/cpp/consoleappendertestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "logunit.h"
#include "writerappendertestcase.h"

using namespace LOG4CXX_NS;
using namespace LOG4CXX_NS::helpers;
using namespace log4cxx;
using namespace log4cxx::helpers;

/**
Unit tests of ConsoleAppender.
Expand All @@ -41,7 +41,7 @@ class ConsoleAppenderTestCase : public WriterAppenderTestCase

WriterAppender* createWriterAppender() const
{
return new LOG4CXX_NS::ConsoleAppender();
return new log4cxx::ConsoleAppender();
}

void testNoLayout()
Expand Down
6 changes: 3 additions & 3 deletions src/test/cpp/customlogger/xlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <log4cxx/spi/loggerrepository.h>


using namespace LOG4CXX_NS;
using namespace LOG4CXX_NS::spi;
using namespace log4cxx;
using namespace log4cxx::spi;

IMPLEMENT_LOG4CXX_OBJECT(XLogger)
IMPLEMENT_LOG4CXX_OBJECT(XFactory)
Expand Down Expand Up @@ -104,7 +104,7 @@ XFactory::XFactory()
{
}

LoggerPtr XFactory::makeNewLoggerInstance(LOG4CXX_NS::helpers::Pool& pool,
LoggerPtr XFactory::makeNewLoggerInstance(log4cxx::helpers::Pool& pool,
const LogString& name) const
{
return LoggerPtr(new XLogger(pool, name));
Expand Down
8 changes: 4 additions & 4 deletions src/test/cpp/customlogger/xlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class XFactory :

XFactory();
LoggerPtr makeNewLoggerInstance(
LOG4CXX_NS::helpers::Pool& pool,
log4cxx::helpers::Pool& pool,
const LogString& name) const override;
};

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

/**
Expand All @@ -84,7 +84,7 @@ class XLogger : public Logger
/**
We introduce a new printing method in order to support {@link
XLevel#LETHAL}. */
void lethal(const LogString& message, const LOG4CXX_NS::spi::LocationInfo& location);
void lethal(const LogString& message, const log4cxx::spi::LocationInfo& location);

/**
We introduce a new printing method in order to support {@link
Expand All @@ -108,7 +108,7 @@ class XLogger : public Logger
/**
We introduce a new printing method that takes the TRACE level.
*/
void trace(const LogString& message, const LOG4CXX_NS::spi::LocationInfo& location);
void trace(const LogString& message, const log4cxx::spi::LocationInfo& location);

/**
We introduce a new printing method that takes the TRACE level.
Expand Down
8 changes: 4 additions & 4 deletions src/test/cpp/customlogger/xloggertestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include "../util/compare.h"
#include <log4cxx/file.h>

using namespace LOG4CXX_NS;
using namespace LOG4CXX_NS::helpers;
using namespace LOG4CXX_NS::xml;
using namespace log4cxx;
using namespace log4cxx::helpers;
using namespace log4cxx::xml;

#define LOG4CXX_TEST_STR(x) L##x

Expand Down Expand Up @@ -77,7 +77,7 @@ LOGUNIT_CLASS(XLoggerTestCase)
DOMConfigurator::configure(fn);

int i = 0;
LOG4CXX_LOG(logger, LOG4CXX_NS::XLevel::getTrace(), "Message " << i);
LOG4CXX_LOG(logger, log4cxx::XLevel::getTrace(), "Message " << i);

i++;
LOG4CXX_DEBUG(logger, "Message " << i);
Expand Down
2 changes: 1 addition & 1 deletion src/test/cpp/db/odbcappendertestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#ifdef LOG4CXX_HAVE_ODBC

using namespace LOG4CXX_NS;
using namespace log4cxx;

/**
Unit tests of log4cxx::SocketAppender
Expand Down
4 changes: 2 additions & 2 deletions src/test/cpp/decodingtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
//
#if LOG4CXX_WCHAR_T_API

using namespace LOG4CXX_NS;
using namespace LOG4CXX_NS::helpers;
using namespace log4cxx;
using namespace log4cxx::helpers;

/**
* Tests support for decoding specification.
Expand Down
2 changes: 1 addition & 1 deletion src/test/cpp/defaultinit/testcase1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <log4cxx/logmanager.h>
#include <log4cxx/logger.h>

using namespace LOG4CXX_NS;
using namespace log4cxx;

LOGUNIT_CLASS(TestCase1)
{
Expand Down
2 changes: 1 addition & 1 deletion src/test/cpp/defaultinit/testcase2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "../insertwide.h"
#include "../logunit.h"

using namespace LOG4CXX_NS;
using namespace log4cxx;

LOGUNIT_CLASS(TestCase2)
{
Expand Down
2 changes: 1 addition & 1 deletion src/test/cpp/defaultinit/testcase3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "../insertwide.h"
#include "../logunit.h"

using namespace LOG4CXX_NS;
using namespace log4cxx;

LOGUNIT_CLASS(TestCase3)
{
Expand Down
2 changes: 1 addition & 1 deletion src/test/cpp/defaultinit/testcase4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "../insertwide.h"
#include "../logunit.h"

using namespace LOG4CXX_NS;
using namespace log4cxx;

LOGUNIT_CLASS(TestCase4)
{
Expand Down
6 changes: 3 additions & 3 deletions src/test/cpp/encodingtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
#include <log4cxx/file.h>
#include <log4cxx/helpers/pool.h>

using namespace LOG4CXX_NS;
using namespace LOG4CXX_NS::util;
using namespace LOG4CXX_NS::helpers;
using namespace log4cxx;
using namespace log4cxx::util;
using namespace log4cxx::helpers;

/**
* Tests support for encoding specification.
Expand Down
2 changes: 1 addition & 1 deletion src/test/cpp/eventsatexittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include <log4cxx/logger.h>

using namespace LOG4CXX_NS;
using namespace log4cxx;

static struct Static
{
Expand Down
4 changes: 2 additions & 2 deletions src/test/cpp/fileappendertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include <log4cxx/patternlayout.h>
#include "logunit.h"

using namespace LOG4CXX_NS;
using namespace LOG4CXX_NS::helpers;
using namespace log4cxx;
using namespace log4cxx::helpers;


/**
Expand Down
6 changes: 3 additions & 3 deletions src/test/cpp/fileappendertestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include <log4cxx/fileappender.h>
#include "insertwide.h"

using namespace LOG4CXX_NS;
using namespace LOG4CXX_NS::helpers;
using namespace log4cxx;
using namespace log4cxx::helpers;

WriterAppender* FileAppenderAbstractTestCase::createWriterAppender() const
{
Expand Down Expand Up @@ -53,7 +53,7 @@ class FileAppenderTestCase : public FileAppenderAbstractTestCase

FileAppender* createFileAppender() const
{
return new LOG4CXX_NS::FileAppender();
return new log4cxx::FileAppender();
}

void testSetDoubleBackslashes()
Expand Down
4 changes: 2 additions & 2 deletions src/test/cpp/fileappendertestcase.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class FileAppenderAbstractTestCase : public WriterAppenderTestCase
{

public:
LOG4CXX_NS::WriterAppender* createWriterAppender() const;
log4cxx::WriterAppender* createWriterAppender() const;

virtual LOG4CXX_NS::FileAppender* createFileAppender() const = 0;
virtual log4cxx::FileAppender* createFileAppender() const = 0;

};
6 changes: 3 additions & 3 deletions src/test/cpp/filetestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#include <CoreFoundation/CFString.h>
#endif

using namespace LOG4CXX_NS;
using namespace LOG4CXX_NS::helpers;
using namespace log4cxx;
using namespace log4cxx::helpers;


LOGUNIT_CLASS(FileTestCase)
Expand Down Expand Up @@ -119,7 +119,7 @@ LOGUNIT_CLASS(FileTestCase)
#if LOG4CXX_UNICHAR_API
void unicharConstructor()
{
const LOG4CXX_NS::UniChar filename[] = { 'i', 'n', 'p', 'u', 't', '/',
const log4cxx::UniChar filename[] = { 'i', 'n', 'p', 'u', 't', '/',
'p', 'a', 't', 't', 'e', 'r', 'n', 'L', 'a', 'y', 'o', 'u', 't', '1', '.',
'p', 'r', 'o', 'p', 'e', 'r', 't', 'i', 'e', 's', 0
};
Expand Down
8 changes: 4 additions & 4 deletions src/test/cpp/filter/andfiltertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
#include <log4cxx/filter/stringmatchfilter.h>
#include "../logunit.h"

using namespace LOG4CXX_NS;
using namespace LOG4CXX_NS::filter;
using namespace LOG4CXX_NS::spi;
using namespace LOG4CXX_NS::helpers;
using namespace log4cxx;
using namespace log4cxx::filter;
using namespace log4cxx::spi;
using namespace log4cxx::helpers;


/**
Expand Down
Loading

0 comments on commit 827f212

Please sign in to comment.