Skip to content
Open
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
3 changes: 2 additions & 1 deletion .github/workflows/log4cxx-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ jobs:
run: |
ROOT=`pwd`
set -x
[ ${{ matrix.logchar }} == unichar ] && OPTIONAL_API=-DLOG4CXX_UNICHAR=ON
cmake \
-DCMAKE_CXX_COMPILER=${{ matrix.cxx }} \
-DLOG4CXX_TEST_ONLY_BUILD=1 \
Expand All @@ -116,7 +117,7 @@ jobs:
-DLOG4CXX_MULTIPROCESS_ROLLING_FILE_APPENDER=${{ matrix.multiprocess }} \
-DLOG4CXX_EVENTS_AT_EXIT=${{ matrix.exitevents }} \
-DBUILD_FUZZERS=${{ matrix.fuzzers }} \
-DLOG4CXX_CHAR=${{ matrix.logchar }} \
-DLOG4CXX_CHAR=${{ matrix.logchar }} $OPTIONAL_API \
-DLOG4CXX_BUILD_NEXT_ABI=${{ matrix.next_abi }} \
-DCMAKE_INSTALL_PREFIX=$ROOT/lib \
-S $ROOT/main \
Expand Down
4 changes: 3 additions & 1 deletion src/main/cpp/asyncbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void AsyncBuffer::renderMessage(LogCharMessageBuffer& msg) const
LOG4CXX_DECODE_WCHAR(lsMsg, wideBuf.extract_str(wideBuf));
msg << lsMsg;
}
#else // !LOG4CXX_LOGCHAR_IS_UTF8
#elif LOG4CXX_LOGCHAR_IS_WCHAR
if (auto pRenderer = std::get_if<WideMessageBufferAppender>(&renderer))
(*pRenderer)(msg);
else
Expand All @@ -169,6 +169,8 @@ void AsyncBuffer::renderMessage(LogCharMessageBuffer& msg) const
LOG4CXX_DECODE_CHAR(lsMsg, narrowBuf.extract_str(narrowBuf));
msg << lsMsg;
}
#else
msg << LOG4CXX_STR("Unichar is not supported");
#endif // !LOG4CXX_LOGCHAR_IS_UTF8
}
#else // !LOG4CXX_CONCEPTS
Expand Down
13 changes: 13 additions & 0 deletions src/main/cpp/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,12 @@ void Logger::addEvent(const LevelPtr& level1, std::basic_string<UniChar>&& messa
{
if (!getHierarchy()) // Has removeHierarchy() been called?
return;
#if LOG4CXX_LOGCHAR_IS_UNICHAR
auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, location, std::move(message));
#else
LOG4CXX_DECODE_UNICHAR(msg, message);
auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, location, std::move(msg));
#endif
callAppenders(event);
}

Expand Down Expand Up @@ -1087,18 +1091,27 @@ void Logger::forcedLog(const LevelPtr& level1, const std::basic_string<UniChar>&
{
if (!getHierarchy()) // Has removeHierarchy() been called?
return;
#if LOG4CXX_LOGCHAR_IS_UNICHAR
auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, message, location);
#else
LOG4CXX_DECODE_UNICHAR(msg, message);
auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, location, std::move(msg));
#endif
callAppenders(event);
}

void Logger::forcedLog(const LevelPtr& level1, const std::basic_string<UniChar>& message) const
{
if (!getHierarchy()) // Has removeHierarchy() been called?
return;
#if LOG4CXX_LOGCHAR_IS_UNICHAR
auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, message,
LocationInfo::getLocationUnavailable());
#else
LOG4CXX_DECODE_UNICHAR(msg, message);
auto event = std::make_shared<LoggingEvent>(m_priv->name, level1, msg,
LocationInfo::getLocationUnavailable());
#endif
callAppenders(event);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/smtpappender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace
// owns SMTP wire-format sanitization (see SMTPSession::toAscii, which silently
// rewrites non-ASCII to '?'); strip CR/LF in the public setters so the same
// boundary is enforced regardless of how the value reaches the appender.
LogString stripSmtpControl(const LogString& value, const logchar* field)
LogString stripSmtpControl(const LogString& value, const LogString& field)
{
if (value.find_first_of(LOG4CXX_STR("\r\n")) == LogString::npos)
{
Expand Down
8 changes: 4 additions & 4 deletions src/main/cpp/threadutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void ThreadUtility::preThreadBlockSignals()

if ( pthread_sigmask(SIG_SETMASK, &set, &old_mask) < 0 )
{
LOGLOG_ERROR( LOG4CXX_STR("Unable to set thread sigmask") );
LogLog::error( LOG4CXX_STR("Unable to set thread sigmask") );
sigmask_valid = false;
}
else
Expand All @@ -207,7 +207,7 @@ void ThreadUtility::threadStartedNameThread(LogString threadName,
#if LOG4CXX_HAS_PTHREAD_SETNAME && !(defined(_WIN32) && defined(_LIBCPP_VERSION))
LOG4CXX_ENCODE_CHAR(sthreadName, threadName);
if (pthread_setname_np(static_cast<pthread_t>(nativeHandle), sthreadName.c_str()) < 0) {
LOGLOG_ERROR(LOG4CXX_STR("unable to set thread name"));
LogLog::error(LOG4CXX_STR("Unable to set thread name"));
}
#elif defined(_WIN32)
typedef HRESULT (WINAPI *TSetThreadDescription)(HANDLE, PCWSTR);
Expand All @@ -227,7 +227,7 @@ void ThreadUtility::threadStartedNameThread(LogString threadName,
{
LOG4CXX_ENCODE_WCHAR(wthreadName, threadName);
if(FAILED(win32Func.SetThreadDescription(static_cast<HANDLE>(nativeHandle), wthreadName.c_str())))
LOGLOG_ERROR( LOG4CXX_STR("unable to set thread name") );
LogLog::error( LOG4CXX_STR("Unable to set thread name") );
}
#endif
}
Expand All @@ -241,7 +241,7 @@ void ThreadUtility::postThreadUnblockSignals()
{
if ( pthread_sigmask(SIG_SETMASK, &old_mask, nullptr) < 0 )
{
LOGLOG_ERROR( LOG4CXX_STR("Unable to set thread sigmask") );
LogLog::error( LOG4CXX_STR("Unable to set thread sigmask") );
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if(${LOG4CXX_CHAR} STREQUAL "unichar")
set(LOGCHAR_IS_UNICHAR 1)
set(LOGCHAR_IS_WCHAR 0)
set(LOGCHAR_IS_UTF8 0)
set(ENABLE_FMT_ASYNC 0)
elseif(${LOG4CXX_CHAR} STREQUAL "wchar_t")
set(LOGCHAR_IS_WCHAR 1)
set(LOGCHAR_IS_UNICHAR 0)
Expand Down
9 changes: 7 additions & 2 deletions src/main/include/log4cxx/helpers/asyncbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class LOG4CXX_EXPORT AsyncBuffer
#endif // LOG4CXX_WCHAR_T_API
else
static_assert(false, "operator<<(std::ostream&) overload must be provided");
#else // !LOG4CXX_LOGCHAR_IS_UTF8
#elif LOG4CXX_LOGCHAR_IS_WCHAR
if constexpr (requires(std::wostream& buf, T v) { buf << v; })
{
append([value](WideMessageBuffer& msgBuf)
Expand All @@ -112,7 +112,12 @@ class LOG4CXX_EXPORT AsyncBuffer
}
else
static_assert(false, "operator<<(std::wostream&) overload must be provided");
#endif // !LOG4CXX_LOGCHAR_IS_UTF8
#else // LOG4CXX_LOGCHAR_IS_WCHAR
append([value](LogCharMessageBuffer& msgBuf)
{
msgBuf << value;
});
#endif // !LOG4CXX_LOGCHAR_IS_UTF8&& !LOG4CXX_LOGCHAR_IS_WCHAR
#else // !LOG4CXX_CONCEPTS
append([value](LogCharMessageBuffer& msgBuf)
{
Expand Down
2 changes: 1 addition & 1 deletion src/test/cpp/helpers/simpledateformattestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ LOGUNIT_CLASS(SimpleDateFormatTestCase)
, (apr_time_t) APR_INT64_C(-9000000000000000000)
};

const logchar* patterns[] =
const LogString patterns[] =
{ LOG4CXX_STR("EEE")
, LOG4CXX_STR("EEEE")
, LOG4CXX_STR("MMM")
Expand Down
26 changes: 12 additions & 14 deletions src/test/cpp/hexdumptestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ LOGUNIT_CLASS(HexdumpTestCase)
0x73, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c,
0x61, 0x7a, 0x79, 0x20, 0x64, 0x6f, 0x67
};
LogString expectedOutput =
LOG4CXX_STR("00000000 54 68 65 20 71 75 69 63 6b 20 62 72 6f 77 6e 20 |The quick brown |")
LOG4CXX_EOL
LOG4CXX_STR("00000010 66 6f 78 20 6a 75 6d 70 73 20 6f 76 65 72 20 74 |fox jumps over t|")
LOG4CXX_EOL
LOG4CXX_STR("00000020 68 65 20 6c 61 7a 79 20 64 6f 67 |he lazy dog|");
LogString expectedOutput =
LOG4CXX_STR("00000000 54 68 65 20 71 75 69 63 6b 20 62 72 6f 77 6e 20 |The quick brown |");
expectedOutput += LOG4CXX_EOL;
expectedOutput += LOG4CXX_STR("00000010 66 6f 78 20 6a 75 6d 70 73 20 6f 76 65 72 20 74 |fox jumps over t|");
expectedOutput += LOG4CXX_EOL;
expectedOutput += LOG4CXX_STR("00000020 68 65 20 6c 61 7a 79 20 64 6f 67 |he lazy dog|");

// Hexdump up until the NULL char
LogString dumped = log4cxx::hexdump(quick_brown_fox, sizeof(quick_brown_fox));
Expand All @@ -77,10 +77,9 @@ LOGUNIT_CLASS(HexdumpTestCase)
unsigned char test1_str[] = {
0x74, 0x65, 0x73, 0x74, 0x31
};
LogString expectedOutput =
LOG4CXX_EOL
LOG4CXX_STR("00000000 74 65 73 74 31 |test1|")
LOG4CXX_EOL;
LogString expectedOutput = LOG4CXX_EOL;
expectedOutput += LOG4CXX_STR("00000000 74 65 73 74 31 |test1|");
expectedOutput += LOG4CXX_EOL;

LogString dumped = log4cxx::hexdump(test1_str, sizeof(test1_str), HexdumpFlags::AddNewline);
LOGUNIT_ASSERT_EQUAL(expectedOutput, dumped);
Expand All @@ -91,10 +90,9 @@ LOGUNIT_CLASS(HexdumpTestCase)
unsigned char test1_str[] = {
0x74, 0x65, 0x73, 0x74, 0x31
};
LogString expectedOutput =
LOG4CXX_EOL
LOG4CXX_STR("00000000 74 65 73 74 31 |test1|")
LOG4CXX_EOL;
LogString expectedOutput = LOG4CXX_EOL;
expectedOutput += LOG4CXX_STR("00000000 74 65 73 74 31 |test1|");
expectedOutput += LOG4CXX_EOL;

LogString dumped = log4cxx::hexdump(test1_str, sizeof(test1_str), HexdumpFlags::AddStartingNewline | HexdumpFlags::AddEndingNewline);
LOGUNIT_ASSERT_EQUAL(expectedOutput, dumped);
Expand Down
Loading