Skip to content

Commit

Permalink
Merge branch 'master' into add_qstring_support
Browse files Browse the repository at this point in the history
  • Loading branch information
swebb2066 authored Aug 9, 2023
2 parents 7fb4a4c + 78d8e82 commit d02e134
Show file tree
Hide file tree
Showing 27 changed files with 232 additions and 42 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/log4cxx-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,30 @@ jobs:
os: ubuntu-20.04
cxx: g++
cc: gcc
fmt: OFF
qt: ON
odbc: OFF
- name: ubuntu20-clang
os: ubuntu-20.04
cxx: clang++
cc: clang
fmt: ON
qt: OFF
odbc: ON
- name: ubuntu22-gcc
os: ubuntu-22.04
cxx: g++
cc: gcc
fmt: OFF
qt: OFF
odbc: OFF
- name: ubuntu22-clang
os: ubuntu-22.04
cxx: clang++
cc: clang
fmt: ON
qt: OFF
odbc: OFF

steps:
- uses: actions/checkout@v3
Expand All @@ -51,14 +63,17 @@ jobs:
- name: 'Configure Dependencies'
run: |
sudo apt-get update
sudo apt-get install -y libapr1-dev libaprutil1-dev libfmt-dev unixodbc-dev
sudo apt-get install -y libapr1-dev libaprutil1-dev
if [ ${{ matrix.fmt }} == ON ]; then sudo apt-get install -y libfmt-dev; fi
if [ ${{ matrix.odbc }} == ON ]; then sudo apt-get install -y unixodbc-dev; fi
if [ ${{ matrix.qt }} == ON ]; then sudo apt-get install -y qtbase5-dev; fi
- name: 'run cmake - posix'
run: |
cd main
mkdir build
cd build
cmake -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} -DCMAKE_C_COMPILER=${{ matrix.cc }} -DLOG4CXX_ENABLE_ODBC=ON ..
cmake -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} -DCMAKE_C_COMPILER=${{ matrix.cc }} -DLOG4CXX_ENABLE_ODBC=${{ matrix.odbc }} -DLOG4CXX_QT_SUPPORT=${{ matrix.qt }} ..
cmake --build .
- name: run unit tests
Expand Down
3 changes: 3 additions & 0 deletions src/cmake/win32_target_environment_path.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ function(get_target_environment_path varName)
set(EXPAT_DLL_DIR "${EXPAT_LIB_DIR}/../bin")
set(LOG4CXX_DLL_DIR "$<SHELL_PATH:$<TARGET_FILE_DIR:${LOG4CXX_LIB_NAME}>>;")
set(PATH_FOR_TESTS ${CMAKE_PROGRAM_PATH};${APR_DLL_DIR};${APR_UTIL_DLL_DIR};${LOG4CXX_DLL_DIR};${EXPAT_DLL_DIR}\;)
if(LOG4CXX_QT_SUPPORT)
list(APPEND PATH_FOR_TESTS "$<SHELL_PATH:$<TARGET_FILE_DIR:log4cxx-qt>>\;")
endif(LOG4CXX_QT_SUPPORT)
list(REMOVE_DUPLICATES PATH_FOR_TESTS)

# Note: we need to include the APR DLLs on our path so that the tests will run.
Expand Down
3 changes: 2 additions & 1 deletion src/examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#

set(ALL_LOG4CXX_EXAMPLES auto-configured console delayedloop stream trivial custom-appender MyApp1 MyApp2)
set(ALL_LOG4CXX_EXAMPLES auto-configured console delayedloop stream ndc-example custom-appender MyApp1 MyApp2)
if(LOG4CXX_QT_SUPPORT)
list(APPEND ALL_LOG4CXX_EXAMPLES MyApp-qt)
endif(LOG4CXX_QT_SUPPORT)
Expand All @@ -39,6 +39,7 @@ foreach(exampleName IN LISTS ALL_LOG4CXX_EXAMPLES)
endif()
if(${exampleName} STREQUAL MyApp-qt)
target_sources(${PROGRAM_NAME} PRIVATE com/foo/config-qt.cpp com/foo/bar-qt.cpp)
target_link_libraries(${PROGRAM_NAME} PRIVATE log4cxx-qt)
endif()
if(${exampleName} STREQUAL auto-configured)
target_sources(${PROGRAM_NAME} PRIVATE com/foo/config3.cpp )
Expand Down
4 changes: 2 additions & 2 deletions src/examples/cpp/MyApp-qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ int main(int argc, char **argv) {
com::foo::ConfigureLogging();
try {
auto logger = com::foo::getLogger("MyApp");
LOG4CXX_INFO(logger, "Entering application.");
LOG4CXX_INFO(logger, QString("Message %1").arg(1));
com::foo::Bar bar;
bar.doIt();
LOG4CXX_INFO(logger, "Exiting application.");
LOG4CXX_INFO(logger, QString("Message %1").arg(2));
}
catch(std::exception&) {
result = EXIT_FAILURE;
Expand Down
4 changes: 2 additions & 2 deletions src/examples/cpp/auto-configured.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
#include "com/foo/config.h"

extern auto rootLogger = com::foo::getLogger();
auto rootLogger = com::foo::getLogger();

static struct ExampleStaticData {
struct ExampleStaticData {
ExampleStaticData() {
LOG4CXX_DEBUG(rootLogger, "static initializer message");
}
Expand Down
4 changes: 2 additions & 2 deletions src/examples/cpp/com/foo/bar-qt.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "com/foo/config-qt.h"
#include "com/foo/bar.h"
#include "com/foo/config-qt.h"

using namespace com::foo;

LoggerPtr Bar::m_logger(getLogger("com.foo.bar"));

void Bar::doIt() {
LOG4CXX_DEBUG(m_logger, QString("Did it again!"));
LOG4CXX_DEBUG(m_logger, QString("Did it again!") << QString(" - again!"));
}
2 changes: 1 addition & 1 deletion src/examples/cpp/com/foo/config-qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ auto getLogger(const QString& name) -> LoggerPtr {
// Retrieve the \c name logger pointer.
auto getLogger(const char* name) -> LoggerPtr {
return name
? log4cxx::LogManager::getLogger(std::string(name))
? log4cxx::LogManager::getLogger(name)
: log4cxx::LogManager::getRootLogger();
}

Expand Down
9 changes: 4 additions & 5 deletions src/examples/cpp/com/foo/config-qt.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef COM_FOO_CONFIG_H_
#define COM_FOO_CONFIG_H_
#include <QString>
#include <log4cxx/logger.h>
#ifndef COM_FOO_CONFIG_QT_H_
#define COM_FOO_CONFIG_QT_H_
#include <log4cxx-qt/logger.h>

/// Methods specific to foo.com
namespace com { namespace foo {
Expand All @@ -19,4 +18,4 @@ extern auto getLogger(const QString& name) -> LoggerPtr;
extern auto getLogger(const char* name = NULL) -> LoggerPtr;

} } // namespace com::foo
#endif // COM_FOO_CONFIG_H_
#endif // COM_FOO_CONFIG_QT_H_
File renamed without changes.
1 change: 1 addition & 0 deletions src/main/cpp-qt/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/
#include <log4cxx-qt/configuration.h>
#include <log4cxx-qt/transcoder.h>
#include <log4cxx/helpers/loglog.h>
#include <log4cxx/xml/domconfigurator.h>
#include <log4cxx/propertyconfigurator.h>
Expand Down
6 changes: 3 additions & 3 deletions src/main/cpp/domconfigurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ spi::ConfigurationStatus DOMConfigurator::configure(const std::wstring& filename
}
#endif

#if LOG4CXX_UNICHAR_API
#if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR
spi::ConfigurationStatus DOMConfigurator::configure(const std::basic_string<UniChar>& filename)
{
File file(filename);
Expand Down Expand Up @@ -899,7 +899,7 @@ spi::ConfigurationStatus DOMConfigurator::configureAndWatch(const std::wstring&
}
#endif

#if LOG4CXX_UNICHAR_API
#if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR
spi::ConfigurationStatus DOMConfigurator::configureAndWatch(const std::basic_string<UniChar>& filename)
{
return configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
Expand Down Expand Up @@ -954,7 +954,7 @@ spi::ConfigurationStatus DOMConfigurator::configureAndWatch(const std::wstring&
}
#endif

#if LOG4CXX_UNICHAR_API
#if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR
spi::ConfigurationStatus DOMConfigurator::configureAndWatch(const std::basic_string<UniChar>& filename, long delay)
{
return doConfigureAndWatch(xdog, File(filename), delay);
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ File::File(const wchar_t* name1)
}
#endif

#if LOG4CXX_UNICHAR_API
#if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR
File::File(const std::basic_string<UniChar>& name1)
: m_priv(std::make_unique<FilePrivate>(decodeLS(name1)))
{
Expand Down
10 changes: 8 additions & 2 deletions src/main/cpp/hexdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <log4cxx/log4cxx.h>
/* Prevent error C2491: 'std::numpunct<_Elem>::id': definition of dllimport static data member not allowed */
#if defined(_MSC_VER) && (LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR)
#define __FORCE_INSTANCE
#endif
#include <log4cxx/hexdump.h>
#include <log4cxx/log4cxx.h>
#include <sstream>
Expand All @@ -32,8 +38,8 @@ LogString log4cxx::hexdump(const void* bytes, uint32_t len, HexdumpFlags flags){
const wchar_t fill_char = L'0';
const wchar_t space_fill_char = L' ';
#else
const char fill_char = '0';
const char space_fill_char = ' ';
const logchar fill_char = '0';
const logchar space_fill_char = ' ';
#endif

if(flags & HexdumpFlags::AddStartingNewline){
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void Level::toString(std::wstring& dst) const

#endif

#if LOG4CXX_UNICHAR_API
#if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR
LevelPtr Level::toLevel(const std::basic_string<UniChar>& sArg)
{
return toLevel(sArg, Level::getDebug());
Expand Down
4 changes: 2 additions & 2 deletions src/main/cpp/messagebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include <log4cxx/log4cxx.h>
/* Prevent error C2491: 'std::numpunct<_Elem>::id': definition of dllimport static data member not allowed */
#if defined(_MSC_VER) && LOG4CXX_UNICHAR_API
#if defined(_MSC_VER) && (LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR)
#define __FORCE_INSTANCE
#endif
#include <log4cxx/helpers/messagebuffer.h>
Expand Down Expand Up @@ -587,7 +587,7 @@ const std::basic_string<log4cxx::UniChar>& MessageBuffer::str(std::basic_ostream

#endif // LOG4CXX_WCHAR_T_API

#if LOG4CXX_UNICHAR_API
#if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR
struct UniCharMessageBuffer::UniCharMessageBufferPrivate : public StringOrStream<UniChar> {};

UniCharMessageBuffer::UniCharMessageBuffer() :
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/outputstreamwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void OutputStreamWriter::write(const LogString& str, Pool& p)
if (str.length() > 0)
{
#ifdef LOG4CXX_MULTI_PROCESS
// Why does this need to happen for multiproces?? why??
// Ensure the logging event is a single write system call to keep events from each process separate
size_t bufSize = str.length() * 2;
char* rawbuf = new char[bufSize];
ByteBuffer buf(rawbuf, (size_t) bufSize);
Expand Down
4 changes: 4 additions & 0 deletions src/main/cpp/timebasedrollingpolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ const std::string TimeBasedRollingPolicy::createFile(const std::string& fileName

if (stat == APR_SUCCESS)
{
#ifdef WIN32
snprintf(szUid, MAX_FILE_LEN, "%p", uid);
#else
snprintf(szUid, MAX_FILE_LEN, "%u", uid);
#endif
}

log4cxx::filesystem::path path(fileName);
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/transcoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ void Transcoder::encode(unsigned int sv, std::wstring& dst)



#if LOG4CXX_UNICHAR_API
#if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR
void Transcoder::decode(const std::basic_string<UniChar>& src, LogString& dst)
{
#if LOG4CXX_LOGCHAR_IS_UNICHAR
Expand Down
22 changes: 22 additions & 0 deletions src/main/include/log4cxx-qt/logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef _LOG4CXX_QT_LOGGER_H
#define _LOG4CXX_QT_LOGGER_H
#include <log4cxx/logger.h>
#include <log4cxx-qt/messagebuffer.h>
#endif // _LOG4CXX_QT_LOGGER_H
74 changes: 74 additions & 0 deletions src/main/include/log4cxx-qt/messagebuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef _LOG4CXX_QT_MESSAGE_BUFFER_H
#define _LOG4CXX_QT_MESSAGE_BUFFER_H
#include <log4cxx-qt/transcoder.h>

#if LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR
inline log4cxx::helpers::UniCharMessageBuffer&
operator<<(log4cxx::helpers::UniCharMessageBuffer& mb, const QString& msg)
{
return mb << msg.utf16();
}

#if LOG4CXX_WCHAR_T_API
inline log4cxx::helpers::WideMessageBuffer&
operator<<(log4cxx::helpers::WideMessageBuffer& mb, const QString& msg)
{
return mb << msg.toStdWString();
}

inline log4cxx::helpers::WideMessageBuffer&
operator<<(log4cxx::helpers::MessageBuffer& mb, const QString& msg)
{
return mb << msg.toStdWString();
}
#else // !LOG4CXX_WCHAR_T_API
inline log4cxx::helpers::UniCharMessageBuffer&
operator<<(log4cxx::helpers::MessageBuffer& mb, const QString& msg)
{
return mb << msg.utf16();
}
#endif // !LOG4CXX_WCHAR_T_API

#else // !(LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR)

#if LOG4CXX_WCHAR_T_API
inline log4cxx::helpers::WideMessageBuffer&
operator<<(log4cxx::helpers::WideMessageBuffer& mb, const QString& msg)
{
return mb << msg.toStdWString();
}

inline log4cxx::helpers::WideMessageBuffer&
operator<<(log4cxx::helpers::MessageBuffer& mb, const QString& msg)
{
return mb << msg.toStdWString();
}
#else // !LOG4CXX_WCHAR_T_API
inline log4cxx::helpers::CharMessageBuffer&
operator<<(log4cxx::helpers::CharMessageBuffer& mb, const QString& msg)
{
LOG4CXX_DECODE_QSTRING(tmp, msg);
return mb << tmp;
}
#endif // !LOG4CXX_WCHAR_T_API

#endif // !(LOG4CXX_UNICHAR_API || LOG4CXX_LOGCHAR_IS_UNICHAR)

#endif // _LOG4CXX_QT_MESSAGE_BUFFER_H
Loading

0 comments on commit d02e134

Please sign in to comment.