├── .astylerc ├── .gitattributes ├── .github └── workflows │ └── cmake-ubuntu.yml ├── .gitignore ├── CMakeLists.txt ├── ChangeLog.md ├── LICENSE ├── Readme.md ├── appveyor.yml ├── build.pri ├── cmake ├── Log4QtConfig.cmake.in ├── MacroEnsureOutOfSourceBuild.cmake └── cmake_uninstall.cmake.in ├── doc └── Doxyfile.in ├── examples ├── CMakeLists.txt ├── basic │ ├── CMakeLists.txt │ ├── basic.pro │ ├── loggerobject.cpp │ ├── loggerobject.h │ ├── loggerobjectprio.cpp │ ├── loggerobjectprio.h │ ├── loggerstatic.cpp │ ├── loggerstatic.h │ └── main.cpp ├── examples.pri ├── examples.pro └── propertyconfigurator │ ├── CMakeLists.txt │ ├── loggerobject.cpp │ ├── loggerobject.h │ ├── loggerobjectprio.cpp │ ├── loggerobjectprio.h │ ├── loggerstatic.cpp │ ├── loggerstatic.h │ ├── main.cpp │ ├── propertyconfigurator.exe.log4qt.properties │ └── propertyconfigurator.pro ├── g++.pri ├── include └── log4qt │ ├── Appender │ ├── Appenderskeleton │ ├── AsyncAppender │ ├── BasicConfigurator │ ├── BinaryFileAppender │ ├── BinaryLayout │ ├── BinaryLogStream │ ├── BinaryLogger │ ├── BinaryLoggingEvent │ ├── BinaryToTextLayout │ ├── BinaryWriterAppender │ ├── ColorConsoleAppender │ ├── ConsoleAppender │ ├── DailyFileAppender │ ├── DailyRollingFileAppender │ ├── DatabaseAppender │ ├── DatabaseLayout │ ├── FileAppender │ ├── Hierarchy │ ├── Layout │ ├── Level │ ├── Log4Qt │ ├── Log4QtShared │ ├── LogManager │ ├── LogStream │ ├── Logger │ ├── LoggerRepository │ ├── LoggingEvent │ ├── MDC │ ├── MainthreadAppender │ ├── NDC │ ├── PatternLayout │ ├── PropertyConfigurator │ ├── RollingBinaryFileAppender │ ├── RollingFileAppender │ ├── SignalAppender │ ├── SimpleLayout │ ├── SimpleTimeLayout │ ├── SystemlogAppender │ ├── TTCCLayout │ ├── TelnetAppender │ ├── WDCAppender │ └── WriterAppender ├── log4qt.pro ├── src ├── log4qt │ ├── .gitignore │ ├── CMakeLists.txt │ ├── appender.cpp │ ├── appender.h │ ├── appenderskeleton.cpp │ ├── appenderskeleton.h │ ├── asyncappender.cpp │ ├── asyncappender.h │ ├── basicconfigurator.cpp │ ├── basicconfigurator.h │ ├── binaryfileappender.cpp │ ├── binaryfileappender.h │ ├── binarylayout.cpp │ ├── binarylayout.h │ ├── binarylogger.cpp │ ├── binarylogger.h │ ├── binaryloggingevent.cpp │ ├── binaryloggingevent.h │ ├── binarylogstream.cpp │ ├── binarylogstream.h │ ├── binarytotextlayout.cpp │ ├── binarytotextlayout.h │ ├── binarywriterappender.cpp │ ├── binarywriterappender.h │ ├── colorconsoleappender.cpp │ ├── colorconsoleappender.h │ ├── consoleappender.cpp │ ├── consoleappender.h │ ├── dailyfileappender.cpp │ ├── dailyfileappender.h │ ├── dailyrollingfileappender.cpp │ ├── dailyrollingfileappender.h │ ├── databaseappender.cpp │ ├── databaseappender.h │ ├── databaselayout.cpp │ ├── databaselayout.h │ ├── fileappender.cpp │ ├── fileappender.h │ ├── helpers │ │ ├── appenderattachable.cpp │ │ ├── appenderattachable.h │ │ ├── binaryclasslogger.cpp │ │ ├── binaryclasslogger.h │ │ ├── classlogger.cpp │ │ ├── classlogger.h │ │ ├── configuratorhelper.cpp │ │ ├── configuratorhelper.h │ │ ├── datetime.cpp │ │ ├── datetime.h │ │ ├── dispatcher.cpp │ │ ├── dispatcher.h │ │ ├── factory.cpp │ │ ├── factory.h │ │ ├── initialisationhelper.cpp │ │ ├── initialisationhelper.h │ │ ├── logerror.cpp │ │ ├── logerror.h │ │ ├── optionconverter.cpp │ │ ├── optionconverter.h │ │ ├── patternformatter.cpp │ │ ├── patternformatter.h │ │ ├── properties.cpp │ │ └── properties.h │ ├── hierarchy.cpp │ ├── hierarchy.h │ ├── layout.cpp │ ├── layout.h │ ├── level.cpp │ ├── level.h │ ├── log4qt.h │ ├── log4qt.pri │ ├── log4qt.pro │ ├── log4qtdefs.h │ ├── log4qtshared.h │ ├── log4qtsharedptr.h │ ├── logger.cpp │ ├── logger.h │ ├── loggerrepository.cpp │ ├── loggerrepository.h │ ├── loggingevent.cpp │ ├── loggingevent.h │ ├── logmanager.cpp │ ├── logmanager.h │ ├── logstream.cpp │ ├── logstream.h │ ├── mainthreadappender.cpp │ ├── mainthreadappender.h │ ├── mdc.cpp │ ├── mdc.h │ ├── ndc.cpp │ ├── ndc.h │ ├── patternlayout.cpp │ ├── patternlayout.h │ ├── propertyconfigurator.cpp │ ├── propertyconfigurator.h │ ├── qmllogger.cpp │ ├── qmllogger.h │ ├── rollingbinaryfileappender.cpp │ ├── rollingbinaryfileappender.h │ ├── rollingfileappender.cpp │ ├── rollingfileappender.h │ ├── signalappender.cpp │ ├── signalappender.h │ ├── simplelayout.cpp │ ├── simplelayout.h │ ├── simpletimelayout.cpp │ ├── simpletimelayout.h │ ├── spi │ │ ├── filter.cpp │ │ └── filter.h │ ├── systemlogappender.cpp │ ├── systemlogappender.h │ ├── telnetappender.cpp │ ├── telnetappender.h │ ├── ttcclayout.cpp │ ├── ttcclayout.h │ ├── varia │ │ ├── binaryeventfilter.cpp │ │ ├── binaryeventfilter.h │ │ ├── debugappender.cpp │ │ ├── debugappender.h │ │ ├── denyallfilter.cpp │ │ ├── denyallfilter.h │ │ ├── levelmatchfilter.cpp │ │ ├── levelmatchfilter.h │ │ ├── levelrangefilter.cpp │ │ ├── levelrangefilter.h │ │ ├── listappender.cpp │ │ ├── listappender.h │ │ ├── nullappender.cpp │ │ ├── nullappender.h │ │ ├── stringmatchfilter.cpp │ │ └── stringmatchfilter.h │ ├── wdcappender.cpp │ ├── wdcappender.h │ ├── writerappender.cpp │ ├── writerappender.h │ ├── xmllayout.cpp │ └── xmllayout.h └── src.pro └── tests ├── CMakeLists.txt ├── binaryloggertest ├── CMakeLists.txt ├── atscopeexit.h ├── binaryloggertest.cpp ├── binaryloggertest.pro ├── elementsinarray.h ├── logging.cpp ├── logging.h ├── testappender.cpp └── testappender.h ├── dailyfileappendertest ├── CMakeLists.txt ├── dailyfileappendertest.cpp └── dailyfileappendertest.pro ├── filewatcher ├── CMakeLists.txt ├── filewatcher.pro └── tst_filewatchertest.cpp ├── log4qttest ├── CMakeLists.txt ├── log4qttest.cpp ├── log4qttest.h └── log4qttest.pro ├── tests.pri └── tests.pro /.astylerc: -------------------------------------------------------------------------------- 1 | # brace style 2 | --style=allman 3 | --remove-brackets 4 | 5 | # indent style 6 | --indent=spaces=4 7 | 8 | # padding options 9 | --align-pointer=name 10 | --align-reference=name 11 | --pad-header 12 | --pad-oper 13 | 14 | # formating options 15 | --keep-one-line-blocks 16 | --close-templates 17 | --convert-tabs 18 | 19 | 20 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.github/workflows/cmake-ubuntu.yml: -------------------------------------------------------------------------------- 1 | name: CMake Ubuntu build and test 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | workflow_dispatch: 9 | 10 | env: 11 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 12 | BUILD_TYPE: Release 13 | 14 | jobs: 15 | build: 16 | # The CMake configure and build commands are platform agnostic and should work equally 17 | # well on Windows or Mac. You can convert this to a matrix build if you need 18 | # cross-platform coverage. 19 | # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 20 | runs-on: ${{ matrix.os }} 21 | strategy: 22 | matrix: 23 | os: [ubuntu-22.04] 24 | qt_version: [6.2.4, 6.5.3, 6.6.3, 6.7.2, 6.8.1] 25 | 26 | steps: 27 | - name: Install ninja 28 | run: sudo apt-get install ninja-build 29 | 30 | - name: Install Qt 31 | uses: jurplel/install-qt-action@v4 32 | with: 33 | version: ${{matrix.qt_version}} 34 | 35 | - uses: actions/checkout@v4 36 | 37 | - name: Create Build Environment 38 | # Some projects don't allow in-source building, so create a separate build directory 39 | # We'll use this as our working directory for all subsequent commands 40 | run: cmake -E make_directory ${{runner.workspace}}/build 41 | 42 | - name: Configure CMake 43 | # Use a bash shell so we can use the same syntax for environment variable 44 | # access regardless of the host operating system 45 | shell: bash 46 | working-directory: ${{runner.workspace}}/build 47 | # Note the current convention is to use the -S and -B options here to specify source 48 | # and build directories, but this is only available with CMake 3.13 and higher. 49 | # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 50 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -GNinja 51 | 52 | - name: Build 53 | working-directory: ${{runner.workspace}}/build 54 | shell: bash 55 | # Execute the build. You can specify a specific target with "--target " 56 | run: cmake --build . --config ${{env.BUILD_TYPE}} 57 | 58 | - name: Test 59 | working-directory: ${{runner.workspace}}/build 60 | shell: bash 61 | # Execute tests defined by the CMake configuration. 62 | # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail 63 | run: ctest -C ${{env.BUILD_TYPE}} 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | 3 | *.slo 4 | *.lo 5 | *.o 6 | *.a 7 | *.la 8 | *.lai 9 | *.so 10 | *.dll 11 | *.dylib 12 | 13 | # Qt-es 14 | 15 | /.qmake.cache 16 | /.qmake.stash 17 | *.pro.user 18 | *.pro.user.* 19 | *.qbs.user 20 | *.qbs.user.* 21 | CMakeLists.txt.user 22 | *.moc 23 | moc_*.cpp 24 | qrc_*.cpp 25 | ui_*.h 26 | Makefile* 27 | *-build-* 28 | 29 | # QtCreator 30 | 31 | *.autosave 32 | 33 | #QtCtreator Qml 34 | *.qmlproject.user 35 | *.qmlproject.user.* 36 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.6.{build} 2 | build: 3 | verbosity: minimal 4 | 5 | environment: 6 | matrix: 7 | # Qt 5.12 8 | - QTDIR: C:\Qt\5.12\msvc2017_64 9 | CMD_VCVARSALL: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64' 10 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 11 | # Qt 5.15 12 | - QTDIR: C:\Qt\5.15\msvc2019_64 13 | CMD_VCVARSALL: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64' 14 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 15 | # Qt 6.2 16 | - QTDIR: C:\Qt\6.2\msvc2019_64 17 | CMD_VCVARSALL: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64' 18 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 19 | # Qt 6.5 20 | - QTDIR: C:\Qt\6.5\msvc2019_64 21 | CMD_VCVARSALL: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64' 22 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 23 | # Qt 6.6 24 | #- QTDIR: C:\Qt\6.6\msvc2019_64 25 | # CMD_VCVARSALL: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64' 26 | # APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 27 | branches: 28 | only: 29 | - master 30 | install: 31 | - call %CMD_VCVARSALL% 32 | - set PATH=%PATH%;%QTDIR%\bin 33 | build_script: 34 | - qmake 35 | - nmake 36 | - nmake check 37 | 38 | 39 | -------------------------------------------------------------------------------- /build.pri: -------------------------------------------------------------------------------- 1 | # uncomment if you want to build a static log4qt library 2 | #DEFINES += LOG4QT_STATIC 3 | 4 | LOG4QT_VERSION_MAJOR = 1 5 | LOG4QT_VERSION_MINOR = 6 6 | LOG4QT_VERSION_PATCH = 0 7 | 8 | DEFINES += LOG4QT_VERSION_MAJOR=$${LOG4QT_VERSION_MAJOR} 9 | DEFINES += LOG4QT_VERSION_MINOR=$${LOG4QT_VERSION_MINOR} 10 | DEFINES += LOG4QT_VERSION_PATCH=$${LOG4QT_VERSION_PATCH} 11 | DEFINES += LOG4QT_VERSION_STR='\\"$${LOG4QT_VERSION_MAJOR}.$${LOG4QT_VERSION_MINOR}.$${LOG4QT_VERSION_PATCH}\\"' 12 | 13 | DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x050F00 14 | DEFINES += QT_DEPRECATED_WARNINGS 15 | -------------------------------------------------------------------------------- /cmake/Log4QtConfig.cmake.in: -------------------------------------------------------------------------------- 1 | include("${CMAKE_CURRENT_LIST_DIR}/Log4QtTargets.cmake") 2 | -------------------------------------------------------------------------------- /cmake/MacroEnsureOutOfSourceBuild.cmake: -------------------------------------------------------------------------------- 1 | # - MACRO_ENSURE_OUT_OF_SOURCE_BUILD() 2 | # MACRO_ENSURE_OUT_OF_SOURCE_BUILD() 3 | # Call this macro in your project if you want to enforce out-of-source builds. 4 | # If an in-source build is detected, it will abort with the given error message. 5 | # This macro works in any of the CMakeLists.txt of your project, but the recommended 6 | # location to call this is close to the beginning of the top level CMakeLists.txt 7 | 8 | # Copyright (c) 2006, Alexander Neundorf, 9 | # 10 | # Redistribution and use is allowed according to the terms of the BSD license. 11 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 12 | 13 | MACRO (MACRO_ENSURE_OUT_OF_SOURCE_BUILD _errorMessage) 14 | 15 | STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" insource) 16 | IF(insource) 17 | MESSAGE(FATAL_ERROR "${_errorMessage}") 18 | ENDIF(insource) 19 | 20 | ENDMACRO (MACRO_ENSURE_OUT_OF_SOURCE_BUILD) 21 | 22 | -------------------------------------------------------------------------------- /cmake/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 2 | message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") 3 | endif() 4 | 5 | file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 6 | string(REGEX REPLACE "\n" ";" files "${files}") 7 | foreach(file ${files}) 8 | set(_file_to_remove "$ENV{DESTDIR}${file}") 9 | message(STATUS "Uninstalling \"${_file_to_remove}\"") 10 | if(EXISTS "${_file_to_remove}") 11 | execute_process(COMMAND ${CMAKE_COMMAND} -E remove ${_file_to_remove} 12 | OUTPUT_VARIABLE rm_out 13 | RESULT_VARIABLE rm_retval) 14 | if(NOT ${rm_retval} EQUAL 0) 15 | message(FATAL_ERROR "Problem when removing \"${_file_to_remove}\": ${rm_out}") 16 | endif() 17 | else() 18 | message(STATUS "File \"${_file_to_remove}\" does not exist.") 19 | endif() 20 | endforeach() 21 | -------------------------------------------------------------------------------- /doc/Doxyfile.in: -------------------------------------------------------------------------------- 1 | RECURSIVE = YES 2 | OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@/doc_doxygen/ 3 | INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src/ @CMAKE_CURRENT_SOURCE_DIR@/include/ @CMAKE_CURRENT_SOURCE_DIR@/docs 4 | WARN_IF_UNDOCUMENTED = NO 5 | GENERATE_LATEX = NO 6 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(basic) 2 | add_subdirectory(propertyconfigurator) 3 | -------------------------------------------------------------------------------- /examples/basic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(basic_SOURCES 2 | loggerobject.cpp 3 | loggerobject.h 4 | loggerobjectprio.cpp 5 | loggerobjectprio.h 6 | loggerstatic.cpp 7 | loggerstatic.h 8 | main.cpp 9 | ) 10 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 11 | add_executable(basic ${basic_SOURCES}) 12 | target_link_libraries(basic log4qt) 13 | -------------------------------------------------------------------------------- /examples/basic/basic.pro: -------------------------------------------------------------------------------- 1 | include(../examples.pri) 2 | include(../../build.pri) 3 | 4 | QT += core network 5 | QT -= gui 6 | 7 | TEMPLATE = app 8 | DESTDIR = ../../bin 9 | 10 | LIBS += -L../../bin \ 11 | -llog4qt 12 | 13 | SOURCES += \ 14 | main.cpp \ 15 | loggerobject.cpp \ 16 | loggerobjectprio.cpp \ 17 | loggerstatic.cpp 18 | 19 | HEADERS += \ 20 | loggerobject.h \ 21 | loggerobjectprio.h \ 22 | loggerstatic.h 23 | 24 | INCLUDEPATH += ../../src 25 | 26 | -------------------------------------------------------------------------------- /examples/basic/loggerobject.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "loggerobject.h" 22 | 23 | #include 24 | #include 25 | 26 | Q_LOGGING_CATEGORY(category1, "test.category1") 27 | 28 | LoggerObject::LoggerObject(QObject *parent) : QObject(parent), 29 | mCounter(0) 30 | { 31 | auto *timer = new QTimer(this); 32 | connect(timer, &QTimer::timeout, this, &LoggerObject::onTimeout); 33 | timer->start(10); 34 | } 35 | 36 | void LoggerObject::onTimeout() 37 | { 38 | logger()->debug() << "Debug output"; 39 | logger()->error() << "Error output"; 40 | logger()->debug(QStringLiteral("test")); 41 | 42 | qCCritical(category1, "a debug message"); 43 | 44 | l4qError(QStringLiteral("an error")); 45 | l4qDebug(QStringLiteral("debug info")); 46 | 47 | l4qError() << "an error via stream"; 48 | l4qError(QStringLiteral("an error with param %1"), 10); 49 | mCounter++; 50 | if (mCounter >= 10) 51 | Q_EMIT exit(0); 52 | } 53 | 54 | #include "moc_loggerobject.cpp" 55 | -------------------------------------------------------------------------------- /examples/basic/loggerobject.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOGGEROBJECT_H 22 | #define LOGGEROBJECT_H 23 | 24 | #include "log4qt/logger.h" 25 | 26 | #include 27 | #include 28 | 29 | class LoggerObject : public QObject 30 | { 31 | Q_OBJECT 32 | LOG4QT_DECLARE_QCLASS_LOGGER 33 | public: 34 | explicit LoggerObject(QObject *parent = nullptr); 35 | 36 | Q_SIGNALS: 37 | void exit(int code); 38 | 39 | private Q_SLOTS: 40 | void onTimeout(); 41 | 42 | private: 43 | Q_DISABLE_COPY_MOVE(LoggerObject) 44 | int mCounter; 45 | }; 46 | 47 | #endif // LOGGEROBJECT_H 48 | -------------------------------------------------------------------------------- /examples/basic/loggerobjectprio.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "loggerobjectprio.h" 22 | 23 | #include 24 | 25 | LoggerObjectPrio::LoggerObjectPrio(QObject *parent) : QObject(parent) 26 | { 27 | auto *timer = new QTimer(this); 28 | connect(timer, &QTimer::timeout, this, &LoggerObjectPrio::onTimeout); 29 | timer->start(1); 30 | } 31 | 32 | void LoggerObjectPrio::onTimeout() 33 | { 34 | logger()->debug() << "Debug output"; 35 | logger()->error() << "Error output"; 36 | } 37 | 38 | #include "moc_loggerobjectprio.cpp" 39 | 40 | -------------------------------------------------------------------------------- /examples/basic/loggerobjectprio.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOGGEROBJECTPRIO_H 22 | #define LOGGEROBJECTPRIO_H 23 | 24 | #include "log4qt/logger.h" 25 | 26 | #include 27 | 28 | class LoggerObjectPrio : public QObject 29 | { 30 | Q_OBJECT 31 | LOG4QT_DECLARE_QCLASS_LOGGER 32 | public: 33 | explicit LoggerObjectPrio(QObject *parent = nullptr); 34 | 35 | private Q_SLOTS: 36 | void onTimeout(); 37 | 38 | }; 39 | 40 | #endif // LOGGEROBJECTPRIO_H 41 | -------------------------------------------------------------------------------- /examples/basic/loggerstatic.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "loggerstatic.h" 22 | 23 | #include "log4qt/logger.h" 24 | #include "log4qt/logmanager.h" 25 | 26 | LOG4QT_DECLARE_STATIC_LOGGER(logger, LoggerStatic) 27 | 28 | LoggerStatic::LoggerStatic() 29 | { 30 | logger()->trace() << "ctor Debug output"; 31 | logger()->info() << "Log4Qt Version String: " << Log4Qt::LogManager::version(); 32 | logger()->info() << "Log4Qt Version Number: " << Log4Qt::LogManager::versionNumber().toString(); 33 | } 34 | 35 | LoggerStatic::~LoggerStatic() 36 | { 37 | logger()->trace() << "dtor Debug output"; 38 | } 39 | -------------------------------------------------------------------------------- /examples/basic/loggerstatic.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOGGERSTATIC_H 22 | #define LOGGERSTATIC_H 23 | 24 | 25 | class LoggerStatic 26 | { 27 | public: 28 | LoggerStatic(); 29 | ~LoggerStatic(); 30 | 31 | LoggerStatic(const LoggerStatic &) = delete; 32 | LoggerStatic &operator=(const LoggerStatic &) = delete; 33 | }; 34 | 35 | #endif // LOGGERSTATIC_H 36 | -------------------------------------------------------------------------------- /examples/examples.pri: -------------------------------------------------------------------------------- 1 | include (../g++.pri) 2 | include (../build.pri) 3 | 4 | CONFIG += c++14 5 | 6 | msvc { 7 | QMAKE_CXXFLAGS += -wd4267 8 | } 9 | -------------------------------------------------------------------------------- /examples/examples.pro: -------------------------------------------------------------------------------- 1 | include(../build.pri) 2 | TEMPLATE = subdirs 3 | 4 | SUBDIRS += basic \ 5 | propertyconfigurator 6 | -------------------------------------------------------------------------------- /examples/propertyconfigurator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(basic_SOURCES 2 | loggerobject.cpp 3 | loggerobject.h 4 | loggerobjectprio.cpp 5 | loggerobjectprio.h 6 | loggerstatic.cpp 7 | loggerstatic.h 8 | main.cpp 9 | ) 10 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 11 | add_executable(propertyconfigurator ${basic_SOURCES}) 12 | target_link_libraries(propertyconfigurator log4qt) 13 | -------------------------------------------------------------------------------- /examples/propertyconfigurator/loggerobject.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "loggerobject.h" 22 | 23 | #include 24 | 25 | LoggerObject::LoggerObject(QObject *parent) : QObject(parent), 26 | mCounter(0) 27 | { 28 | auto *timer = new QTimer(this); 29 | connect(timer, &QTimer::timeout, this, &LoggerObject::onTimeout); 30 | timer->start(10); 31 | } 32 | 33 | void LoggerObject::onTimeout() 34 | { 35 | logger()->debug() << "Debug output"; 36 | logger()->error() << "Error output"; 37 | 38 | mCounter++; 39 | if (mCounter >= 10) 40 | Q_EMIT exit(0); 41 | } 42 | 43 | #include "moc_loggerobject.cpp" 44 | -------------------------------------------------------------------------------- /examples/propertyconfigurator/loggerobject.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOGGEROBJECT_H 22 | #define LOGGEROBJECT_H 23 | 24 | #include "log4qt/logger.h" 25 | 26 | #include 27 | 28 | class LoggerObject : public QObject 29 | { 30 | Q_OBJECT 31 | LOG4QT_DECLARE_QCLASS_LOGGER 32 | public: 33 | explicit LoggerObject(QObject *parent = nullptr); 34 | 35 | Q_SIGNALS: 36 | void exit(int code); 37 | 38 | private Q_SLOTS: 39 | void onTimeout(); 40 | 41 | private: 42 | int mCounter; 43 | }; 44 | 45 | #endif // LOGGEROBJECT_H 46 | -------------------------------------------------------------------------------- /examples/propertyconfigurator/loggerobjectprio.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "loggerobjectprio.h" 22 | 23 | #include 24 | 25 | LoggerObjectPrio::LoggerObjectPrio(QObject *parent) : QObject(parent) 26 | { 27 | auto *timer = new QTimer(this); 28 | connect(timer, &QTimer::timeout, this, &LoggerObjectPrio::onTimeout); 29 | timer->start(1); 30 | } 31 | 32 | void LoggerObjectPrio::onTimeout() 33 | { 34 | logger()->debug() << "Debug output"; 35 | logger()->error() << "Error output"; 36 | } 37 | 38 | #include "moc_loggerobjectprio.cpp" 39 | -------------------------------------------------------------------------------- /examples/propertyconfigurator/loggerobjectprio.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOGGEROBJECTPRIO_H 22 | #define LOGGEROBJECTPRIO_H 23 | 24 | #include "log4qt/logger.h" 25 | 26 | #include 27 | 28 | class LoggerObjectPrio : public QObject 29 | { 30 | Q_OBJECT 31 | LOG4QT_DECLARE_QCLASS_LOGGER 32 | public: 33 | explicit LoggerObjectPrio(QObject *parent = nullptr); 34 | 35 | private Q_SLOTS: 36 | void onTimeout(); 37 | 38 | }; 39 | 40 | #endif // LOGGEROBJECTPRIO_H 41 | -------------------------------------------------------------------------------- /examples/propertyconfigurator/loggerstatic.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "loggerstatic.h" 22 | 23 | #include "log4qt/logger.h" 24 | 25 | LOG4QT_DECLARE_STATIC_LOGGER(logger, LoggerStatic) 26 | 27 | LoggerStatic::LoggerStatic() 28 | { 29 | logger()->trace() << "ctor Debug output"; 30 | } 31 | 32 | LoggerStatic::~LoggerStatic() 33 | { 34 | logger()->trace() << "dtor Debug output"; 35 | } 36 | -------------------------------------------------------------------------------- /examples/propertyconfigurator/loggerstatic.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOGGERSTATIC_H 22 | #define LOGGERSTATIC_H 23 | 24 | 25 | class LoggerStatic 26 | { 27 | public: 28 | LoggerStatic(); 29 | ~LoggerStatic(); 30 | 31 | LoggerStatic(const LoggerStatic &) = delete; 32 | LoggerStatic &operator=(const LoggerStatic &) = delete; 33 | }; 34 | 35 | #endif // LOGGERSTATIC_H 36 | -------------------------------------------------------------------------------- /examples/propertyconfigurator/propertyconfigurator.exe.log4qt.properties: -------------------------------------------------------------------------------- 1 | logpath=. 2 | 3 | log4j.reset=true 4 | log4j.Debug=WARN 5 | log4j.threshold=NULL 6 | log4j.handleQtMessages=true 7 | log4j.watchThisFile=false 8 | 9 | log4j.rootLogger=ALL, console, daily 10 | 11 | log4j.appender.console=org.apache.log4j.ConsoleAppender 12 | log4j.appender.console.target=STDOUT_TARGET 13 | log4j.appender.console.layout=org.apache.log4j.TTCCLayout 14 | log4j.appender.console.layout.dateFormat=dd.MM.yyyy hh:mm:ss.zzz 15 | log4j.appender.console.layout.contextPrinting=true 16 | log4j.appender.console.threshold=ALL 17 | 18 | log4j.appender.daily=org.apache.log4j.DailyFileAppender 19 | log4j.appender.daily.file=${logpath}/propertyconfigurator.log 20 | log4j.appender.daily.appendFile=true 21 | log4j.appender.daily.datePattern=_yyyy_MM_dd 22 | log4j.appender.daily.keepDays=90 23 | log4j.appender.daily.layout=${log4j.appender.console.layout} 24 | log4j.appender.daily.layout.dateFormat=${log4j.appender.console.layout.dateFormat} 25 | log4j.appender.daily.layout.contextPrinting=${log4j.appender.console.layout.contextPrinting} 26 | 27 | log4j.logger.LoggerObjectPrio=ERROR, daily, console 28 | log4j.additivity.LoggerObjectPrio=false 29 | -------------------------------------------------------------------------------- /examples/propertyconfigurator/propertyconfigurator.pro: -------------------------------------------------------------------------------- 1 | include(../examples.pri) 2 | include(../../build.pri) 3 | 4 | QT += core network 5 | QT -= gui 6 | 7 | TEMPLATE = app 8 | DESTDIR = ../../bin 9 | 10 | LIBS += -L../../bin \ 11 | -llog4qt 12 | 13 | SOURCES += \ 14 | main.cpp \ 15 | loggerobject.cpp \ 16 | loggerobjectprio.cpp \ 17 | loggerstatic.cpp 18 | 19 | HEADERS += \ 20 | loggerobject.h \ 21 | loggerobjectprio.h \ 22 | loggerstatic.h 23 | 24 | INCLUDEPATH += ../../src 25 | 26 | DISTFILES += \ 27 | propertyconfigurator.exe.log4qt.properties 28 | 29 | 30 | -------------------------------------------------------------------------------- /g++.pri: -------------------------------------------------------------------------------- 1 | *-g++* { 2 | NORMAL_CFLAGS = -Wno-long-long -ansi 3 | NORMAL_CXXFLAGS = \ 4 | -Wnon-virtual-dtor -Wundef -Wcast-align \ 5 | -Wchar-subscripts -Wpointer-arith \ 6 | -Wwrite-strings -Wpacked -Wformat-security \ 7 | -Wmissing-format-attribute -Woverloaded-virtual \ 8 | # -Wzero-as-null-pointer-constant 9 | 10 | 11 | # NORMAL_CXXFLAGS += -Wconversion 12 | 13 | NORMAL_CFLAGS += -pedantic 14 | 15 | USABLE_CXXFLAGS = -Wold-style-cast 16 | HARD_CXXFLAGS = -Weffc++ -Wshadow 17 | PITA_CXXFLAGS = -Wunreachable-code 18 | 19 | QMAKE_CFLAGS += $$NORMAL_CFLAGS 20 | QMAKE_CXXFLAGS += $$NORMAL_CFLAGS $$NORMAL_CXXFLAGS 21 | 22 | # Not needed - warn_on.prf adds QMAKE_CXXFLAGS_WARN_ON to QMAKE_CXXFLAGS 23 | #QMAKE_CFLAGS_WARN_ON += $$NORMAL_CFLAGS 24 | #QMAKE_CXXFLAGS_WARN_ON += $$NORMAL_CFLAGS $$NORMAL_CXXFLAGS 25 | 26 | QMAKE_CXXFLAGS_WARN_ON += $$USABLE_CXXFLAGS 27 | #QMAKE_CXXFLAGS_WARN_ON += $$HARD_CXXFLAGS # headers must compile with this, code doesn't need to; needs patched Qt 28 | #QMAKE_CXXFLAGS_WARN_ON += $$PITA_CXXFLAGS # header would be nice, but it's probably pointless, due to noise from Qt and libstdc++ 29 | 30 | } 31 | 32 | msvc { 33 | QMAKE_CFLAGS_WARN_ON -= -W3 34 | QMAKE_CFLAGS_WARN_ON += -W4 35 | 36 | QMAKE_CXXFLAGS_WARN_ON -= -W3 37 | QMAKE_CXXFLAGS_WARN_ON += -W4 38 | 39 | # disable common warnings in Qt/stdlib 40 | # disable 4127: conditional expression is constant 41 | # 4512: assignment operator could not be generated 42 | # 4267: conversion from 'size_t' to 'type', possible loss of data 43 | QMAKE_CXXFLAGS += -wd4127 -wd4512 -wd4267 -we4265 -wd4913 44 | 45 | # /WX ... treat all warnings as errors 46 | # /we ... Treat warning as error 47 | 48 | } 49 | -------------------------------------------------------------------------------- /include/log4qt/Appender: -------------------------------------------------------------------------------- 1 | #include "appender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/Appenderskeleton: -------------------------------------------------------------------------------- 1 | #include "appenderskeleton.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/AsyncAppender: -------------------------------------------------------------------------------- 1 | #include "asyncappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/BasicConfigurator: -------------------------------------------------------------------------------- 1 | #include "basicconfigurator.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/BinaryFileAppender: -------------------------------------------------------------------------------- 1 | #include "binaryfileappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/BinaryLayout: -------------------------------------------------------------------------------- 1 | #include "binarylayout.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/BinaryLogStream: -------------------------------------------------------------------------------- 1 | #include "binarylogstream.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/BinaryLogger: -------------------------------------------------------------------------------- 1 | #include "binarylogger.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/BinaryLoggingEvent: -------------------------------------------------------------------------------- 1 | #include "binaryloggingevent.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/BinaryToTextLayout: -------------------------------------------------------------------------------- 1 | #include "binarytotextlayout.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/BinaryWriterAppender: -------------------------------------------------------------------------------- 1 | #include "binarywriterappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/ColorConsoleAppender: -------------------------------------------------------------------------------- 1 | #include "colorconsoleappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/ConsoleAppender: -------------------------------------------------------------------------------- 1 | #include "consoleappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/DailyFileAppender: -------------------------------------------------------------------------------- 1 | #include "dailyfileappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/DailyRollingFileAppender: -------------------------------------------------------------------------------- 1 | #include "dailyrollingfileappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/DatabaseAppender: -------------------------------------------------------------------------------- 1 | #include "databaseappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/DatabaseLayout: -------------------------------------------------------------------------------- 1 | #include "databaselayout.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/FileAppender: -------------------------------------------------------------------------------- 1 | #include "fileappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/Hierarchy: -------------------------------------------------------------------------------- 1 | #include "hierarchy.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/Layout: -------------------------------------------------------------------------------- 1 | #include "layout.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/Level: -------------------------------------------------------------------------------- 1 | #include "level.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/Log4Qt: -------------------------------------------------------------------------------- 1 | #include "log4qt.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/Log4QtShared: -------------------------------------------------------------------------------- 1 | #include "log4qtshared.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/LogManager: -------------------------------------------------------------------------------- 1 | #include "logmanager.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/LogStream: -------------------------------------------------------------------------------- 1 | #include "logstream.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/Logger: -------------------------------------------------------------------------------- 1 | #include "logger.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/LoggerRepository: -------------------------------------------------------------------------------- 1 | #include "loggerrepository.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/LoggingEvent: -------------------------------------------------------------------------------- 1 | #include "loggingevent.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/MDC: -------------------------------------------------------------------------------- 1 | #include "mdc.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/MainthreadAppender: -------------------------------------------------------------------------------- 1 | #include "mainthreadappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/NDC: -------------------------------------------------------------------------------- 1 | #include "ndc.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/PatternLayout: -------------------------------------------------------------------------------- 1 | #include "patternlayout.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/PropertyConfigurator: -------------------------------------------------------------------------------- 1 | #include "propertyconfigurator.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/RollingBinaryFileAppender: -------------------------------------------------------------------------------- 1 | #include "rollingbinaryfileappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/RollingFileAppender: -------------------------------------------------------------------------------- 1 | #include "rollingfileappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/SignalAppender: -------------------------------------------------------------------------------- 1 | #include "signalappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/SimpleLayout: -------------------------------------------------------------------------------- 1 | #include "simplelayout.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/SimpleTimeLayout: -------------------------------------------------------------------------------- 1 | #include "simpletimelayout.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/SystemlogAppender: -------------------------------------------------------------------------------- 1 | #include "systemlogappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/TTCCLayout: -------------------------------------------------------------------------------- 1 | #include "ttcclayout.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/TelnetAppender: -------------------------------------------------------------------------------- 1 | #include "telnetappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/WDCAppender: -------------------------------------------------------------------------------- 1 | #include "wdcappender.h" 2 | -------------------------------------------------------------------------------- /include/log4qt/WriterAppender: -------------------------------------------------------------------------------- 1 | #include "writerappender.h" 2 | -------------------------------------------------------------------------------- /log4qt.pro: -------------------------------------------------------------------------------- 1 | #CONFIG += build_with_db_logging \ 2 | # build_with_telnet_logging \ 3 | # build_with_qml_logging 4 | 5 | TEMPLATE = subdirs 6 | SUBDIRS += src \ 7 | tests \ 8 | examples 9 | 10 | tests.depends = src 11 | examples.depends = src 12 | 13 | OTHER_FILES += LICENSE \ 14 | Readme.md \ 15 | .travis.yml \ 16 | appveyor.yml \ 17 | ChangeLog.md 18 | -------------------------------------------------------------------------------- /src/log4qt/.gitignore: -------------------------------------------------------------------------------- 1 | /.qmlls.ini 2 | -------------------------------------------------------------------------------- /src/log4qt/appender.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "appender.h" 22 | 23 | namespace Log4Qt 24 | { 25 | 26 | Appender::Appender(QObject *parent) : 27 | QObject(parent) 28 | { 29 | } 30 | 31 | Appender::~Appender() = default; 32 | 33 | Logger *Appender::logger() const 34 | { 35 | return mLog4QtClassLogger.logger(this); 36 | } 37 | 38 | } // namespace Log4Qt 39 | 40 | #include "moc_appender.cpp" 41 | -------------------------------------------------------------------------------- /src/log4qt/appender.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_APPENDER_H 22 | #define LOG4QT_APPENDER_H 23 | 24 | #include "layout.h" 25 | #include "log4qtdefs.h" 26 | #include "log4qtsharedptr.h" 27 | #include "spi/filter.h" 28 | #include "helpers/classlogger.h" 29 | 30 | namespace Log4Qt 31 | { 32 | 33 | class LoggingEvent; 34 | 35 | /*! 36 | * \brief The class Appender is the base class for all Appenders. 37 | * 38 | * To allow the whole hirarchy to be an ascendant of QObject Appender is 39 | * not an interface. 40 | * 41 | * \note All the functions declared in this class are thread-safe. 42 | * 43 | * \note The ownership and lifetime of objects of this class are managed. 44 | * See \ref Ownership "Object ownership" for more details. 45 | */ 46 | class LOG4QT_EXPORT Appender : public QObject 47 | { 48 | Q_OBJECT 49 | 50 | /*! 51 | * The property holds the Layout used by the Appender. 52 | * 53 | * \sa layout(), setLayout() 54 | */ 55 | Q_PROPERTY(LayoutSharedPtr layout READ layout WRITE setLayout) 56 | 57 | /*! 58 | * The property holds the name of the Appender. 59 | * 60 | * \sa name(), setName() 61 | */ 62 | Q_PROPERTY(QString name READ name WRITE setName) 63 | 64 | /*! 65 | * The property holds if the Appender requires a Layout or not. 66 | * 67 | * \sa requiresLayout(), setRequiresLayout() 68 | */ 69 | Q_PROPERTY(bool requiresLayout READ requiresLayout) 70 | 71 | public: 72 | Appender(QObject *parent = nullptr); 73 | virtual ~Appender(); 74 | 75 | virtual FilterSharedPtr filter() const = 0; 76 | virtual QString name() const = 0; 77 | virtual LayoutSharedPtr layout() const = 0; 78 | virtual bool requiresLayout() const = 0; 79 | virtual void setLayout(const LayoutSharedPtr &layout) = 0; 80 | virtual void setName(const QString &name) = 0; 81 | 82 | virtual void addFilter(const FilterSharedPtr &filter) = 0; 83 | virtual void clearFilters() = 0; 84 | virtual void close() = 0; 85 | virtual void doAppend(const LoggingEvent &event) = 0; 86 | 87 | protected: 88 | /*! 89 | * Returns a pointer to a Logger named after of the object. 90 | * 91 | * \sa Logger::logger() 92 | */ 93 | Logger *logger() const; 94 | 95 | private: 96 | Q_DISABLE_COPY_MOVE(Appender) 97 | mutable ClassLogger mLog4QtClassLogger; 98 | }; 99 | 100 | using AppenderSharedPtr = Log4QtSharedPtr; 101 | 102 | } // namespace Log4Qt 103 | 104 | #endif // LOG4QT_APPENDER_H 105 | -------------------------------------------------------------------------------- /src/log4qt/asyncappender.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "asyncappender.h" 22 | #include "loggingevent.h" 23 | #include "helpers/dispatcher.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #if (__cplusplus >= 201703L) // C++17 or later 30 | #include 31 | #endif 32 | 33 | namespace Log4Qt 34 | { 35 | 36 | AsyncAppender::AsyncAppender(QObject *parent) : AppenderSkeleton(parent) 37 | , mThread(nullptr) 38 | , mDispatcher(nullptr) 39 | { 40 | } 41 | 42 | AsyncAppender::~AsyncAppender() 43 | { 44 | closeInternal(); 45 | } 46 | 47 | bool AsyncAppender::requiresLayout() const 48 | { 49 | return false; 50 | } 51 | 52 | void AsyncAppender::activateOptions() 53 | { 54 | if (mThread != nullptr) 55 | return; 56 | 57 | mThread = new QThread(); 58 | mDispatcher = new Dispatcher(); 59 | mDispatcher->setAsyncAppender(this); 60 | 61 | mDispatcher->moveToThread(mThread); 62 | mThread->start(); 63 | } 64 | 65 | void AsyncAppender::close() 66 | { 67 | closeInternal(); 68 | AppenderSkeleton::close(); 69 | } 70 | 71 | void AsyncAppender::closeInternal() 72 | { 73 | QMutexLocker locker(&mObjectGuard); 74 | 75 | if (isClosed()) 76 | return; 77 | 78 | if (mThread != nullptr) 79 | { 80 | mDispatcher->setAsyncAppender(nullptr); 81 | mThread->quit(); 82 | mThread->wait(); 83 | delete mThread; 84 | mThread = nullptr; 85 | delete mDispatcher; 86 | mDispatcher = nullptr; 87 | } 88 | } 89 | 90 | void AsyncAppender::callAppenders(const LoggingEvent &event) const 91 | { 92 | Q_UNUSED(event) 93 | QReadLocker locker(&mAppenderGuard); 94 | 95 | #if (__cplusplus >= 201703L) 96 | for (auto &&pAppender : std::as_const(mAppenders)) 97 | #else 98 | for (auto &&pAppender : qAsConst(mAppenders)) 99 | #endif 100 | pAppender->doAppend(event); 101 | } 102 | 103 | void AsyncAppender::append(const LoggingEvent &event) 104 | { 105 | // Post to the event loop of the dispatcher 106 | qApp->postEvent(mDispatcher, new LoggingEvent(event)); 107 | } 108 | 109 | bool AsyncAppender::checkEntryConditions() const 110 | { 111 | if ((mThread != nullptr) && !mThread->isRunning()) 112 | { 113 | LogError e = 114 | LOG4QT_QCLASS_ERROR(QT_TR_NOOP("Use of appender '%1' without a running dispatcher thread"), 115 | APPENDER_ASNC_DISPATCHER_NOT_RUNNING); 116 | e << name(); 117 | logger()->error(e); 118 | return false; 119 | } 120 | 121 | return AppenderSkeleton::checkEntryConditions(); 122 | } 123 | 124 | } // namespace Log4Qt 125 | 126 | #include "moc_asyncappender.cpp" 127 | -------------------------------------------------------------------------------- /src/log4qt/asyncappender.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_ASYNCAPPENDER_H 22 | #define LOG4QT_ASYNCAPPENDER_H 23 | 24 | #include "appenderskeleton.h" 25 | #include "helpers/appenderattachable.h" 26 | 27 | namespace Log4Qt 28 | { 29 | 30 | class Dispatcher; 31 | 32 | /*! 33 | * \brief The class AsyncAppender lets users log events asynchronously. 34 | * 35 | * The AsyncAppender will collect the events sent to it and then dispatch them to all the 36 | * appenders that are attached to it. You can attach multiple appenders to an AsyncAppender. 37 | * 38 | * The AsyncAppender uses a separate thread to serve the events fromthe event loop. 39 | * 40 | * \note All the functions declared in this class are thread-safe. 41 | *   42 | * \note The ownership and lifetime of objects of this class are managed. 43 | * See \ref Ownership "Object ownership" for more details. 44 | */ 45 | class LOG4QT_EXPORT AsyncAppender : public AppenderSkeleton, public AppenderAttachable 46 | { 47 | Q_OBJECT 48 | 49 | public: 50 | AsyncAppender(QObject *parent = nullptr); 51 | ~AsyncAppender() override; 52 | 53 | bool requiresLayout() const override; 54 | 55 | void activateOptions() override; 56 | void close() override; 57 | void callAppenders(const LoggingEvent &event) const; 58 | 59 | /*! 60 | * Tests if all entry conditions for using append() in this class are 61 | * met. 62 | * 63 | * If a conditions is not met, an error is logged and the function 64 | * returns false. Otherwise the result of 65 | * AppenderSkeleton::checkEntryConditions() is returned. 66 | * 67 | * The checked conditions are: 68 | * - dispatcher thread running (APPENDER_ASNC_DISPATCHER_NOT_RUNNING) 69 | * 70 | * The function is called as part of the checkEntryConditions() chain 71 | * started by AppenderSkeleton::doAppend(). 72 | * 73 | * \sa AppenderSkeleton::doAppend(), 74 | * AppenderSkeleton::checkEntryConditions() 75 | */ 76 | bool checkEntryConditions() const override; 77 | 78 | protected: 79 | void append(const LoggingEvent &event) override; 80 | 81 | private: 82 | Q_DISABLE_COPY_MOVE(AsyncAppender) 83 | 84 | //! Event dispatcher trhead 85 | QThread *mThread; 86 | Dispatcher *mDispatcher; 87 | void closeInternal(); 88 | }; 89 | 90 | 91 | } // namespace Log4Qt 92 | 93 | #endif // LOG4QT_AsyncAppender_H 94 | -------------------------------------------------------------------------------- /src/log4qt/basicconfigurator.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "basicconfigurator.h" 22 | 23 | #include "consoleappender.h" 24 | #include "helpers/configuratorhelper.h" 25 | #include "logmanager.h" 26 | #include "patternlayout.h" 27 | #include "varia/listappender.h" 28 | 29 | #include 30 | #include 31 | 32 | namespace Log4Qt 33 | { 34 | 35 | bool BasicConfigurator::configure() 36 | { 37 | auto *list = new ListAppender; 38 | list->setName(QStringLiteral("BasicConfigurator")); 39 | list->setConfiguratorList(true); 40 | list->setThreshold(Level::ERROR_INT); 41 | LogManager::logLogger()->addAppender(AppenderSharedPtr(list)); 42 | 43 | LayoutSharedPtr p_layout(new PatternLayout(PatternLayout::TTCC_CONVERSION_PATTERN)); 44 | p_layout->setName(QStringLiteral("BasicConfigurator TTCC")); 45 | p_layout->activateOptions(); 46 | ConsoleAppender *p_appender = new ConsoleAppender(p_layout, ConsoleAppender::STDOUT_TARGET); 47 | p_appender->setName(QStringLiteral("BasicConfigurator stdout")); 48 | p_appender->activateOptions(); 49 | LogManager::rootLogger()->addAppender(p_appender); 50 | 51 | LogManager::logLogger()->removeAppender(list); 52 | ConfiguratorHelper::setConfigureError(list->list()); 53 | return (list->list().count() == 0); 54 | } 55 | 56 | void BasicConfigurator::configure(Appender *pAppender) 57 | { 58 | LogManager::rootLogger()->addAppender(pAppender); 59 | } 60 | 61 | void BasicConfigurator::resetConfiguration() 62 | { 63 | LogManager::resetConfiguration(); 64 | } 65 | 66 | } // namespace Log4Qt 67 | -------------------------------------------------------------------------------- /src/log4qt/basicconfigurator.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_BASICCONFIGURATOR_H 22 | #define LOG4QT_BASICCONFIGURATOR_H 23 | 24 | #include "log4qtdefs.h" 25 | #include "log4qt.h" 26 | 27 | namespace Log4Qt 28 | { 29 | 30 | class Appender; 31 | 32 | /*! 33 | * \brief The class BasicConfigurator provides a simple package 34 | * configuration. 35 | * 36 | * \note All the functions declared in this class are thread-safe. 37 | */ 38 | class LOG4QT_EXPORT BasicConfigurator 39 | { 40 | private: 41 | Q_DISABLE_COPY_MOVE(BasicConfigurator) 42 | 43 | public: 44 | static bool configure(); 45 | static void configure(Appender *pAppender); 46 | static void resetConfiguration(); 47 | }; 48 | 49 | 50 | } // namspace 51 | 52 | #endif // _BASICCONFIGURATOR_H 53 | -------------------------------------------------------------------------------- /src/log4qt/binarylayout.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "binarylayout.h" 22 | #include "binaryloggingevent.h" 23 | 24 | namespace Log4Qt 25 | { 26 | 27 | BinaryLayout::BinaryLayout(QObject *parent) 28 | : Layout(parent) 29 | { 30 | } 31 | 32 | QByteArray BinaryLayout::binaryFormat(const BinaryLoggingEvent &event) const 33 | { 34 | return event.binaryMessage(); 35 | } 36 | 37 | QString BinaryLayout::format(const LoggingEvent &event) 38 | { 39 | Q_UNUSED(event) 40 | return QString{}; 41 | } 42 | 43 | QString BinaryLayout::contentType() const 44 | { 45 | return QStringLiteral("application/octet-stream"); 46 | } 47 | 48 | } // namespace Log4Qt 49 | 50 | #include "moc_binarylayout.cpp" 51 | 52 | -------------------------------------------------------------------------------- /src/log4qt/binarylayout.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_BINARYLAYOUT_H 22 | #define LOG4QT_BINARYLAYOUT_H 23 | 24 | #include "layout.h" 25 | 26 | #include 27 | 28 | namespace Log4Qt 29 | { 30 | 31 | class LoggingEvent; 32 | class BinaryLoggingEvent; 33 | 34 | class LOG4QT_EXPORT BinaryLayout : public Layout 35 | { 36 | Q_OBJECT 37 | Q_PROPERTY(QByteArray binaryFooter READ binaryFooter WRITE setBinaryFooter) 38 | Q_PROPERTY(QByteArray binaryHeader READ binaryHeader WRITE setBinaryHeader) 39 | 40 | public: 41 | explicit BinaryLayout(QObject *parent = nullptr); 42 | 43 | virtual QByteArray binaryFormat(const BinaryLoggingEvent &event) const; 44 | virtual QString format(const LoggingEvent &event) override; 45 | 46 | virtual QString contentType() const override; 47 | 48 | virtual QByteArray binaryFooter() const; 49 | void setBinaryFooter(const QByteArray &footer); 50 | 51 | virtual QByteArray binaryHeader() const; 52 | void setBinaryHeader(const QByteArray &header); 53 | 54 | private: 55 | Q_DISABLE_COPY_MOVE(BinaryLayout) 56 | 57 | QByteArray mFooter; 58 | QByteArray mHeader; 59 | }; 60 | 61 | inline QByteArray BinaryLayout::binaryFooter() const 62 | { 63 | return mFooter; 64 | } 65 | 66 | inline void BinaryLayout::setBinaryFooter(const QByteArray &footer) 67 | { 68 | mFooter = footer; 69 | } 70 | 71 | inline QByteArray BinaryLayout::binaryHeader() const 72 | { 73 | return mHeader; 74 | } 75 | 76 | inline void BinaryLayout::setBinaryHeader(const QByteArray &header) 77 | { 78 | mHeader = header; 79 | } 80 | 81 | } // namespace Log4Qt 82 | 83 | #endif // LOG4QT_BINARYLAYOUT_H 84 | -------------------------------------------------------------------------------- /src/log4qt/binarylogger.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "binarylogger.h" 22 | #include "binaryloggingevent.h" 23 | #include "helpers/classlogger.h" 24 | #include "helpers/datetime.h" 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | BinaryLogger::BinaryLogger(LoggerRepository *loggerRepository, Level level, const QString &name, Logger *parent) 30 | : Logger(loggerRepository, level, name, parent) 31 | { 32 | } 33 | 34 | BinaryLogger::~BinaryLogger() = default; 35 | 36 | void BinaryLogger::forcedLog(Level level, const QByteArray &message) const 37 | { 38 | BinaryLoggingEvent event(this, level, message); 39 | callAppenders(event); 40 | } 41 | 42 | BinaryLogStream BinaryLogger::log(Level level) const 43 | { 44 | return BinaryLogStream(this, level); 45 | } 46 | 47 | void BinaryLogger::log(Level level, const QByteArray &message) const 48 | { 49 | if (isEnabledFor(level)) 50 | forcedLog(level, message); 51 | } 52 | 53 | void BinaryLogger::log(Level level, const QByteArray &message, QDateTime timeStamp) const 54 | { 55 | if (isEnabledFor(level)) 56 | { 57 | BinaryLoggingEvent event(this, level, message, timeStamp.toMSecsSinceEpoch()); 58 | callAppenders(event); 59 | } 60 | } 61 | 62 | } // namespace Log4Qt 63 | 64 | #include "moc_binarylogger.cpp" 65 | 66 | -------------------------------------------------------------------------------- /src/log4qt/binarylogger.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_BINARYLOGGER_H 22 | #define LOG4QT_BINARYLOGGER_H 23 | 24 | #include "logger.h" 25 | #include "binarylogstream.h" 26 | #include "helpers/binaryclasslogger.h" 27 | 28 | class QByteArray; 29 | 30 | namespace Log4Qt 31 | { 32 | 33 | class Appender; 34 | class BinaryLoggingEvent; 35 | class LoggerRepository; 36 | class Hierarchy; 37 | 38 | #define LOG4QT_DECLARE_STATIC_BINARYLOGGER(FUNCTION, CLASS) \ 39 | static Log4Qt::BinaryLogger *FUNCTION() \ 40 | { \ 41 | static Log4Qt::Logger * p_logger(Log4Qt::Logger::logger(#CLASS"@@binary@@" )); \ 42 | return qobject_cast(p_logger); \ 43 | } 44 | 45 | #define LOG4QT_DECLARE_QCLASS_BINARYLOGGER \ 46 | private: \ 47 | mutable Log4Qt::BinaryClassLogger mLog4QtClassLogger; \ 48 | public: \ 49 | inline Log4Qt::BinaryLogger *logger() const \ 50 | { \ 51 | return mLog4QtClassLogger.logger(this); \ 52 | } \ 53 | private: 54 | 55 | class LOG4QT_EXPORT BinaryLogger : public Logger 56 | { 57 | Q_OBJECT 58 | public: 59 | BinaryLogStream debug() const {return log(Level::DEBUG_INT);} 60 | void debug(const QByteArray &message) const {log(Level::DEBUG_INT, message);} 61 | BinaryLogStream error() const {return log(Level::ERROR_INT);} 62 | void error(const QByteArray &message) const {log(Level::ERROR_INT, message);} 63 | BinaryLogStream fatal() const {return log(Level::FATAL_INT);} 64 | void fatal(const QByteArray &message) const {log(Level::FATAL_INT, message);} 65 | BinaryLogStream info() const {return log(Level::INFO_INT);} 66 | void info(const QByteArray &message) const {log(Level::INFO_INT, message);} 67 | BinaryLogStream trace() const {return log(Level::TRACE_INT);} 68 | void trace(const QByteArray &message) const {log(Level::TRACE_INT, message);} 69 | BinaryLogStream warn() const {return log(Level::WARN_INT);} 70 | void warn(const QByteArray &message) const {log(Level::WARN_INT, message);} 71 | 72 | BinaryLogStream log(Level level) const; 73 | void log(Level level, const QByteArray &message) const; 74 | void log(Level level, const QByteArray &message, QDateTime timeStamp) const; 75 | 76 | protected: 77 | BinaryLogger(LoggerRepository *loggerRepository, Level level, const QString &name, Logger *parent = nullptr); 78 | virtual ~BinaryLogger(); 79 | 80 | void forcedLog(Level level, const QByteArray &message) const; 81 | 82 | private: 83 | BinaryLogger(const BinaryLogger &other); // Not implemented 84 | BinaryLogger &operator=(const BinaryLogger &other); // Not implemented 85 | // Needs to be friend to create BinaryLogger objects 86 | friend class Hierarchy; 87 | }; 88 | 89 | } // namespace Log4Qt 90 | 91 | #endif // LOG4QT_BINARYLOGGER_H 92 | -------------------------------------------------------------------------------- /src/log4qt/binaryloggingevent.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "binaryloggingevent.h" 22 | #include "logger.h" 23 | #include "helpers/datetime.h" 24 | 25 | #ifndef QT_NO_DATASTREAM 26 | #include 27 | #endif 28 | 29 | namespace Log4Qt 30 | { 31 | 32 | static const char binMarker[] = "@@@ binary message @@@"; 33 | 34 | BinaryLoggingEvent::BinaryLoggingEvent() = default; 35 | 36 | BinaryLoggingEvent::BinaryLoggingEvent(const Logger *logger, Level level, const QByteArray &message) 37 | : LoggingEvent(logger, level, QString(binMarker)) 38 | , mBinaryMessage(message) 39 | { 40 | } 41 | 42 | BinaryLoggingEvent::BinaryLoggingEvent(const Logger *logger, Level level, const QByteArray &message, qint64 timeStamp) 43 | : LoggingEvent(logger, level, QString(binMarker), timeStamp) 44 | , mBinaryMessage(message) 45 | { 46 | } 47 | 48 | BinaryLoggingEvent::BinaryLoggingEvent(const Logger *logger, Level level, const QByteArray &message, const QString &ndc, const QHash &properties, const QString &threadName, qint64 timeStamp) 49 | : LoggingEvent(logger, level, QString(binMarker), ndc, properties, threadName, timeStamp) 50 | , mBinaryMessage(message) 51 | { 52 | } 53 | 54 | QByteArray BinaryLoggingEvent::binaryMessage() const 55 | { 56 | return mBinaryMessage; 57 | } 58 | 59 | QString BinaryLoggingEvent::toString() const 60 | { 61 | return level().toString() + QLatin1Char(':') + mBinaryMessage.toHex(); 62 | } 63 | 64 | QString BinaryLoggingEvent::binaryMarker() 65 | { 66 | return binMarker; 67 | } 68 | 69 | #ifndef QT_NO_DATASTREAM 70 | QDataStream &operator<<(QDataStream &out, const BinaryLoggingEvent &loggingEvent) 71 | { 72 | out << static_cast(loggingEvent); 73 | out << loggingEvent.mBinaryMessage; 74 | return out; 75 | } 76 | 77 | QDataStream &operator>>(QDataStream &in, BinaryLoggingEvent &loggingEvent) 78 | { 79 | in >> static_cast(loggingEvent); 80 | in >> loggingEvent.mBinaryMessage; 81 | return in; 82 | } 83 | #endif // QT_NO_DATASTREAM 84 | 85 | } // namespace Log4Qt 86 | -------------------------------------------------------------------------------- /src/log4qt/binaryloggingevent.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_BINARYLOGGINGEVENT_H 22 | #define LOG4QT_BINARYLOGGINGEVENT_H 23 | 24 | #include "loggingevent.h" 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | class LOG4QT_EXPORT BinaryLoggingEvent : public LoggingEvent 30 | { 31 | public: 32 | BinaryLoggingEvent(); 33 | BinaryLoggingEvent(const Logger *logger, 34 | Level level, 35 | const QByteArray &message); 36 | BinaryLoggingEvent(const Logger *logger, 37 | Level level, 38 | const QByteArray &message, 39 | qint64 timeStamp); 40 | BinaryLoggingEvent(const Logger *logger, 41 | Level level, 42 | const QByteArray &message, 43 | const QString &ndc, 44 | const QHash &properties, 45 | const QString &threadName, 46 | qint64 timeStamp); 47 | QByteArray binaryMessage() const; 48 | 49 | QString toString() const; 50 | 51 | static QString binaryMarker(); 52 | 53 | private: 54 | QByteArray mBinaryMessage; 55 | 56 | #ifndef QT_NO_DATASTREAM 57 | // Needs to be friend to stream objects 58 | friend LOG4QT_EXPORT QDataStream &operator<<(QDataStream &out, const BinaryLoggingEvent &loggingEvent); 59 | friend LOG4QT_EXPORT QDataStream &operator>>(QDataStream &in, BinaryLoggingEvent &loggingEvent); 60 | #endif // QT_NO_DATASTREAM 61 | }; 62 | 63 | #ifndef QT_NO_DATASTREAM 64 | LOG4QT_EXPORT QDataStream &operator<<(QDataStream &out, const BinaryLoggingEvent &loggingEvent); 65 | LOG4QT_EXPORT QDataStream &operator>>(QDataStream &in, BinaryLoggingEvent &loggingEvent); 66 | #endif // QT_NO_DATASTREAM 67 | 68 | } // namespace Log4Qt 69 | 70 | Q_DECLARE_METATYPE(Log4Qt::BinaryLoggingEvent) 71 | Q_DECLARE_TYPEINFO(Log4Qt::BinaryLoggingEvent, Q_MOVABLE_TYPE); 72 | 73 | #endif // LOG4QT_BINARYLOGGINGEVENT_H 74 | -------------------------------------------------------------------------------- /src/log4qt/binarylogstream.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "binarylogstream.h" 22 | #include "binarylogger.h" 23 | #include "binaryloggingevent.h" 24 | 25 | #include 26 | #include 27 | 28 | namespace Log4Qt 29 | { 30 | 31 | struct BinaryLogStream::Stream 32 | { 33 | Stream(const Logger *logger, Level level) 34 | : logger(logger) 35 | , level(level) 36 | { 37 | } 38 | ~Stream(); 39 | 40 | QByteArray buffer; 41 | QPointer logger; 42 | Level level; 43 | }; 44 | 45 | BinaryLogStream::Stream::~Stream() 46 | { 47 | if (auto blogger = qobject_cast(logger)) 48 | blogger->log(level, buffer); 49 | else if (logger->isEnabledFor(level)) 50 | { 51 | BinaryLoggingEvent event(logger, level, buffer); 52 | logger->callAppenders(event); 53 | } 54 | } 55 | 56 | BinaryLogStream::BinaryLogStream(const Logger *logger, Level level) 57 | : mStream(new Stream(logger, level)) 58 | { 59 | } 60 | 61 | BinaryLogStream &BinaryLogStream::operator<<(const QByteArray &data) 62 | { 63 | mStream->buffer.append(data); 64 | return *this; 65 | } 66 | 67 | } // namespace Log4Qt 68 | -------------------------------------------------------------------------------- /src/log4qt/binarylogstream.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_BINARYLOGSTREAM_H 22 | #define LOG4QT_BINARYLOGSTREAM_H 23 | 24 | #include 25 | 26 | #include "level.h" 27 | 28 | class QByteArray; 29 | 30 | namespace Log4Qt 31 | { 32 | class Logger; 33 | 34 | class LOG4QT_EXPORT BinaryLogStream 35 | { 36 | public: 37 | BinaryLogStream(const Logger *logger, Level level); 38 | 39 | BinaryLogStream &operator<<(const QByteArray &data); 40 | 41 | private: 42 | struct Stream; 43 | QSharedPointer mStream; 44 | }; 45 | 46 | } // namespace Log4Qt 47 | 48 | #endif // LOG4QT_BINARYLOGSTREAM_H 49 | -------------------------------------------------------------------------------- /src/log4qt/binarytotextlayout.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "binarytotextlayout.h" 22 | #include "binaryloggingevent.h" 23 | #include "simplelayout.h" 24 | 25 | #include 26 | 27 | namespace Log4Qt 28 | { 29 | 30 | BinaryToTextLayout::BinaryToTextLayout(const LayoutSharedPtr &subLayout, QObject *parent) 31 | : Layout(parent) 32 | , mSubLayout(subLayout) 33 | { 34 | } 35 | 36 | QString BinaryToTextLayout::format(const LoggingEvent &event) 37 | { 38 | if (!mSubLayout.isNull()) 39 | { 40 | if (const auto *binaryEvent = dynamic_cast(&event)) 41 | { 42 | QString hexData = binaryEvent->binaryMessage().toHex(); 43 | QString spacedHexData; 44 | 45 | for (int i = 0; i < hexData.length(); i += 2) 46 | spacedHexData.append(hexData.mid(i, 2) % " "); 47 | 48 | // replace binary marker in output with hexdump 49 | return mSubLayout->format(event).replace(Log4Qt::BinaryLoggingEvent::binaryMarker(), QStringLiteral("%1 bytes: %2").arg(binaryEvent->binaryMessage().size()).arg(spacedHexData)); 50 | } 51 | } 52 | return QString(); 53 | } 54 | 55 | } // namespace Log4Qt 56 | 57 | #include "moc_binarytotextlayout.cpp" 58 | -------------------------------------------------------------------------------- /src/log4qt/binarytotextlayout.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_BINARYTOTEXTLAYOUT_H 22 | #define LOG4QT_BINARYTOTEXTLAYOUT_H 23 | 24 | #include "layout.h" 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | //! Used to format binary messages for a textual appenders 30 | class LOG4QT_EXPORT BinaryToTextLayout : public Layout 31 | { 32 | Q_OBJECT 33 | Q_PROPERTY(LayoutSharedPtr subLayout READ subLayout WRITE setSubLayout) 34 | public: 35 | explicit BinaryToTextLayout(const LayoutSharedPtr &subLayout = LayoutSharedPtr(), QObject *parent = nullptr); 36 | 37 | virtual QString format(const LoggingEvent &event) override; 38 | 39 | LayoutSharedPtr subLayout() const {return mSubLayout;} 40 | void setSubLayout(const LayoutSharedPtr &layout) {mSubLayout = layout;} 41 | 42 | private: 43 | Q_DISABLE_COPY_MOVE(BinaryToTextLayout) 44 | LayoutSharedPtr mSubLayout; 45 | }; 46 | 47 | } // namespace Log4Qt 48 | 49 | #endif // LOG4QT_BINARYTOTEXTLAYOUT_H 50 | -------------------------------------------------------------------------------- /src/log4qt/binarywriterappender.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_BINARYWRITTERAPPENDER_H 22 | #define LOG4QT_BINARYWRITTERAPPENDER_H 23 | 24 | #include "appenderskeleton.h" 25 | 26 | class QDataStream; 27 | namespace Log4Qt 28 | { 29 | 30 | class BinaryLayout; 31 | 32 | class LOG4QT_EXPORT BinaryWriterAppender : public AppenderSkeleton 33 | { 34 | Q_OBJECT 35 | Q_PROPERTY(QDataStream *writer READ writer WRITE setWriter) 36 | public: 37 | BinaryWriterAppender(QObject *parent = nullptr); 38 | BinaryWriterAppender(QDataStream *dataStream, QObject *parent = nullptr); 39 | ~BinaryWriterAppender() override; 40 | 41 | bool requiresLayout() const override; 42 | QDataStream *writer() const; 43 | 44 | void setWriter(QDataStream *dataStream); 45 | 46 | void activateOptions() override; 47 | void close() override; 48 | 49 | protected: 50 | void append(const LoggingEvent &event) override; 51 | bool checkEntryConditions() const override; 52 | 53 | void closeWriter(); 54 | 55 | virtual bool handleIoErrors() const; 56 | void writeFooter() const; 57 | void writeHeader() const; 58 | 59 | private: 60 | Q_DISABLE_COPY_MOVE(BinaryWriterAppender) 61 | void writeRawData(const QByteArray &data) const; 62 | void closeInternal(); 63 | BinaryLayout *binaryLayout() const; 64 | 65 | QDataStream *mWriter; 66 | }; 67 | 68 | inline QDataStream *BinaryWriterAppender::writer() const 69 | { 70 | return mWriter; 71 | } 72 | 73 | } // namespace Log4Qt 74 | 75 | #endif // LOG4QT_BINARYWRITTERAPPENDER_H 76 | -------------------------------------------------------------------------------- /src/log4qt/colorconsoleappender.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_COLORCONSOLEAPPENDER_H 22 | #define LOG4QT_COLORCONSOLEAPPENDER_H 23 | 24 | #include "consoleappender.h" 25 | 26 | // if we are in WIN* 27 | #ifdef Q_OS_WIN 28 | #define WIN32_LEAN_AND_MEAN 29 | #define NOGDI 30 | #include 31 | #endif 32 | 33 | class QFile; 34 | class QTextStream; 35 | 36 | namespace Log4Qt 37 | { 38 | 39 | /*! 40 | * \brief The class ColorConsoleAppender appends to stdout or stderr with color formatting. 41 | * 42 | * \note All the functions declared in this class are thread-safe. 43 | * 44 | * \note The ownership and lifetime of objects of this class are managed. 45 | * See \ref Ownership "Object ownership" for more details. 46 | */ 47 | class LOG4QT_EXPORT ColorConsoleAppender : public ConsoleAppender 48 | { 49 | Q_OBJECT 50 | 51 | public: 52 | ColorConsoleAppender(QObject *parent = nullptr); 53 | ColorConsoleAppender(const LayoutSharedPtr &layout, 54 | QObject *parent = nullptr); 55 | ColorConsoleAppender(const LayoutSharedPtr &layout, 56 | const QString &target, 57 | QObject *parent = nullptr); 58 | /*! 59 | * Creates a ConsoleAppender with the layout \a pLayout, the target 60 | * value specified by the \a target constant and the parent 61 | * \a parent. 62 | */ 63 | ColorConsoleAppender(const LayoutSharedPtr &layout, 64 | Target target, 65 | QObject *parent = nullptr); 66 | 67 | ~ColorConsoleAppender() override; 68 | // if we are in WIN* 69 | #ifdef Q_OS_WIN 70 | void activateOptions() override; 71 | void close() override; 72 | 73 | protected: 74 | void append(const LoggingEvent &event) override; 75 | 76 | private: 77 | HANDLE hConsole; 78 | #endif 79 | void closeInternal(); 80 | }; 81 | 82 | 83 | } // namespace Log4Qt 84 | 85 | 86 | #endif // #ifndef LOG4QT_COLORCONSOLEAPPENDER_H 87 | -------------------------------------------------------------------------------- /src/log4qt/dailyfileappender.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_DAILYFILEAPPENDER_H 22 | #define LOG4QT_DAILYFILEAPPENDER_H 23 | 24 | #include "fileappender.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | namespace Log4Qt 32 | { 33 | 34 | class LOG4QT_EXPORT IDateRetriever 35 | { 36 | public: 37 | virtual ~IDateRetriever(); 38 | virtual QDate currentDate() const = 0; 39 | }; 40 | 41 | class LOG4QT_EXPORT DefaultDateRetriever final : public IDateRetriever 42 | { 43 | public: 44 | 45 | /** 46 | * Return the current date, as reported by the system clock. 47 | */ 48 | QDate currentDate() const override; 49 | }; 50 | 51 | /*! 52 | * \brief The class DailyFileAppender extends FileAppender so that the 53 | * a log file is created for each day 54 | */ 55 | class LOG4QT_EXPORT DailyFileAppender : public FileAppender 56 | { 57 | Q_OBJECT 58 | 59 | //! The property holds the date pattern used by the appender. 60 | Q_PROPERTY(QString datePattern READ datePattern WRITE setDatePattern) 61 | 62 | /** 63 | * Number of days that old log files will be kept on disk. 64 | * Set to a positive value to enable automatic deletion. Per default, all files are kept. Check 65 | * for obsolete files happens once a day. 66 | */ 67 | Q_PROPERTY(int keepDays READ keepDays WRITE setKeepDays) 68 | 69 | public: 70 | explicit DailyFileAppender(QObject *parent = nullptr); 71 | DailyFileAppender(const LayoutSharedPtr &layout, const QString &fileName, const QString &datePattern = QString(), int keepDays = 0, QObject *parent = nullptr); 72 | 73 | QString datePattern() const; 74 | void setDatePattern(const QString &datePattern); 75 | 76 | int keepDays() const; 77 | void setKeepDays(int keepDays); 78 | 79 | void activateOptions() override; 80 | 81 | void append(const LoggingEvent &event) override; 82 | 83 | void setDateRetriever(const QSharedPointer &dateRetriever); 84 | 85 | private: 86 | Q_DISABLE_COPY_MOVE(DailyFileAppender) 87 | 88 | void setLogFileForCurrentDay(); 89 | void rollOver(); 90 | QString appendDateToFilename() const; 91 | 92 | QSharedPointer mDateRetriever; 93 | 94 | QString mDatePattern; 95 | QDate mLastDate; 96 | int mKeepDays; 97 | QString mOriginalFilename; 98 | 99 | QFutureSynchronizer mDeleteObsoleteFilesExecutors; 100 | }; 101 | 102 | } 103 | 104 | #endif // LOG4QT_DAILYFILEAPPENDER_H 105 | -------------------------------------------------------------------------------- /src/log4qt/databaselayout.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * package: Log4Qt 4 | * file: databaselayout.h 5 | * created: March 2010 6 | * author: Michael Filonenko 7 | * 8 | * 9 | * Copyright 2010 Michael Filonenko 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | ******************************************************************************/ 24 | 25 | #ifndef LOG4QT_DATABASELAYOUT_H 26 | #define LOG4QT_DATABASELAYOUT_H 27 | 28 | 29 | #include "layout.h" 30 | 31 | #include 32 | 33 | 34 | namespace Log4Qt 35 | { 36 | 37 | /*! 38 | * \brief The class DatabaseLayout outputs loggin event into sql table. 39 | * 40 | * \note The ownership and lifetime of objects of this class are managed. 41 | * See \ref Ownership "Object ownership" for more details. 42 | */ 43 | class LOG4QT_EXPORT DatabaseLayout : public Layout 44 | { 45 | Q_OBJECT 46 | 47 | /*! 48 | The property holds column name to save timestamp of log event 49 | */ 50 | Q_PROPERTY(QString timeStampColumn READ timeStampColumn WRITE setTimeStampColumn) 51 | /*! 52 | The property holds column name to save logger name of log event 53 | */ 54 | Q_PROPERTY(QString loggenameColumn READ loggenameColumn WRITE setLoggenameColumn) 55 | /*! 56 | The property holds column name to save thread name of log event 57 | */ 58 | Q_PROPERTY(QString threadNameColumn READ threadNameColumn WRITE setThreadNameColumn) 59 | /*! 60 | The property holds column name to save level of log event 61 | */ 62 | Q_PROPERTY(QString levelColumn READ levelColumn WRITE setLevelColumn) 63 | /*! 64 | The property holds column name to save message of log event 65 | */ 66 | Q_PROPERTY(QString messageColumn READ messageColumn WRITE setMessageColumn) 67 | 68 | 69 | public: 70 | DatabaseLayout(QObject *parent = nullptr); 71 | // virtual ~DatabaseLayout(); // Use compiler default 72 | private: 73 | Q_DISABLE_COPY(DatabaseLayout) 74 | 75 | public: 76 | virtual QSqlRecord formatRecord(const LoggingEvent &event); 77 | QString format(const LoggingEvent &event) override; 78 | 79 | QString timeStampColumn() const; 80 | QString loggenameColumn() const; 81 | QString threadNameColumn() const; 82 | QString levelColumn() const; 83 | QString messageColumn() const; 84 | 85 | void setTimeStampColumn(const QString &columnName); 86 | void setLoggenameColumn(const QString &columnName); 87 | void setThreadNameColumn(const QString &columnName); 88 | void setLevelColumn(const QString &columnName); 89 | void setMessageColumn(const QString &columnName); 90 | 91 | private: 92 | QString mTimeStamp; 93 | QString mLoggename; 94 | QString mThreadName; 95 | QString mLevel; 96 | QString mMessage; 97 | }; 98 | 99 | 100 | inline DatabaseLayout::DatabaseLayout(QObject *parent) : 101 | Layout(parent) 102 | {} 103 | 104 | 105 | } // namespace Log4Qt 106 | 107 | #endif // LOG4QT_DATABASELAYOUT_H 108 | -------------------------------------------------------------------------------- /src/log4qt/helpers/appenderattachable.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "helpers/appenderattachable.h" 22 | #include "varia/listappender.h" 23 | #include "appender.h" 24 | 25 | #if (__cplusplus >= 201703L) // C++17 or later 26 | #include 27 | #endif 28 | 29 | namespace Log4Qt 30 | { 31 | 32 | AppenderAttachable::AppenderAttachable() : 33 | mAppenderGuard(QReadWriteLock::Recursive) 34 | { 35 | } 36 | 37 | AppenderAttachable::~AppenderAttachable() = default; 38 | 39 | QList AppenderAttachable::appenders() const 40 | { 41 | QReadLocker locker(&mAppenderGuard); 42 | return mAppenders; 43 | } 44 | 45 | AppenderSharedPtr AppenderAttachable::appender(const QString &name) const 46 | { 47 | QReadLocker locker(&mAppenderGuard); 48 | 49 | #if (__cplusplus >= 201703L) 50 | for (auto &&pAppender : std::as_const(mAppenders)) 51 | #else 52 | for (auto &&pAppender : qAsConst(mAppenders)) 53 | #endif 54 | if (pAppender->name() == name) 55 | return pAppender; 56 | return AppenderSharedPtr(); 57 | } 58 | 59 | void AppenderAttachable::addAppender(const AppenderSharedPtr &appender) 60 | { 61 | if (appender.isNull()) 62 | return; 63 | QWriteLocker locker(&mAppenderGuard); 64 | if (mAppenders.contains(appender)) 65 | return; 66 | mAppenders.append(appender); 67 | } 68 | 69 | bool AppenderAttachable::isAttached(const AppenderSharedPtr &appender) const 70 | { 71 | QReadLocker locker(&mAppenderGuard); 72 | return mAppenders.contains(appender); 73 | } 74 | 75 | void AppenderAttachable::removeAllAppenders() 76 | { 77 | mAppenders.clear(); 78 | } 79 | 80 | void AppenderAttachable::removeAppender(const AppenderSharedPtr &appender) 81 | { 82 | if (appender.isNull()) 83 | return; 84 | QWriteLocker locker(&mAppenderGuard); 85 | mAppenders.removeAll(appender); 86 | 87 | } 88 | 89 | void AppenderAttachable::removeAppender(const QString &name) 90 | { 91 | AppenderSharedPtr pAppender = appender(name); 92 | if (pAppender) 93 | removeAppender(pAppender); 94 | } 95 | 96 | } // namespace Log4Qt 97 | 98 | -------------------------------------------------------------------------------- /src/log4qt/helpers/appenderattachable.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_APPENDERATTACHABLE_H 22 | #define LOG4QT_APPENDERATTACHABLE_H 23 | 24 | #include "log4qt/log4qt.h" 25 | #include "log4qt/appender.h" 26 | 27 | #include 28 | #include 29 | 30 | namespace Log4Qt 31 | { 32 | 33 | /*! 34 | * \brief Implementation for attaching appenders to objects 35 | */ 36 | class LOG4QT_EXPORT AppenderAttachable 37 | { 38 | 39 | public: 40 | AppenderAttachable(); 41 | virtual ~AppenderAttachable(); 42 | 43 | /*! 44 | * Add an appender. 45 | */ 46 | virtual void addAppender(const AppenderSharedPtr &appender); 47 | 48 | /*! 49 | * Get all previously added appenders as an Enumeration. 50 | */ 51 | virtual QList appenders() const; 52 | 53 | /*! 54 | * Get an appender by name. 55 | */ 56 | virtual AppenderSharedPtr appender(const QString &name) const; 57 | 58 | /*! 59 | Returns true if the specified appender is in the 60 | list of attached appenders, false otherwise. 61 | */ 62 | virtual bool isAttached(const AppenderSharedPtr &appender) const; 63 | 64 | /*! 65 | * Removes all appenders that have been previously added from this 66 | * Logger. 67 | * 68 | * To allow configurators to collect events during the configuration 69 | * process ListAppenders with the configuratorList property set, will 70 | * not be removed. 71 | * 72 | * \sa LisAppender::setConfiguratorList() 73 | */ 74 | virtual void removeAllAppenders(); 75 | 76 | /*! 77 | * Remove the appender passed as parameter from the list of appenders. 78 | */ 79 | virtual void removeAppender(const AppenderSharedPtr &appender); 80 | 81 | /*! 82 | * Remove the appender with the name passed as parameter from the 83 | * list of appenders. 84 | */ 85 | virtual void removeAppender(const QString &name); 86 | 87 | protected: 88 | QList mAppenders; 89 | mutable QReadWriteLock mAppenderGuard; 90 | }; 91 | 92 | } // namespace Log4Qt 93 | 94 | #endif // LOG4QT_APPENDERATTACHABLE_H 95 | -------------------------------------------------------------------------------- /src/log4qt/helpers/binaryclasslogger.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "helpers/binaryclasslogger.h" 22 | 23 | #include "logmanager.h" 24 | #include "binarylogger.h" 25 | 26 | #include 27 | 28 | namespace Log4Qt 29 | { 30 | 31 | BinaryClassLogger::BinaryClassLogger() 32 | : mLogger(nullptr) 33 | { 34 | } 35 | 36 | BinaryLogger *BinaryClassLogger::logger(const QObject *object) 37 | { 38 | Q_ASSERT_X(object, "BinaryClassLogger::logger()", "object must not be null"); 39 | QString loggename(object->metaObject()->className()); 40 | loggename += QStringLiteral("@@binary@@"); 41 | if (!mLogger.loadAcquire()) 42 | mLogger.testAndSetOrdered(nullptr, qobject_cast(LogManager::logger(loggename))); 43 | return mLogger.loadAcquire(); 44 | } 45 | 46 | } // namespace Log4Qt 47 | -------------------------------------------------------------------------------- /src/log4qt/helpers/binaryclasslogger.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_BINARYCLASSLOGGER_H 22 | #define LOG4QT_BINARYCLASSLOGGER_H 23 | 24 | #include "log4qt/log4qtshared.h" 25 | 26 | #include 27 | 28 | class QObject; 29 | namespace Log4Qt 30 | { 31 | 32 | class Logger; 33 | class BinaryLogger; 34 | 35 | class LOG4QT_EXPORT BinaryClassLogger 36 | { 37 | public: 38 | BinaryClassLogger(); 39 | BinaryLogger *logger(const QObject *object); 40 | 41 | private: 42 | mutable QAtomicPointer mLogger; 43 | }; 44 | 45 | } // namespace Log4Qt 46 | 47 | #endif // LOG4QT_BINARYCLASSLOGGER_H 48 | -------------------------------------------------------------------------------- /src/log4qt/helpers/classlogger.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "logmanager.h" 22 | #include "helpers/classlogger.h" 23 | 24 | namespace Log4Qt 25 | { 26 | 27 | ClassLogger::ClassLogger() : 28 | mLogger(nullptr) 29 | { 30 | } 31 | 32 | Logger *ClassLogger::logger(const QObject *object) 33 | { 34 | Q_ASSERT_X(object, "ClassLogger::logger()", "pObject must not be null"); 35 | if (!static_cast(mLogger.loadAcquire())) 36 | mLogger.testAndSetOrdered(nullptr, 37 | LogManager::logger(QLatin1String(object->metaObject()->className()))); 38 | return const_cast(static_cast(mLogger.loadAcquire())); 39 | } 40 | 41 | } // namespace Log4Qt 42 | -------------------------------------------------------------------------------- /src/log4qt/helpers/classlogger.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_CLASSLOGGER_H 22 | #define LOG4QT_CLASSLOGGER_H 23 | 24 | #include "log4qt/log4qtshared.h" 25 | 26 | #include 27 | 28 | class QObject; 29 | 30 | namespace Log4Qt 31 | { 32 | class Logger; 33 | 34 | /*! 35 | * \brief The class ClassLogger provides logging for a QObject derived 36 | * class. 37 | * 38 | * The class ClassLogger provides a logger for a specified QObject derived 39 | * object. It is used by \ref LOG4QT_DECLARE_QCLASS_LOGGER to implement the 40 | * member functions provided by the macro. 41 | * 42 | * \note All the functions declared in this class are thread-safe. 43 | * 44 | * \sa LOG4QT_DECLARE_QCLASS_LOGGER 45 | */ 46 | class LOG4QT_EXPORT ClassLogger 47 | { 48 | public: 49 | /*! 50 | * Creates a ClassLogger object. 51 | */ 52 | ClassLogger(); 53 | 54 | /*! 55 | * Returns a pointer to a Logger named after the class of the object 56 | * \a pObject. 57 | * 58 | * On the first invocation the Logger is requested by a call to 59 | * LogManager::logger(const char *pName). The pointer is stored to be 60 | * returned on subsequent invocations. 61 | * 62 | * \sa LogManager::logger(const char *pName) 63 | */ 64 | Logger *logger(const QObject *object); 65 | 66 | private: 67 | mutable QAtomicPointer mLogger; 68 | }; 69 | 70 | } // namespace Log4Qt 71 | 72 | #endif // LOG4QT_CLASSLOGGER_H 73 | -------------------------------------------------------------------------------- /src/log4qt/helpers/configuratorhelper.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "helpers/configuratorhelper.h" 22 | 23 | #include "helpers/initialisationhelper.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace Log4Qt 31 | { 32 | 33 | ConfiguratorHelper::ConfiguratorHelper(QObject *parent) : 34 | QObject(parent), 35 | mConfigureFunc(nullptr), 36 | mConfigurationFileWatch(nullptr) 37 | { 38 | } 39 | 40 | 41 | ConfiguratorHelper::~ConfiguratorHelper() 42 | { 43 | delete mConfigurationFileWatch; 44 | } 45 | 46 | LOG4QT_IMPLEMENT_INSTANCE(ConfiguratorHelper) 47 | 48 | void ConfiguratorHelper::doConfigurationFileChanged(const QString &fileName) 49 | { 50 | if (!mConfigureFunc || 51 | !QFileInfo::exists(mConfigurationFile.absoluteFilePath())) 52 | return; 53 | mConfigureFunc(fileName); 54 | Q_EMIT configurationFileChanged(fileName, mConfigureError.count() > 0); 55 | } 56 | 57 | void ConfiguratorHelper::doConfigurationFileDirectoryChanged(const QString &path) 58 | { 59 | Q_UNUSED(path) 60 | QTimer::singleShot(100, this, &ConfiguratorHelper::tryToReAddConfigurationFile); 61 | } 62 | 63 | void ConfiguratorHelper::tryToReAddConfigurationFile() 64 | { 65 | if (!mConfigurationFileWatch->files().contains(mConfigurationFile.absoluteFilePath())) 66 | mConfigurationFileWatch->addPath(mConfigurationFile.absoluteFilePath()); 67 | } 68 | 69 | void ConfiguratorHelper::doSetConfigurationFile(const QString &fileName, 70 | ConfigureFunc pConfigureFunc) 71 | { 72 | QMutexLocker locker(&mObjectGuard); 73 | mConfigurationFile.setFile(fileName); 74 | mConfigureFunc = nullptr; 75 | delete mConfigurationFileWatch; 76 | mConfigurationFileWatch = nullptr; 77 | if (fileName.isEmpty() || !QFileInfo::exists(fileName)) 78 | return; 79 | 80 | mConfigureFunc = pConfigureFunc; 81 | mConfigurationFileWatch = new QFileSystemWatcher(); 82 | 83 | if (mConfigurationFileWatch->addPath(mConfigurationFile.absoluteFilePath())) 84 | { 85 | mConfigurationFileWatch->addPath(mConfigurationFile.absolutePath()); 86 | connect(mConfigurationFileWatch, &QFileSystemWatcher::fileChanged, 87 | this, &ConfiguratorHelper::doConfigurationFileChanged); 88 | connect(mConfigurationFileWatch, &QFileSystemWatcher::directoryChanged, 89 | this, &ConfiguratorHelper::doConfigurationFileDirectoryChanged); 90 | } 91 | else 92 | qWarning() << "Add Path '" << fileName << "' to file system watcher failed!"; 93 | } 94 | 95 | } // namespace Log4Qt 96 | 97 | #include "moc_configuratorhelper.cpp" 98 | -------------------------------------------------------------------------------- /src/log4qt/helpers/datetime.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "helpers/datetime.h" 22 | 23 | #include "helpers/initialisationhelper.h" 24 | 25 | namespace Log4Qt 26 | { 27 | 28 | DateTime::DateTime() = default; 29 | 30 | DateTime::~DateTime() = default; 31 | 32 | DateTime::DateTime(const DateTime &other) = default; 33 | 34 | QString DateTime::toString(const QString &format) const 35 | { 36 | if (format.isEmpty()) 37 | return QString(); 38 | if (!isValid()) 39 | return QString(); 40 | 41 | if (format == QStringLiteral("NONE")) 42 | return QString(); 43 | if (format == QStringLiteral("RELATIVE")) 44 | return QString::number(toMSecsSinceEpoch() - InitialisationHelper::startTime()); 45 | if (format == QStringLiteral("ISO8601")) 46 | return formatDateTime(QStringLiteral("yyyy-MM-dd hh:mm:ss.zzz")); 47 | if (format == QStringLiteral("ABSOLUTE")) 48 | return formatDateTime(QStringLiteral("HH:mm:ss.zzz")); 49 | if (format == QStringLiteral("DATE")) 50 | return formatDateTime(QStringLiteral("dd MM yyyy HH:mm:ss.zzz")); 51 | 52 | return formatDateTime(format); 53 | } 54 | 55 | QString DateTime::formatDateTime(const QString &format) const 56 | { 57 | return QDateTime::toString(format); 58 | } 59 | 60 | } // namespace Log4Qt 61 | -------------------------------------------------------------------------------- /src/log4qt/helpers/dispatcher.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "helpers/dispatcher.h" 22 | #include "loggingevent.h" 23 | #include "asyncappender.h" 24 | 25 | #include 26 | 27 | namespace Log4Qt 28 | { 29 | 30 | Dispatcher::Dispatcher(QObject *parent) : QObject(parent) 31 | , mAsyncAppender(nullptr) 32 | {} 33 | 34 | void Dispatcher::customEvent(QEvent *event) 35 | { 36 | if (event->type() == LoggingEvent::eventId) 37 | { 38 | auto *logEvent = static_cast(event); 39 | if (mAsyncAppender != nullptr) 40 | mAsyncAppender->callAppenders(*logEvent); 41 | } 42 | QObject::customEvent(event); 43 | } 44 | 45 | void Dispatcher::setAsyncAppender(AsyncAppender *asyncAppender) 46 | { 47 | mAsyncAppender = asyncAppender; 48 | } 49 | 50 | } // namespace Log4Qt 51 | 52 | #include "moc_dispatcher.cpp" 53 | -------------------------------------------------------------------------------- /src/log4qt/helpers/dispatcher.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QTDISPATCHER_H 22 | #define LOG4QTDISPATCHER_H 23 | 24 | #include 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | class AsyncAppender; 30 | 31 | /*! 32 | * \brief The class Dispatcher does the actual logging to the attached appanders. 33 | * 34 | * The Dispatcher is the worker object which class the attached apperders in the 35 | * the context of the DispatcherThread. 36 | * 37 | * \note All the functions declared in this class are thread-safe. 38 | */ 39 | class Dispatcher : public QObject 40 | { 41 | Q_OBJECT 42 | public: 43 | explicit Dispatcher(QObject *parent = nullptr); 44 | 45 | void setAsyncAppender(AsyncAppender *asyncAppender); 46 | 47 | protected: 48 | void customEvent(QEvent *event) override; 49 | 50 | private: 51 | AsyncAppender *mAsyncAppender; 52 | }; 53 | 54 | } // namespace Log4Qt 55 | 56 | #endif // DISPATCHER_H 57 | -------------------------------------------------------------------------------- /src/log4qt/hierarchy.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_HIERARCHY_H 22 | #define LOG4QT_HIERARCHY_H 23 | 24 | #include "loggerrepository.h" 25 | 26 | #include 27 | #include 28 | 29 | namespace Log4Qt 30 | { 31 | 32 | /*! 33 | * \brief The class Hierarchy implements a logger repository. 34 | * 35 | * \note All the functions declared in this class are thread-safe. 36 | */ 37 | class LOG4QT_EXPORT Hierarchy : public LoggerRepository 38 | { 39 | public: 40 | Hierarchy(); 41 | ~Hierarchy() override; 42 | 43 | public: 44 | bool exists(const QString &name) const override; 45 | Logger *logger(const QString &name) override; 46 | QList loggers() const override; 47 | Logger *rootLogger() const override; 48 | Level threshold() const override; 49 | void setThreshold(Level level) override; 50 | void setThreshold(const QString &threshold) override; 51 | 52 | bool isDisabled(Level level) override; 53 | void resetConfiguration() override; 54 | void shutdown() override; 55 | 56 | private: 57 | Logger *createLogger(const QString &name); 58 | void resetLogger(Logger *logger, Level level) const; 59 | 60 | private: 61 | mutable QReadWriteLock mObjectGuard; 62 | QHash mLoggers; 63 | Level mThreshold; 64 | Logger *mRootLogger; 65 | }; 66 | 67 | inline Logger *Hierarchy::rootLogger() const 68 | { 69 | return mRootLogger; 70 | } 71 | 72 | inline Level Hierarchy::threshold() const 73 | { 74 | return mThreshold; 75 | } 76 | 77 | inline void Hierarchy::setThreshold(Level level) 78 | { 79 | mThreshold = level; 80 | } 81 | 82 | inline bool Hierarchy::isDisabled(Level level) 83 | { 84 | return level < mThreshold; 85 | } 86 | 87 | } // namespace Log4Qt 88 | 89 | #endif // LOG4QT_HIERARCHY_H 90 | -------------------------------------------------------------------------------- /src/log4qt/layout.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "layout.h" 22 | 23 | #include "loggingevent.h" 24 | #include "logmanager.h" 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | Layout::Layout(QObject *parent) : 30 | QObject(parent) 31 | {} 32 | 33 | Layout::~Layout() = default; 34 | 35 | QString Layout::contentType() const 36 | { 37 | return QStringLiteral("text/plain"); 38 | } 39 | 40 | void Layout::activateOptions() 41 | { 42 | } 43 | 44 | QString Layout::endOfLine() 45 | { 46 | // There seams to be no function in Qt for this. MinGW enter '\r\n' automatically 47 | return QStringLiteral("\n"); 48 | } 49 | 50 | } // namespace Log4Qt 51 | 52 | #include "moc_layout.cpp" 53 | -------------------------------------------------------------------------------- /src/log4qt/log4qt.pro: -------------------------------------------------------------------------------- 1 | QT += core xml network concurrent 2 | include(../../build.pri) 3 | include(../../g++.pri) 4 | include(log4qt.pri) 5 | 6 | CONFIG += c++17 \ 7 | hide_symbols 8 | 9 | contains(DEFINES, LOG4QT_STATIC) { 10 | message(Building static log4qt...) 11 | CONFIG += staticlib 12 | } 13 | 14 | TEMPLATE = lib 15 | TARGET = log4qt 16 | QT -= gui 17 | 18 | # .. is needed for msvc since it is treating '.' as the directory of the current file 19 | # and not the directory where the compiled source is found 20 | INCLUDEPATH += .. . 21 | 22 | DESTDIR = ../../bin 23 | DEFINES += NOMINMAX QT_DEPRECATED_WARNINGS QT_NO_CAST_FROM_BYTEARRAY QT_USE_QSTRINGBUILDER 24 | DEFINES += LOG4QT_LIBRARY 25 | 26 | target.path = $$INSTALL_PREFIX/lib$$LIB_SUFFIX 27 | INSTALLS = target 28 | 29 | header_base.files = $$HEADERS_BASE 30 | header_base.path = $$INSTALL_PREFIX/include/log4qt 31 | INSTALLS += header_base 32 | header_helpers.files = $$HEADERS_HELPERS 33 | header_helpers.path = $$INSTALL_PREFIX/include/log4qt/helpers 34 | INSTALLS += header_helpers 35 | header_spi.files = $$HEADERS_SPI 36 | header_spi.path = $$INSTALL_PREFIX/include/log4qt/spi 37 | INSTALLS += header_spi 38 | header_varia.files = $$HEADERS_VARIA 39 | header_varia.path = $$INSTALL_PREFIX/include/log4qt/varia 40 | INSTALLS += header_varia 41 | 42 | -------------------------------------------------------------------------------- /src/log4qt/log4qtdefs.h: -------------------------------------------------------------------------------- 1 | #ifndef LOG4QTDEFS_H 2 | #define LOG4QTDEFS_H 3 | 4 | #include 5 | 6 | #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) 7 | #include 8 | #endif 9 | 10 | // use Q_DISABLE_COPY for Qt version prior to 5.13.0 11 | #ifndef Q_DISABLE_COPY_MOVE 12 | #define Q_DISABLE_COPY_MOVE(Class) \ 13 | Q_DISABLE_COPY(Class) 14 | #endif 15 | 16 | #endif // LOG4QTDEFS_H 17 | -------------------------------------------------------------------------------- /src/log4qt/log4qtshared.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_SHARED_H 22 | #define LOG4QT_SHARED_H 23 | 24 | #include 25 | 26 | // Define LOG4QT_STATIC in you applikation if you want to link against the 27 | // static version of Log4Qt 28 | 29 | #ifdef LOG4QT_STATIC 30 | # define LOG4QT_EXPORT 31 | #else 32 | # if defined(LOG4QT_LIBRARY) 33 | # define LOG4QT_EXPORT Q_DECL_EXPORT 34 | # else 35 | # define LOG4QT_EXPORT Q_DECL_IMPORT 36 | # endif 37 | #endif 38 | 39 | #endif // LOG4QT_SHARED_H 40 | -------------------------------------------------------------------------------- /src/log4qt/log4qtsharedptr.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_LOG4QTSHAREDPTR_H 22 | #define LOG4QT_LOG4QTSHAREDPTR_H 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | namespace Log4Qt 30 | { 31 | 32 | template 33 | class Log4QtSharedPtr : public QSharedPointer 34 | { 35 | public: 36 | Log4QtSharedPtr(Log4QtClass *ptr) 37 | : QSharedPointer(ptr, &Log4QtClass::deleteLater) 38 | { 39 | static_assert(std::is_base_of::value, "Need a QObject derived class here"); 40 | } 41 | 42 | Log4QtSharedPtr() 43 | : QSharedPointer() 44 | { 45 | } 46 | 47 | Log4QtSharedPtr(const QSharedPointer &other) 48 | : QSharedPointer(other) 49 | { 50 | } 51 | 52 | Log4QtSharedPtr(const QWeakPointer &other) 53 | : QSharedPointer(other) 54 | { 55 | } 56 | }; 57 | 58 | } 59 | 60 | #endif // LOG4QT_LOG4QTSHAREDPTR_H 61 | -------------------------------------------------------------------------------- /src/log4qt/loggerrepository.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "loggerrepository.h" 22 | 23 | 24 | namespace Log4Qt 25 | { 26 | 27 | LoggerRepository::LoggerRepository() = default; 28 | 29 | LoggerRepository::~LoggerRepository() = default; 30 | 31 | } // namespace Log4Qt 32 | -------------------------------------------------------------------------------- /src/log4qt/loggerrepository.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_LOGGERREPOSITORY_H 22 | #define LOG4QT_LOGGERREPOSITORY_H 23 | 24 | #include "level.h" 25 | 26 | #include 27 | 28 | namespace Log4Qt 29 | { 30 | 31 | class Logger; 32 | 33 | /*! 34 | * \brief The class LoggerRepository is abstract base class for a logger 35 | * repository. 36 | */ 37 | class LOG4QT_EXPORT LoggerRepository 38 | { 39 | public: 40 | LoggerRepository(); 41 | virtual ~LoggerRepository(); 42 | LoggerRepository(const LoggerRepository &other) = delete; 43 | LoggerRepository &operator=(const LoggerRepository &other) = delete; 44 | 45 | virtual bool exists(const QString &name) const = 0; 46 | virtual Logger *logger(const QString &name) = 0; 47 | virtual QList loggers() const = 0; 48 | virtual Logger *rootLogger() const = 0; 49 | virtual Level threshold() const = 0; 50 | virtual void setThreshold(Level level) = 0; 51 | virtual void setThreshold(const QString &threshold) = 0; 52 | 53 | virtual bool isDisabled(Level level) = 0; 54 | virtual void resetConfiguration() = 0; 55 | virtual void shutdown() = 0; 56 | }; 57 | 58 | } // namespace Log4Qt 59 | 60 | #endif // LOG4QT_LOGGERREPOSITORY_H 61 | -------------------------------------------------------------------------------- /src/log4qt/logstream.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "logstream.h" 22 | #include "logger.h" 23 | 24 | namespace Log4Qt 25 | { 26 | 27 | LogStream::LogStream(const Logger &iLogger, Level iLevel) 28 | : stream(new Stream(&iLogger, iLevel)) 29 | { 30 | } 31 | 32 | LogStream::Stream::Stream(const Logger *iLogger, Level iLevel) 33 | #if QT_VERSION < 0x060000 34 | : ts(&buffer, QIODevice::WriteOnly) 35 | #else 36 | : ts(&buffer, QIODeviceBase::WriteOnly) 37 | #endif 38 | , mLogger(iLogger) 39 | , mLevel(iLevel) 40 | { 41 | } 42 | 43 | LogStream::Stream::~Stream() 44 | { 45 | if (!mLogger.isNull()) 46 | mLogger->log(mLevel, buffer); 47 | } 48 | 49 | } // namespace Log4Qt 50 | -------------------------------------------------------------------------------- /src/log4qt/logstream.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_LOGSTREAM_H 22 | #define LOG4QT_LOGSTREAM_H 23 | 24 | #include "level.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | namespace Log4Qt 32 | { 33 | class Logger; 34 | 35 | class LOG4QT_EXPORT LogStream 36 | { 37 | public: 38 | LogStream(const Logger &iLogger, Level iLevel); 39 | template 40 | LogStream &operator<<(const T &t) 41 | { 42 | stream->ts << t; 43 | return *this; 44 | } 45 | 46 | private: 47 | struct Stream 48 | { 49 | Stream(const Logger *iLogger, Level iLevel); 50 | ~Stream(); 51 | 52 | QTextStream ts; 53 | QString buffer; 54 | QPointer mLogger; 55 | Level mLevel; 56 | }; 57 | QSharedPointer stream; 58 | }; 59 | } 60 | 61 | #endif // LOG4QT_LOGSTREAM_H 62 | -------------------------------------------------------------------------------- /src/log4qt/mainthreadappender.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "mainthreadappender.h" 22 | #include "loggingevent.h" 23 | #include "helpers/dispatcher.h" 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #if (__cplusplus >= 201703L) // C++17 or later 30 | #include 31 | #endif 32 | 33 | namespace Log4Qt 34 | { 35 | 36 | MainThreadAppender::MainThreadAppender(QObject *parent) : AppenderSkeleton(parent) 37 | {} 38 | 39 | bool MainThreadAppender::requiresLayout() const 40 | { 41 | return false; 42 | } 43 | 44 | void MainThreadAppender::activateOptions() 45 | { 46 | } 47 | 48 | void MainThreadAppender::append(const LoggingEvent &event) 49 | { 50 | QReadLocker locker(&mAppenderGuard); 51 | 52 | #if (__cplusplus >= 201703L) 53 | for (auto &&pAppender : std::as_const(mAppenders)) 54 | #else 55 | for (auto &&pAppender : qAsConst(mAppenders)) 56 | #endif 57 | { 58 | if (QThread::currentThread() != qApp->thread()) 59 | qApp->postEvent(pAppender.data(), new LoggingEvent(event)); 60 | else 61 | pAppender->doAppend(event); 62 | } 63 | } 64 | 65 | bool MainThreadAppender::checkEntryConditions() const 66 | { 67 | return AppenderSkeleton::checkEntryConditions(); 68 | } 69 | 70 | } // namespace Log4Qt 71 | 72 | #include "moc_mainthreadappender.cpp" 73 | 74 | -------------------------------------------------------------------------------- /src/log4qt/mainthreadappender.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_MAINTHREADAPPENDER_H 22 | #define LOG4QT_MAINTHREADAPPENDER_H 23 | 24 | #include "appenderskeleton.h" 25 | #include "helpers/appenderattachable.h" 26 | 27 | namespace Log4Qt 28 | { 29 | 30 | /*! 31 | * \brief The class MainThreadAppender uses the QEvent system to write 32 | * log from not main threads within the main thread. 33 | * 34 | * 35 | * \note All the functions declared in this class are thread-safe. 36 | *   37 | * \note The ownership and lifetime of objects of this class are managed. 38 | * See \ref Ownership "Object ownership" for more details. 39 | */ 40 | class LOG4QT_EXPORT MainThreadAppender : public AppenderSkeleton, public AppenderAttachable 41 | { 42 | Q_OBJECT 43 | 44 | public: 45 | MainThreadAppender(QObject *parent = nullptr); 46 | 47 | bool requiresLayout() const override; 48 | 49 | void activateOptions() override; 50 | 51 | /*! 52 | * Tests if all entry conditions for using append() in this class are 53 | * met. 54 | * 55 | * If a conditions is not met, an error is logged and the function 56 | * returns false. Otherwise the result of 57 | * AppenderSkeleton::checkEntryConditions() is returned. 58 | * 59 | * The checked conditions are: 60 | * - none 61 | * 62 | * The function is called as part of the checkEntryConditions() chain 63 | * started by AppenderSkeleton::doAppend(). 64 | * 65 | * \sa AppenderSkeleton::doAppend(), 66 | * AppenderSkeleton::checkEntryConditions() 67 | */ 68 | bool checkEntryConditions() const override; 69 | 70 | protected: 71 | void append(const LoggingEvent &event) override; 72 | 73 | private: 74 | Q_DISABLE_COPY_MOVE(MainThreadAppender) 75 | 76 | }; 77 | 78 | 79 | } // namespace Log4Qt 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/log4qt/mdc.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "mdc.h" 22 | 23 | #include 24 | #include 25 | #include "helpers/initialisationhelper.h" 26 | #include "logger.h" 27 | 28 | 29 | namespace Log4Qt 30 | { 31 | 32 | QString MDC::get(const QString &key) 33 | { 34 | if (!instance()->mHash.hasLocalData()) 35 | return QString(); 36 | 37 | return instance()->mHash.localData()->value(key); 38 | } 39 | 40 | QHash MDC::context() 41 | { 42 | if (!instance()->mHash.hasLocalData()) 43 | return QHash(); 44 | 45 | return *instance()->mHash.localData(); 46 | } 47 | 48 | LOG4QT_IMPLEMENT_INSTANCE(MDC) 49 | 50 | QHash *MDC::localData() 51 | { 52 | if (!instance()->mHash.hasLocalData()) 53 | instance()->mHash.setLocalData(new QHash); 54 | return instance()->mHash.localData(); 55 | } 56 | } // namespace Log4Qt 57 | -------------------------------------------------------------------------------- /src/log4qt/mdc.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_MDC_H 22 | #define LOG4QT_MDC_H 23 | 24 | #include "log4qtdefs.h" 25 | #include "log4qt.h" 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace Log4Qt 32 | { 33 | 34 | /*! 35 | * \brief The class MDC implements a mapped diagnostic context. 36 | * 37 | * \note All the functions declared in this class are thread-safe. 38 | */ 39 | class LOG4QT_EXPORT MDC 40 | { 41 | private: 42 | MDC(); 43 | Q_DISABLE_COPY_MOVE(MDC) 44 | 45 | public: 46 | static QString get(const QString &key); 47 | static QHash context(); 48 | 49 | /*! 50 | * Returns the MDC instance. 51 | */ 52 | static MDC *instance(); 53 | 54 | static void put(const QString &key, const QString &value); 55 | static void remove(const QString &key); 56 | 57 | private: 58 | static QHash *localData(); 59 | 60 | private: 61 | QThreadStorage *> mHash; 62 | }; 63 | 64 | inline MDC::MDC() 65 | {} 66 | 67 | inline void MDC::put(const QString &key, const QString &value) 68 | { 69 | localData()->insert(key, value); 70 | } 71 | 72 | inline void MDC::remove(const QString &key) 73 | { 74 | localData()->remove(key); 75 | } 76 | 77 | 78 | } // namespace Log4Qt 79 | 80 | #endif // LOG4QT_MDC_H 81 | -------------------------------------------------------------------------------- /src/log4qt/ndc.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "ndc.h" 22 | 23 | #include "helpers/initialisationhelper.h" 24 | #include "logger.h" 25 | 26 | #include 27 | #include 28 | 29 | namespace Log4Qt 30 | { 31 | 32 | LOG4QT_DECLARE_STATIC_LOGGER(logger, Log4Qt: NDC) 33 | 34 | void NDC::clear() 35 | { 36 | if (!instance()->mStack.hasLocalData()) 37 | return; 38 | 39 | instance()->mStack.localData()->clear(); 40 | } 41 | 42 | 43 | int NDC::depth() 44 | { 45 | if (!instance()->mStack.hasLocalData()) 46 | return 0; 47 | 48 | return instance()->mStack.localData()->count(); 49 | } 50 | 51 | 52 | LOG4QT_IMPLEMENT_INSTANCE(NDC) 53 | 54 | 55 | QString NDC::pop() 56 | { 57 | if (!instance()->mStack.hasLocalData() || instance()->mStack.localData()->isEmpty()) 58 | { 59 | logger()->warn(QStringLiteral("Requesting pop from empty NDC stack")); 60 | return QString(); 61 | } 62 | 63 | return instance()->mStack.localData()->pop(); 64 | } 65 | 66 | 67 | void NDC::push(const QString &message) 68 | { 69 | if (!instance()->mStack.hasLocalData()) 70 | instance()->mStack.setLocalData(new QStack); 71 | 72 | instance()->mStack.localData()->push(message); 73 | } 74 | 75 | 76 | void NDC::setMaxDepth(int maxDepth) 77 | { 78 | if (!instance()->mStack.hasLocalData() || 79 | instance()->mStack.localData()->size() <= maxDepth) 80 | return; 81 | 82 | instance()->mStack.localData()->resize(maxDepth); 83 | } 84 | 85 | 86 | QString NDC::peek() 87 | { 88 | if (!instance()->mStack.hasLocalData() || 89 | instance()->mStack.localData()->isEmpty()) 90 | return QString(); 91 | 92 | return instance()->mStack.localData()->top(); 93 | } 94 | 95 | } // namespace Log4Qt 96 | -------------------------------------------------------------------------------- /src/log4qt/ndc.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_NDC_H 22 | #define LOG4QT_NDC_H 23 | 24 | #include "log4qtdefs.h" 25 | #include "log4qtshared.h" 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace Log4Qt 32 | { 33 | 34 | /*! 35 | * \brief The class NDC implements a nested diagnostic context. 36 | * 37 | * The method remove() is not required. QThreadStorage cleans up on thread 38 | * exit. 39 | * 40 | * \note All the functions declared in this class are thread-safe. 41 | */ 42 | class LOG4QT_EXPORT NDC 43 | { 44 | private: 45 | NDC(); 46 | Q_DISABLE_COPY_MOVE(NDC) 47 | 48 | public: 49 | static void clear(); 50 | static int depth(); 51 | 52 | /*! 53 | * Returns the NDC instance. 54 | */ 55 | static NDC *instance(); 56 | 57 | static QString pop(); 58 | static void push(const QString &message); 59 | static void setMaxDepth(int maxDepth); 60 | static QString peek(); 61 | 62 | private: 63 | QThreadStorage *> mStack; 64 | }; 65 | 66 | inline NDC::NDC() 67 | {} 68 | 69 | } // namespace Log4Qt 70 | 71 | #endif // LOG4QT_NDC_H 72 | -------------------------------------------------------------------------------- /src/log4qt/patternlayout.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "patternlayout.h" 22 | 23 | #include "helpers/patternformatter.h" 24 | #include "loggingevent.h" 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | 30 | PatternLayout::PatternLayout(QObject *parent) : 31 | Layout(parent) 32 | { 33 | setConversionPattern(DEFAULT_CONVERSION_PATTERN); 34 | } 35 | 36 | PatternLayout::PatternLayout(const QString &pattern, 37 | QObject *parent) : 38 | Layout(parent) 39 | { 40 | setConversionPattern(pattern); 41 | } 42 | 43 | PatternLayout::PatternLayout(ConversionPattern conversionPattern, 44 | QObject *parent) : 45 | Layout(parent) 46 | { 47 | setConversionPattern(conversionPattern); 48 | } 49 | 50 | void PatternLayout::setConversionPattern(ConversionPattern conversionPattern) 51 | { 52 | switch (conversionPattern) 53 | { 54 | case DEFAULT_CONVERSION_PATTERN: 55 | setConversionPattern(QStringLiteral("%m%n")); 56 | break; 57 | case TTCC_CONVERSION_PATTERN: 58 | setConversionPattern(QStringLiteral("%r [%t] %p %c %x - %m%n")); 59 | break; 60 | default: 61 | Q_ASSERT_X(false, "PatternLayout::setConversionFormat", "Unknown ConversionFormat"); 62 | setConversionPattern(QString()); 63 | } 64 | } 65 | 66 | QString PatternLayout::format(const LoggingEvent &event) 67 | { 68 | Q_ASSERT_X(mPatternFormatter, "PatternLayout::format()", "mpPatternConverter must not be null"); 69 | 70 | return mPatternFormatter->format(event); 71 | } 72 | 73 | void PatternLayout::updatePatternFormatter() 74 | { 75 | mPatternFormatter.reset(new PatternFormatter(mPattern)); 76 | } 77 | 78 | } // namespace Log4Qt 79 | 80 | #include "moc_patternlayout.cpp" 81 | 82 | -------------------------------------------------------------------------------- /src/log4qt/qmllogger.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "qmllogger.h" 22 | 23 | #include "logger.h" 24 | #include "level.h" 25 | 26 | #include 27 | #include 28 | 29 | namespace Log4Qt 30 | { 31 | 32 | QmlLogger::QmlLogger(QObject *parent) : 33 | QObject(parent) 34 | , mContext(QStringLiteral("Qml")) 35 | , mLogger(nullptr) 36 | { 37 | } 38 | 39 | void QmlLogger::trace(const QString &message) const 40 | { 41 | logger()->trace(message); 42 | } 43 | 44 | void QmlLogger::debug(const QString &message) const 45 | { 46 | logger()->debug(message); 47 | } 48 | 49 | void QmlLogger::info(const QString &message) const 50 | { 51 | logger()->info(message); 52 | } 53 | 54 | void QmlLogger::error(const QString &message) const 55 | { 56 | logger()->error(message); 57 | } 58 | 59 | void QmlLogger::fatal(const QString &message) const 60 | { 61 | logger()->fatal(message); 62 | } 63 | 64 | void QmlLogger::log(Level level, const QString &message) const 65 | { 66 | Log4Qt::Level loglevel(static_cast(level)); 67 | logger()->log(loglevel, message); 68 | } 69 | 70 | QString QmlLogger::name() const 71 | { 72 | return mName; 73 | } 74 | 75 | void QmlLogger::setName(const QString &name) 76 | { 77 | if (mName != name) 78 | { 79 | mName = name; 80 | Q_EMIT nameChanged(name); 81 | } 82 | } 83 | 84 | QString QmlLogger::context() const 85 | { 86 | return mContext; 87 | } 88 | 89 | QmlLogger::Level QmlLogger::level() const 90 | { 91 | return static_cast(mLogger->level().toInt()); 92 | } 93 | 94 | void QmlLogger::setContext(const QString &context) 95 | { 96 | if (mContext != context) 97 | { 98 | mContext = context; 99 | Q_EMIT contextChanged(context); 100 | } 101 | } 102 | 103 | void QmlLogger::setLevel(QmlLogger::Level level) 104 | { 105 | if (this->level() != level) 106 | { 107 | mLogger->setLevel(Log4Qt::Level(static_cast(level))); 108 | Q_EMIT levelChanged(level); 109 | } 110 | } 111 | 112 | QString QmlLogger::loggename() const 113 | { 114 | if (mName.isEmpty() && (parent() != nullptr)) 115 | mName = parent()->objectName(); 116 | 117 | if (!mContext.isEmpty()) 118 | return mContext % "." % mName; 119 | return mName; 120 | } 121 | 122 | Logger *QmlLogger::logger() const 123 | { 124 | if (mLogger == nullptr) 125 | mLogger = Log4Qt::Logger::logger(loggename()); 126 | 127 | return mLogger; 128 | } 129 | 130 | } 131 | 132 | #include "moc_qmllogger.cpp" 133 | -------------------------------------------------------------------------------- /src/log4qt/signalappender.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "signalappender.h" 22 | 23 | #include "layout.h" 24 | 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | SignalAppender::SignalAppender(QObject *parent) : 30 | AppenderSkeleton(parent) 31 | { 32 | } 33 | 34 | void SignalAppender::append(const LoggingEvent &event) 35 | { 36 | QString message(layout()->format(event)); 37 | Q_EMIT appended(message); 38 | } 39 | 40 | } 41 | 42 | #include "moc_signalappender.cpp" 43 | -------------------------------------------------------------------------------- /src/log4qt/signalappender.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef SIGNALAPPENDER_H 22 | #define SIGNALAPPENDER_H 23 | 24 | #include "appenderskeleton.h" 25 | #include "loggingevent.h" 26 | 27 | namespace Log4Qt 28 | { 29 | 30 | /*! 31 | * \ingroup log4qt 32 | * @class SignalAppender signalappender.h "src/kernel/components/signalappender.h" 33 | */ 34 | class LOG4QT_EXPORT SignalAppender : public AppenderSkeleton 35 | { 36 | Q_OBJECT 37 | public: 38 | explicit SignalAppender(QObject *parent = nullptr); 39 | 40 | bool requiresLayout() const override; 41 | 42 | protected: 43 | void append(const Log4Qt::LoggingEvent &event) override; 44 | 45 | Q_SIGNALS: 46 | /*! 47 | * @param message 48 | */ 49 | void appended(const QString &message); 50 | 51 | }; 52 | 53 | inline bool SignalAppender::requiresLayout() const 54 | { 55 | return true; 56 | } 57 | 58 | } // namespace Log4Qt 59 | 60 | #endif // SIGNALAPPENDER_H 61 | -------------------------------------------------------------------------------- /src/log4qt/simplelayout.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "simplelayout.h" 22 | 23 | #include "loggingevent.h" 24 | 25 | namespace Log4Qt 26 | { 27 | 28 | QString SimpleLayout::format(const LoggingEvent &event) 29 | { 30 | if (mShowLevel) 31 | return event.level().toString() + QStringLiteral(" - ") + event.message() + Layout::endOfLine(); 32 | 33 | return event.message() + Layout::endOfLine(); 34 | } 35 | 36 | 37 | } // namespace Log4Qt 38 | 39 | #include "moc_simplelayout.cpp" 40 | -------------------------------------------------------------------------------- /src/log4qt/simplelayout.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_SIMPLELAYOUT_H 22 | #define LOG4QT_SIMPLELAYOUT_H 23 | 24 | #include "layout.h" 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | /*! 30 | * \brief The class SimpleLayout outputs the level and message of a logging 31 | * event. 32 | * 33 | * \note The ownership and lifetime of objects of this class are managed. 34 | * See \ref Ownership "Object ownership" for more details. 35 | */ 36 | class LOG4QT_EXPORT SimpleLayout : public Layout 37 | { 38 | Q_OBJECT 39 | Q_PROPERTY(bool showLevel READ showLevel WRITE setShowLevel) 40 | 41 | public: 42 | SimpleLayout(QObject *parent = nullptr); 43 | 44 | private: 45 | Q_DISABLE_COPY_MOVE(SimpleLayout) 46 | bool mShowLevel; 47 | 48 | public: 49 | bool showLevel() const; 50 | void setShowLevel(bool show); 51 | 52 | QString format(const LoggingEvent &event) override; 53 | 54 | }; 55 | 56 | inline SimpleLayout::SimpleLayout(QObject *parent) 57 | : Layout(parent) 58 | , mShowLevel{true} 59 | { 60 | } 61 | 62 | inline bool SimpleLayout::showLevel() const 63 | { 64 | return mShowLevel; 65 | } 66 | 67 | inline void SimpleLayout::setShowLevel(bool show) 68 | { 69 | mShowLevel = show; 70 | } 71 | 72 | } // namespace Log4Qt 73 | 74 | #endif // LOG4QT_SIMPLELAYOUT_H 75 | -------------------------------------------------------------------------------- /src/log4qt/simpletimelayout.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "simpletimelayout.h" 22 | 23 | #include "loggingevent.h" 24 | #include "helpers/datetime.h" 25 | 26 | 27 | namespace Log4Qt 28 | { 29 | 30 | QString SimpleTimeLayout::format(const LoggingEvent &event) 31 | { 32 | return DateTime::fromMSecsSinceEpoch(event.timeStamp()).toString(QStringLiteral("dd.MM.yyyy hh:mm")) 33 | + QStringLiteral("[") + event.threadName() + QStringLiteral("]") 34 | + QStringLiteral(" ") + event.level().toString() 35 | + QStringLiteral(" ") + event.loggename() 36 | + QStringLiteral(" - ") + event.message() + Layout::endOfLine(); 37 | } 38 | 39 | 40 | } // namespace Log4Qt 41 | 42 | #include "moc_simpletimelayout.cpp" 43 | -------------------------------------------------------------------------------- /src/log4qt/simpletimelayout.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_SIMPLETIMELAYOUT_H 22 | #define LOG4QT_SIMPLETIMELAYOUT_H 23 | 24 | #include "layout.h" 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | /*! 30 | * \brief The class SimpleTimeLayout outputs the time, logger name, thread, level and message of a logging 31 | * event. 32 | * 33 | * \note The ownership and lifetime of objects of this class are managed. 34 | * See \ref Ownership "Object ownership" for more details. 35 | */ 36 | class LOG4QT_EXPORT SimpleTimeLayout : public Layout 37 | { 38 | Q_OBJECT 39 | 40 | public: 41 | SimpleTimeLayout(QObject *parent = nullptr); 42 | 43 | private: 44 | Q_DISABLE_COPY_MOVE(SimpleTimeLayout) 45 | 46 | public: 47 | QString format(const LoggingEvent &event) override; 48 | }; 49 | 50 | inline SimpleTimeLayout::SimpleTimeLayout(QObject *parent) : 51 | Layout(parent) 52 | {} 53 | 54 | } // namespace Log4Qt 55 | 56 | #endif // LOG4QT_SIMPLETIMELAYOUT_H 57 | -------------------------------------------------------------------------------- /src/log4qt/spi/filter.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "spi/filter.h" 22 | 23 | namespace Log4Qt 24 | { 25 | 26 | Filter::Filter(QObject *parent) : 27 | QObject(parent) 28 | {} 29 | 30 | Filter::~Filter() = default; 31 | 32 | FilterSharedPtr Filter::next() const 33 | { 34 | return mNext; 35 | } 36 | 37 | void Filter::setNext(const FilterSharedPtr &filter) 38 | { 39 | mNext = filter; 40 | } 41 | 42 | void Filter::activateOptions() 43 | {} 44 | 45 | } // namespace Log4Qt 46 | 47 | #include "moc_filter.cpp" 48 | -------------------------------------------------------------------------------- /src/log4qt/spi/filter.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_FILTER_H 22 | #define LOG4QT_FILTER_H 23 | 24 | #include "log4qt/log4qt.h" 25 | #include "log4qt/log4qtsharedptr.h" 26 | 27 | #include 28 | 29 | namespace Log4Qt 30 | { 31 | 32 | class LoggingEvent; 33 | class Filter; 34 | 35 | using FilterSharedPtr = Log4QtSharedPtr; 36 | 37 | /*! 38 | * \brief The class Filter is the base class for all filters. 39 | * 40 | * \note The ownership and lifetime of objects of this class are managed. 41 | * See \ref Ownership "Object ownership" for more details. 42 | */ 43 | class LOG4QT_EXPORT Filter : public QObject 44 | { 45 | Q_OBJECT 46 | 47 | /*! 48 | * The property holds the next filter of this filter. 49 | * 50 | * The default is 0 for no next filter. 51 | * 52 | * 53 | * 54 | * \sa next(), setNext() 55 | */ 56 | Q_PROPERTY(FilterSharedPtr next READ next WRITE setNext) 57 | 58 | public: 59 | enum Decision 60 | { 61 | ACCEPT, /*!< The log event must be logged immediately without consulting 62 | with the remaining filters, if any, in the chain. */ 63 | DENY, /*!< The log event must be dropped immediately without consulting 64 | with the remaining filters, if any, in the chain. */ 65 | NEUTRAL /*!< This filter is neutral with respect to the log event. The 66 | remaining filters, if any, should be consulted for a final decision. */ 67 | }; 68 | Q_ENUM(Decision) 69 | 70 | public: 71 | Filter(QObject *parent = nullptr); 72 | virtual ~Filter(); 73 | 74 | FilterSharedPtr next() const; 75 | void setNext(const FilterSharedPtr &filter); 76 | 77 | virtual void activateOptions(); 78 | virtual Decision decide(const LoggingEvent &event) const = 0; 79 | 80 | private: 81 | FilterSharedPtr mNext; 82 | }; 83 | 84 | 85 | } // namespace Log4Qt 86 | 87 | 88 | #endif // LOG4QT_FILTER_H 89 | -------------------------------------------------------------------------------- /src/log4qt/systemlogappender.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef SYSTEMLOGAPPENDER_H 22 | #define SYSTEMLOGAPPENDER_H 23 | 24 | #include "appenderskeleton.h" 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | /*! 30 | * \brief The class SystemLogAppender appends log events to a Event Log under win* 31 | * and to syslog under *nix. 32 | * 33 | * \note All the functions declared in this class are thread-safe. 34 | * 35 | * \note The ownership and lifetime of objects of this class are managed. 36 | * See \ref Ownership "Object ownership" for more details. 37 | */ 38 | class LOG4QT_EXPORT SystemLogAppender: public AppenderSkeleton 39 | { 40 | Q_OBJECT 41 | 42 | /** 43 | * The property holds the port used by the telenet appender. 44 | * 45 | * The default is QCoreApplication::applicationName() 46 | * 47 | * \sa serviceName(), setServiceName() 48 | */ 49 | Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName) 50 | 51 | public: 52 | explicit SystemLogAppender(QObject *parent = nullptr); 53 | ~SystemLogAppender() override; 54 | 55 | bool requiresLayout() const override; 56 | QString serviceName() const; 57 | void setServiceName(const QString &serviceName); 58 | 59 | protected: 60 | void append(const Log4Qt::LoggingEvent &event) override; 61 | 62 | QString mServiceName; 63 | char *ident; 64 | }; 65 | 66 | inline bool SystemLogAppender::requiresLayout() const 67 | { 68 | return true; 69 | } 70 | 71 | } 72 | 73 | #endif //#ifndef SYSTEMLOGAPPENDER_H 74 | -------------------------------------------------------------------------------- /src/log4qt/ttcclayout.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "ttcclayout.h" 22 | 23 | #include "helpers/datetime.h" 24 | #include "helpers/patternformatter.h" 25 | #include "logger.h" 26 | #include "loggingevent.h" 27 | 28 | #include 29 | 30 | namespace Log4Qt 31 | { 32 | 33 | TTCCLayout::TTCCLayout(QObject *parent) : 34 | Layout(parent), 35 | mCategoryPrefixing(true), 36 | mContextPrinting(true), 37 | mThreadPrinting(true) 38 | { 39 | setDateFormat(RELATIVE); 40 | } 41 | 42 | TTCCLayout::TTCCLayout(const QString &dateFormat, 43 | QObject *parent) : 44 | Layout(parent), 45 | mCategoryPrefixing(true), 46 | mContextPrinting(true), 47 | mThreadPrinting(true) 48 | { 49 | setDateFormat(dateFormat); 50 | } 51 | 52 | TTCCLayout::TTCCLayout(DateFormat dateFormat, 53 | QObject *parent) : 54 | Layout(parent), 55 | mCategoryPrefixing(true), 56 | mContextPrinting(true), 57 | mThreadPrinting(true) 58 | { 59 | setDateFormat(dateFormat); 60 | } 61 | 62 | void TTCCLayout::setDateFormat(DateFormat dateFormat) 63 | { 64 | switch (dateFormat) 65 | { 66 | case NONE: 67 | setDateFormat(QStringLiteral("NONE")); 68 | break; 69 | case ISO8601: 70 | setDateFormat(QStringLiteral("ISO8601")); 71 | break; 72 | case ABSOLUTE: 73 | setDateFormat(QStringLiteral("ABSOLUTE")); 74 | break; 75 | case DATE: 76 | setDateFormat(QStringLiteral("DATE")); 77 | break; 78 | case RELATIVE: 79 | setDateFormat(QStringLiteral("RELATIVE")); 80 | break; 81 | default: 82 | Q_ASSERT_X(false, "TTCCLayout::setDateFormat", "Unknown DateFormat"); 83 | setDateFormat(QString()); 84 | } 85 | } 86 | 87 | 88 | QString TTCCLayout::format(const LoggingEvent &event) 89 | { 90 | Q_ASSERT_X(mPatternFormatter, "TTCCLayout::format()", "mpPatternConverter must not be null"); 91 | 92 | return mPatternFormatter->format(event); 93 | } 94 | 95 | 96 | void TTCCLayout::updatePatternFormatter() 97 | { 98 | QString pattern; 99 | 100 | pattern += QStringLiteral("%d{") + mDateFormat + QStringLiteral("}"); 101 | if (mThreadPrinting) 102 | pattern += QStringLiteral(" [%t]"); 103 | pattern += QStringLiteral(" %-5p"); 104 | if (mCategoryPrefixing) 105 | pattern += QStringLiteral(" %c"); 106 | if (mContextPrinting) 107 | pattern += QStringLiteral(" %x"); 108 | pattern += QStringLiteral(" - %m%n"); 109 | 110 | mPatternFormatter.reset(new PatternFormatter(pattern)); 111 | } 112 | 113 | } // namespace Log4Qt 114 | 115 | #include "moc_ttcclayout.cpp" 116 | -------------------------------------------------------------------------------- /src/log4qt/varia/binaryeventfilter.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "varia/binaryeventfilter.h" 22 | 23 | #include "binaryloggingevent.h" 24 | 25 | namespace Log4Qt 26 | { 27 | 28 | BinaryEventFilter::BinaryEventFilter(QObject *parent) 29 | : Filter(parent) 30 | , mAcceptBinaryEvents{true} 31 | { 32 | } 33 | 34 | Filter::Decision BinaryEventFilter::decide(const LoggingEvent &event) const 35 | { 36 | bool isBinaryEvent = dynamic_cast(&event) != nullptr; 37 | 38 | if (!isBinaryEvent) 39 | return Filter::NEUTRAL; 40 | 41 | if (mAcceptBinaryEvents) 42 | return Filter::ACCEPT; 43 | return Filter::DENY; 44 | } 45 | 46 | } // namespace Log4Qt 47 | 48 | #include "moc_binaryeventfilter.cpp" 49 | -------------------------------------------------------------------------------- /src/log4qt/varia/binaryeventfilter.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_BINARYEVENTFILTER_H 22 | #define LOG4QT_BINARYEVENTFILTER_H 23 | 24 | #include "log4qt/spi/filter.h" 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | class LOG4QT_EXPORT BinaryEventFilter : public Filter 30 | { 31 | Q_OBJECT 32 | Q_PROPERTY(bool acceptBinaryEvents READ acceptBinaryEvents WRITE setAcceptBinaryEvents) 33 | public: 34 | explicit BinaryEventFilter(QObject *parent = nullptr); 35 | 36 | bool acceptBinaryEvents() const; 37 | void setAcceptBinaryEvents(bool accept); 38 | 39 | Decision decide(const LoggingEvent &event) const override; 40 | 41 | private: 42 | bool mAcceptBinaryEvents; 43 | }; 44 | 45 | inline bool BinaryEventFilter::acceptBinaryEvents() const 46 | { 47 | return mAcceptBinaryEvents; 48 | } 49 | 50 | inline void BinaryEventFilter::setAcceptBinaryEvents(bool accept) 51 | { 52 | mAcceptBinaryEvents = accept; 53 | } 54 | 55 | } // namespace Log4Qt 56 | 57 | #endif // LOG4QT_BINARYEVENTFILTER_H 58 | -------------------------------------------------------------------------------- /src/log4qt/varia/debugappender.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "varia/debugappender.h" 22 | 23 | #include "layout.h" 24 | #include "loggingevent.h" 25 | 26 | #ifdef Q_OS_WIN 27 | #include 28 | #endif 29 | 30 | #include 31 | 32 | namespace Log4Qt 33 | { 34 | 35 | DebugAppender::DebugAppender(const LayoutSharedPtr &layout, 36 | QObject *parent) : 37 | AppenderSkeleton(true, layout, parent) 38 | { 39 | } 40 | 41 | bool DebugAppender::requiresLayout() const 42 | { 43 | return true; 44 | } 45 | 46 | void DebugAppender::append(const LoggingEvent &event) 47 | { 48 | Q_ASSERT_X(layout(), "DebugAppender::append()", "Layout must not be null"); 49 | 50 | QString message(layout()->format(event)); 51 | #ifdef Q_OS_WIN 52 | OutputDebugStringW(message.toStdWString().c_str()); 53 | #else 54 | std::cerr << message.toLocal8Bit().constData() << std::endl; 55 | std::cerr << std::flush; 56 | #endif 57 | } 58 | 59 | } // namspace Log4Qt 60 | 61 | #include "moc_debugappender.cpp" 62 | -------------------------------------------------------------------------------- /src/log4qt/varia/debugappender.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_DEBUGAPPENDER_H 22 | #define LOG4QT_DEBUGAPPENDER_H 23 | 24 | #include "log4qt/appenderskeleton.h" 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | /*! 30 | * \brief The class DebugAppender appends logging events to the platform 31 | * specific debug output. 32 | * 33 | * A DebugAppender appends to the Debugger on Windows and to stderr on all 34 | * other systems. 35 | * 36 | * \note All the functions declared in this class are thread-safe. 37 | * 38 | * \note The ownership and lifetime of objects of this class are managed. 39 | * See \ref Ownership "Object ownership" for more details. 40 | */ 41 | class LOG4QT_EXPORT DebugAppender : public AppenderSkeleton 42 | { 43 | Q_OBJECT 44 | 45 | public: 46 | /*! 47 | * Creates a DebugAppender. 48 | */ 49 | DebugAppender(QObject *parent = nullptr); 50 | 51 | /*! 52 | * Creates a DebugAppender with the specified layout \a pLayout 53 | */ 54 | DebugAppender(const LayoutSharedPtr &layout, 55 | QObject *parent = nullptr); 56 | 57 | private: 58 | Q_DISABLE_COPY_MOVE(DebugAppender) 59 | 60 | public: 61 | /*! 62 | * The DebugAppended requires a layout. The function returns true. 63 | * 64 | * \sa setLayout() 65 | */ 66 | bool requiresLayout() const override; 67 | 68 | protected: 69 | /*! 70 | * Appends the specified logging event \a event to the debug output. 71 | * The output is formatted using the appender's layout. 72 | * 73 | * The method is called by the AppenderSkeleton::doAppend() after it 74 | * the entry conditions have been tested and it has been found that the 75 | * logging event needs to be appended. 76 | * 77 | * \sa setLayout(), AppenderSkeleton::doAppend(), checkEntryConditions() 78 | */ 79 | void append(const LoggingEvent &event) override; 80 | 81 | }; 82 | 83 | inline DebugAppender::DebugAppender(QObject *parent) : 84 | AppenderSkeleton(parent) 85 | {} 86 | 87 | 88 | } // namespace Log4Qt 89 | 90 | #endif // LOG4QT_DEBUGAPPENDER_H 91 | -------------------------------------------------------------------------------- /src/log4qt/varia/denyallfilter.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "varia/denyallfilter.h" 22 | 23 | namespace Log4Qt 24 | { 25 | 26 | DenyAllFilter::DenyAllFilter(QObject *parent) : 27 | Filter(parent) 28 | {} 29 | 30 | } // namespace Log4Qt 31 | 32 | #include "moc_denyallfilter.cpp" 33 | -------------------------------------------------------------------------------- /src/log4qt/varia/denyallfilter.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_DENYALLFILTER_H 22 | #define LOG4QT_DENYALLFILTER_H 23 | 24 | #include "log4qt/spi/filter.h" 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | /*! 30 | * \brief The class DenyAllFilter drops all logging events 31 | * 32 | * \note The ownership and lifetime of objects of this class are managed. 33 | * See \ref Ownership "Object ownership" for more details. 34 | */ 35 | class LOG4QT_EXPORT DenyAllFilter : public Filter 36 | { 37 | Q_OBJECT 38 | 39 | public: 40 | DenyAllFilter(QObject *parent = nullptr); 41 | 42 | Decision decide(const LoggingEvent &event) const override 43 | { 44 | Q_UNUSED(&event); 45 | return Filter::DENY; 46 | } 47 | }; 48 | 49 | } // namespace Log4Qt 50 | 51 | #endif // LOG4QT_DENYALLFILTER_H 52 | -------------------------------------------------------------------------------- /src/log4qt/varia/levelmatchfilter.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "varia/levelmatchfilter.h" 22 | 23 | #include "loggingevent.h" 24 | 25 | namespace Log4Qt 26 | { 27 | 28 | LevelMatchFilter::LevelMatchFilter(QObject *parent) : 29 | Filter(parent), 30 | mAcceptOnMatch(true), 31 | mLevelToMatch(Level::NULL_INT) 32 | {} 33 | 34 | Filter::Decision LevelMatchFilter::decide(const LoggingEvent &event) const 35 | { 36 | if (mLevelToMatch == Level::NULL_INT || 37 | event.level() != mLevelToMatch) 38 | return Filter::NEUTRAL; 39 | 40 | if (mAcceptOnMatch) 41 | return Filter::ACCEPT; 42 | return Filter::DENY; 43 | } 44 | 45 | } // namespace Log4Qt 46 | 47 | #include "moc_levelmatchfilter.cpp" 48 | -------------------------------------------------------------------------------- /src/log4qt/varia/levelmatchfilter.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_LEVELMATCHFILTER_H 22 | #define LOG4QT_LEVELMATCHFILTER_H 23 | 24 | #include "log4qt/spi/filter.h" 25 | #include "log4qt/level.h" 26 | 27 | namespace Log4Qt 28 | { 29 | 30 | /*! 31 | * \brief The class LevelMatchFilter allows logging events with a specified 32 | * level. 33 | * 34 | * \note The ownership and lifetime of objects of this class are managed. 35 | * See \ref Ownership "Object ownership" for more details. 36 | */ 37 | class LOG4QT_EXPORT LevelMatchFilter : public Filter 38 | { 39 | Q_OBJECT 40 | 41 | /*! 42 | * The property holds if an event is accpeted on a match. 43 | * 44 | * The default is true. 45 | * 46 | * \sa acceptOnMatch(), setAcceptOnMatch() 47 | */ 48 | Q_PROPERTY(bool acceptOnMatch READ acceptOnMatch WRITE setAcceptOnMatch) 49 | 50 | /*! 51 | * The property holds the level to match for this filter. 52 | * 53 | * The default is Level::NULL_INT. 54 | * 55 | * \sa levelToMatch(), setLevelToMatch() 56 | */ 57 | Q_PROPERTY(Log4Qt::Level levelToMatch READ levelToMatch WRITE setLevelToMatch) 58 | 59 | public: 60 | LevelMatchFilter(QObject *parent = nullptr); 61 | 62 | bool acceptOnMatch() const; 63 | Level levelToMatch() const; 64 | void setAcceptOnMatch(bool accept); 65 | void setLevelToMatch(Level level); 66 | 67 | Decision decide(const LoggingEvent &event) const override; 68 | 69 | private: 70 | bool mAcceptOnMatch; 71 | Level mLevelToMatch; 72 | }; 73 | 74 | inline bool LevelMatchFilter::acceptOnMatch() const 75 | { 76 | return mAcceptOnMatch; 77 | } 78 | 79 | inline Level LevelMatchFilter::levelToMatch() const 80 | { 81 | return mLevelToMatch; 82 | } 83 | 84 | inline void LevelMatchFilter::setAcceptOnMatch(bool accept) 85 | { 86 | mAcceptOnMatch = accept; 87 | } 88 | 89 | inline void LevelMatchFilter::setLevelToMatch(Level level) 90 | { 91 | mLevelToMatch = level; 92 | } 93 | 94 | } // namespace Log4Qt 95 | 96 | #endif // LOG4QT_LEVELMATCHFILTER_H 97 | -------------------------------------------------------------------------------- /src/log4qt/varia/levelrangefilter.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "varia/levelrangefilter.h" 22 | 23 | #include "loggingevent.h" 24 | 25 | namespace Log4Qt 26 | { 27 | 28 | LevelRangeFilter::LevelRangeFilter(QObject *parent) : 29 | Filter(parent), 30 | mAcceptOnMatch(true), 31 | mLevelMin(Level::NULL_INT), 32 | mLevelMax(Level::OFF_INT) 33 | {} 34 | 35 | 36 | Filter::Decision LevelRangeFilter::decide(const LoggingEvent &event) const 37 | { 38 | if (event.level() < mLevelMin) 39 | return Filter::DENY; 40 | 41 | if (event.level() > mLevelMax) 42 | return Filter::DENY; 43 | 44 | if (mAcceptOnMatch) 45 | return Filter::ACCEPT; 46 | return Filter::NEUTRAL; 47 | } 48 | 49 | } // namespace Log4Qt 50 | 51 | #include "moc_levelrangefilter.cpp" 52 | -------------------------------------------------------------------------------- /src/log4qt/varia/levelrangefilter.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_LEVELRANGEFILTER_H 22 | #define LOG4QT_LEVELRANGEFILTER_H 23 | 24 | #include "log4qt/spi/filter.h" 25 | #include "log4qt/level.h" 26 | 27 | namespace Log4Qt 28 | { 29 | 30 | /*! 31 | * \brief The class LevelMatchFilter allows logging events with levels in a 32 | * specified range. 33 | * 34 | * \note The ownership and lifetime of objects of this class are managed. 35 | * See \ref Ownership "Object ownership" for more details. 36 | */ 37 | class LOG4QT_EXPORT LevelRangeFilter : public Filter 38 | { 39 | Q_OBJECT 40 | 41 | /*! 42 | * The property holds if an event is accpeted on a match. 43 | * 44 | * The default is true. 45 | * 46 | * \sa acceptOnMatch(), acceptOnMatch() 47 | */ 48 | Q_PROPERTY(bool acceptOnMatch READ acceptOnMatch WRITE setAcceptOnMatch) 49 | 50 | /*! 51 | * The property holds the maximum level of the range for this filter. 52 | * 53 | * The default is Level::OFF_INT. 54 | * 55 | * \sa levelMax(), setLevelMax() 56 | */ 57 | Q_PROPERTY(Log4Qt::Level levelMax READ levelMax WRITE setLevelMax) 58 | 59 | /*! 60 | * The property holds the minimum level of the range for this filter. 61 | * 62 | * The default is Level::NULL_INT. 63 | * 64 | * \sa levelMin(), setLevelMin() 65 | */ 66 | Q_PROPERTY(Log4Qt::Level levelMin READ levelMin WRITE setLevelMin) 67 | 68 | public: 69 | LevelRangeFilter(QObject *parent = nullptr); 70 | 71 | bool acceptOnMatch() const; 72 | Level levelMax() const; 73 | Level levelMin() const; 74 | void setAcceptOnMatch(bool accept); 75 | void setLevelMax(Level level); 76 | void setLevelMin(Level level); 77 | 78 | Decision decide(const LoggingEvent &event) const override; 79 | 80 | private: 81 | bool mAcceptOnMatch; 82 | Level mLevelMin; 83 | Level mLevelMax; 84 | }; 85 | 86 | inline bool LevelRangeFilter::acceptOnMatch() const 87 | { 88 | return mAcceptOnMatch; 89 | } 90 | 91 | inline Level LevelRangeFilter::levelMax() const 92 | { 93 | return mLevelMax; 94 | } 95 | 96 | inline Level LevelRangeFilter::levelMin() const 97 | { 98 | return mLevelMin; 99 | } 100 | 101 | inline void LevelRangeFilter::setAcceptOnMatch(bool accept) 102 | { 103 | mAcceptOnMatch = accept; 104 | } 105 | 106 | inline void LevelRangeFilter::setLevelMax(Level level) 107 | { 108 | mLevelMax = level; 109 | } 110 | 111 | inline void LevelRangeFilter::setLevelMin(Level level) 112 | { 113 | mLevelMin = level; 114 | } 115 | 116 | } // namespace Log4Qt 117 | 118 | #endif // LOG4QT_LEVELRANGEFILTER_H 119 | -------------------------------------------------------------------------------- /src/log4qt/varia/listappender.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "varia/listappender.h" 22 | 23 | namespace Log4Qt 24 | { 25 | 26 | ListAppender::ListAppender(QObject *parent) : 27 | AppenderSkeleton(parent), 28 | mConfiguratorList(false), 29 | mMaxCount(0) 30 | { 31 | } 32 | 33 | QList ListAppender::list() const 34 | { 35 | QMutexLocker locker(&mObjectGuard); 36 | return mList; 37 | } 38 | 39 | void ListAppender::setMaxCount(int n) 40 | { 41 | QMutexLocker locker(&mObjectGuard); 42 | 43 | if (n < 0) 44 | { 45 | logger()->warn(QStringLiteral("Attempt to set maximum count for appender '%1' to %2. Using zero instead"), name(), n); 46 | n = 0; 47 | } 48 | mMaxCount = n; 49 | ensureMaxCount(); 50 | } 51 | 52 | QList ListAppender::clearList() 53 | { 54 | QMutexLocker locker(&mObjectGuard); 55 | 56 | QList result = mList; 57 | mList.clear(); 58 | return result; 59 | } 60 | 61 | void ListAppender::append(const LoggingEvent &event) 62 | { 63 | if ((mMaxCount <= 0) || (mList.size() < mMaxCount)) 64 | mList << event; 65 | } 66 | 67 | void ListAppender::ensureMaxCount() 68 | { 69 | if (mMaxCount <= 0) 70 | return; 71 | 72 | while (mList.size() > mMaxCount) 73 | mList.removeFirst(); 74 | } 75 | 76 | } // namespace Log4Qt 77 | 78 | #include "moc_listappender.cpp" 79 | -------------------------------------------------------------------------------- /src/log4qt/varia/nullappender.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "varia/nullappender.h" 22 | 23 | #include "layout.h" 24 | #include "loggingevent.h" 25 | 26 | 27 | 28 | namespace Log4Qt 29 | { 30 | 31 | NullAppender::NullAppender(QObject *parent) : 32 | AppenderSkeleton(false, parent) 33 | { 34 | } 35 | 36 | NullAppender::~NullAppender() 37 | { 38 | close(); 39 | } 40 | 41 | void NullAppender::append(const LoggingEvent &event) 42 | { 43 | Q_UNUSED(event); 44 | } 45 | 46 | } // namespace Log4Qt 47 | 48 | #include "moc_nullappender.cpp" 49 | -------------------------------------------------------------------------------- /src/log4qt/varia/nullappender.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_NULLAPPENDER_H 22 | #define LOG4QT_NULLAPPENDER_H 23 | 24 | #include "log4qt/appenderskeleton.h" 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | /*! 30 | * \brief The class NullAppender ignores all requests to append. 31 | * 32 | * \note All the functions declared in this class are thread-safe. 33 | * 34 | * \note The ownership and lifetime of objects of this class are managed. See 35 | * \ref Ownership "Object ownership" for more details. 36 | */ 37 | class LOG4QT_EXPORT NullAppender : public AppenderSkeleton 38 | { 39 | Q_OBJECT 40 | 41 | public: 42 | NullAppender(QObject *parent = nullptr); 43 | ~NullAppender() override; 44 | 45 | public: 46 | bool requiresLayout() const override; 47 | 48 | protected: 49 | void append(const LoggingEvent &event) override; 50 | 51 | private: 52 | Q_DISABLE_COPY_MOVE(NullAppender) 53 | }; 54 | 55 | inline bool NullAppender::requiresLayout() const 56 | { 57 | return false; 58 | } 59 | 60 | } // namespace Log4Qt 61 | 62 | #endif // LOG4QT_NULLAPPENDER_H 63 | -------------------------------------------------------------------------------- /src/log4qt/varia/stringmatchfilter.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "varia/stringmatchfilter.h" 22 | 23 | #include "loggingevent.h" 24 | 25 | namespace Log4Qt 26 | { 27 | 28 | StringMatchFilter::StringMatchFilter(QObject *parent) : 29 | Filter(parent), 30 | mAcceptOnMatch(true), 31 | mStringToMatch(), 32 | mCaseSensitivity(Qt::CaseInsensitive) 33 | {} 34 | 35 | 36 | Filter::Decision StringMatchFilter::decide(const LoggingEvent &event) const 37 | { 38 | if (event.message().isEmpty() || 39 | mStringToMatch.isEmpty() || 40 | !event.message().contains(mStringToMatch,mCaseSensitivity)) 41 | return Filter::NEUTRAL; 42 | 43 | if (mAcceptOnMatch) 44 | return Filter::ACCEPT; 45 | 46 | return Filter::DENY; 47 | } 48 | 49 | } // namespace Log4Qt 50 | 51 | #include "moc_stringmatchfilter.cpp" 52 | -------------------------------------------------------------------------------- /src/log4qt/varia/stringmatchfilter.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_STRINGMATCHFILTER_H 22 | #define LOG4QT_STRINGMATCHFILTER_H 23 | 24 | #include "log4qt/spi/filter.h" 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | /*! 30 | * \brief The class StringMatchFilter allows logging events with a 31 | * specified level. 32 | * 33 | * \note The ownership and lifetime of objects of this class are managed. 34 | * See \ref Ownership "Object ownership" for more details. 35 | */ 36 | class LOG4QT_EXPORT StringMatchFilter : public Filter 37 | { 38 | Q_OBJECT 39 | 40 | /*! 41 | * The property holds if an event is accpeted on a match. 42 | * 43 | * The default is true. 44 | * 45 | * \sa acceptOnMatch(), acceptOnMatch() 46 | */ 47 | Q_PROPERTY(bool acceptOnMatch READ acceptOnMatch WRITE setAcceptOnMatch) 48 | 49 | /*! 50 | * The property holds the string to match for this filter. 51 | * 52 | * \sa stringToMatch(), setStringToMatch() 53 | */ 54 | Q_PROPERTY(QString stringToMatch READ stringToMatch WRITE setStringToMatch) 55 | 56 | public: 57 | StringMatchFilter(QObject *parent = nullptr); 58 | 59 | bool acceptOnMatch() const; 60 | QString stringToMatch() const; 61 | void setAcceptOnMatch(bool accept); 62 | void setStringToMatch(const QString &string, Qt::CaseSensitivity cs = Qt::CaseSensitive); 63 | 64 | Decision decide(const LoggingEvent &event) const override; 65 | 66 | private: 67 | bool mAcceptOnMatch; 68 | QString mStringToMatch; 69 | Qt::CaseSensitivity mCaseSensitivity; 70 | }; 71 | 72 | inline bool StringMatchFilter::acceptOnMatch() const 73 | { 74 | return mAcceptOnMatch; 75 | } 76 | 77 | inline QString StringMatchFilter::stringToMatch() const 78 | { 79 | return mStringToMatch; 80 | } 81 | 82 | inline void StringMatchFilter::setAcceptOnMatch(bool accept) 83 | { 84 | mAcceptOnMatch = accept; 85 | } 86 | 87 | inline void StringMatchFilter::setStringToMatch(const QString &string, Qt::CaseSensitivity cs) 88 | { 89 | mStringToMatch = string; 90 | mCaseSensitivity = cs; 91 | } 92 | 93 | } // namespace Log4Qt 94 | 95 | #endif // LOG4QT_STRINGMATCHFILTER_H 96 | -------------------------------------------------------------------------------- /src/log4qt/wdcappender.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "wdcappender.h" 22 | 23 | #include "layout.h" 24 | #include "loggingevent.h" 25 | 26 | #ifdef Q_OS_WIN 27 | #include 28 | #else 29 | static void OutputDebugString(const wchar_t *lpOutputString) 30 | { 31 | Q_UNUSED(lpOutputString) 32 | } 33 | #endif 34 | 35 | namespace Log4Qt 36 | { 37 | 38 | WDCAppender::WDCAppender(QObject *parent) 39 | : AppenderSkeleton(false, parent) 40 | { 41 | } 42 | 43 | WDCAppender::WDCAppender(const LayoutSharedPtr &layout, QObject *parent) 44 | : AppenderSkeleton(false, layout, parent) 45 | { 46 | } 47 | 48 | bool WDCAppender::requiresLayout() const 49 | { 50 | return true; 51 | } 52 | 53 | void WDCAppender::append(const LoggingEvent &event) 54 | { 55 | Q_ASSERT_X(layout(), "WDCAppender::append()", "Layout must not be null"); 56 | 57 | QString message(layout()->format(event)); 58 | 59 | OutputDebugString(message.toStdWString().c_str()); 60 | } 61 | 62 | } 63 | 64 | #include "moc_wdcappender.cpp" 65 | -------------------------------------------------------------------------------- /src/log4qt/wdcappender.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_WDCAPPENDER_H 22 | #define LOG4QT_WDCAPPENDER_H 23 | 24 | #include "appenderskeleton.h" 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | class LOG4QT_EXPORT WDCAppender : public AppenderSkeleton 30 | { 31 | Q_OBJECT 32 | public: 33 | WDCAppender(QObject *parent = nullptr); 34 | WDCAppender(const LayoutSharedPtr &layout, 35 | QObject *parent = nullptr); 36 | 37 | virtual bool requiresLayout() const override; 38 | 39 | protected: 40 | virtual void append(const LoggingEvent &event) override; 41 | 42 | private: 43 | Q_DISABLE_COPY_MOVE(WDCAppender) 44 | }; 45 | 46 | } // namespace Log4Qt 47 | 48 | #endif // LOG4QT_WDCAPPENDER_H 49 | -------------------------------------------------------------------------------- /src/log4qt/xmllayout.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #include "xmllayout.h" 22 | #include "loggingevent.h" 23 | 24 | #include 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | XMLLayout::XMLLayout(QObject *parent) 30 | : Layout(parent) 31 | 32 | { 33 | } 34 | 35 | QString XMLLayout::format(const LoggingEvent &event) 36 | { 37 | QString output; 38 | QXmlStreamWriter writer(&output); 39 | 40 | writer.writeStartElement(QStringLiteral("log4j:event")); 41 | writer.writeAttribute(QStringLiteral("logger"), event.loggename()); 42 | writer.writeAttribute(QStringLiteral("timestamp"), QString::number(event.timeStamp())); 43 | writer.writeAttribute(QStringLiteral("level"), event.level().toString()); 44 | writer.writeAttribute(QStringLiteral("thread"), event.threadName()); 45 | 46 | writer.writeStartElement(QStringLiteral("log4j:message")); 47 | writer.writeCDATA(event.message()); 48 | writer.writeEndElement(); 49 | 50 | if (!event.ndc().isEmpty()) 51 | { 52 | writer.writeStartElement(QStringLiteral("log4j:NDC")); 53 | writer.writeCDATA(event.ndc()); 54 | writer.writeEndElement(); 55 | } 56 | 57 | auto props = event.properties(); 58 | if (!props.isEmpty()) 59 | { 60 | writer.writeStartElement(QStringLiteral("log4j:properties")); 61 | for (auto pos = props.constBegin(); pos != props.constEnd(); ++pos) 62 | { 63 | writer.writeStartElement(QStringLiteral("log4j:data")); 64 | writer.writeAttribute(QStringLiteral("name"), pos.key()); 65 | writer.writeAttribute(QStringLiteral("value"), pos.value()); 66 | writer.writeEndElement(); 67 | } 68 | writer.writeEndElement(); 69 | } 70 | writer.writeEndElement(); 71 | 72 | return output; 73 | } 74 | 75 | } 76 | 77 | #include "moc_xmllayout.cpp" 78 | -------------------------------------------------------------------------------- /src/log4qt/xmllayout.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * 3 | * This file is part of Log4Qt library. 4 | * 5 | * Copyright (C) 2007 - 2020 Log4Qt contributors 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | ******************************************************************************/ 20 | 21 | #ifndef LOG4QT_XMLLAYOUT_H 22 | #define LOG4QT_XMLLAYOUT_H 23 | 24 | #include "layout.h" 25 | 26 | namespace Log4Qt 27 | { 28 | 29 | class LOG4QT_EXPORT XMLLayout : public Layout 30 | { 31 | Q_OBJECT 32 | public: 33 | explicit XMLLayout(QObject *parent = nullptr); 34 | 35 | QString format(const LoggingEvent &event) override; 36 | 37 | private: 38 | Q_DISABLE_COPY_MOVE(XMLLayout) 39 | }; 40 | 41 | } 42 | 43 | #endif // LOG4QT_XMLLAYOUT_H 44 | 45 | -------------------------------------------------------------------------------- /src/src.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | SUBDIRS += log4qt 4 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(binaryloggertest) 2 | add_subdirectory(dailyfileappendertest) 3 | add_subdirectory(log4qttest) 4 | add_subdirectory(filewatcher) 5 | -------------------------------------------------------------------------------- /tests/binaryloggertest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Test REQUIRED) 2 | 3 | set(blt_SOURCES 4 | atscopeexit.h 5 | binaryloggertest.cpp 6 | elementsinarray.h 7 | logging.cpp 8 | logging.h 9 | testappender.cpp 10 | testappender.h 11 | ) 12 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 13 | add_executable(binaryloggertest ${blt_SOURCES}) 14 | target_link_libraries(binaryloggertest log4qt Qt${QT_VERSION_MAJOR}::Test) 15 | 16 | add_test(NAME binaryloggertest COMMAND $) 17 | -------------------------------------------------------------------------------- /tests/binaryloggertest/atscopeexit.h: -------------------------------------------------------------------------------- 1 | #ifndef ATSCOPEEXIT_H 2 | #define ATSCOPEEXIT_H 3 | 4 | #include 5 | 6 | /*! 7 | * \brief The AtScopeExit class provides a facility to execute a callable at scope exit 8 | * If you want to use a member function as callable, use std::bind 9 | * \code 10 | * { 11 | * auto e1 = createScopeExitGuard([]{doSomeCleanupHere();}); 12 | * auto e2 = createScopeExitGuard(doSomeCleanupHere); 13 | * auto e3 = createScopeExitGuard(std::bind(&MyClass::cleanup, this)); 14 | * auto e4 = createScopeExitGuard(MyFunctor{}); 15 | * } 16 | * \endcode 17 | */ 18 | template 19 | class AtScopeExit 20 | { 21 | public: 22 | AtScopeExit(Callable callable) 23 | : callee(callable) 24 | , valid{true} 25 | { 26 | } 27 | 28 | ~AtScopeExit() 29 | { 30 | if (valid) 31 | callee(); 32 | } 33 | 34 | AtScopeExit(const AtScopeExit &other) = delete; 35 | AtScopeExit &operator=(const AtScopeExit &other) = delete; 36 | AtScopeExit(AtScopeExit &&other) 37 | : callee{std::move(other.callee)} 38 | { 39 | other.valid = false; 40 | } 41 | 42 | AtScopeExit &operator=(AtScopeExit &&other) 43 | { 44 | if (this != &other) 45 | { 46 | callee = std::move(other.callee); 47 | valid = true; 48 | other.valid = false; 49 | } 50 | return *this; 51 | } 52 | 53 | private: 54 | Callable callee; 55 | bool valid; 56 | }; 57 | 58 | template 59 | AtScopeExit createScopeExitGuard(Callable callable) 60 | { 61 | return AtScopeExit(callable); 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /tests/binaryloggertest/binaryloggertest.pro: -------------------------------------------------------------------------------- 1 | include(../tests.pri) 2 | 3 | QT += core testlib network 4 | QT -= gui 5 | 6 | TARGET = binaryloggertest 7 | TEMPLATE = app 8 | 9 | HEADERS += \ 10 | testappender.h \ 11 | elementsinarray.h \ 12 | atscopeexit.h \ 13 | 14 | SOURCES += binaryloggertest.cpp \ 15 | testappender.cpp 16 | 17 | DESTDIR=../../bin 18 | 19 | LIBS += -L../../bin/ \ 20 | -llog4qt 21 | 22 | INCLUDEPATH += ../../src 23 | -------------------------------------------------------------------------------- /tests/binaryloggertest/elementsinarray.h: -------------------------------------------------------------------------------- 1 | #ifndef ELEMENTSINARRAY_H 2 | #define ELEMENTSINARRAY_H 3 | 4 | template 5 | size_t elementsInArray(T (&)[N] ) 6 | { 7 | return N; 8 | } 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /tests/binaryloggertest/logging.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGGING_H 2 | #define LOGGING_H 3 | 4 | #include 5 | 6 | class QByteArray; 7 | class QVariant; 8 | 9 | class Logging 10 | { 11 | public: 12 | static QString createDumpString(const QByteArray &data, const bool withCaption = true); 13 | static QString toString(const QVariant &value); 14 | static QString indentString(const QString &string, const QStringList &indentBrackets); 15 | }; 16 | 17 | #endif // LOGGING_H 18 | -------------------------------------------------------------------------------- /tests/binaryloggertest/testappender.cpp: -------------------------------------------------------------------------------- 1 | #include "testappender.h" 2 | #include 3 | 4 | #include "log4qt/layout.h" 5 | 6 | TestAppender::TestAppender(QObject *parent) 7 | : Log4Qt::AppenderSkeleton(parent) 8 | { 9 | } 10 | 11 | QStringList TestAppender::list() const 12 | { 13 | QMutexLocker locker(&mObjectGuard); 14 | return mMessages; 15 | } 16 | 17 | QStringList TestAppender::clearList() 18 | { 19 | QMutexLocker locker(&mObjectGuard); 20 | QStringList copy(mMessages); 21 | mMessages.clear(); 22 | return copy; 23 | } 24 | 25 | bool TestAppender::requiresLayout() const 26 | { 27 | return true; 28 | } 29 | 30 | void TestAppender::append(const Log4Qt::LoggingEvent &event) 31 | { 32 | Q_ASSERT_X(layout(), "TestAppender::append()", "Layout must not be null"); 33 | mMessages << layout()->format(event); 34 | } 35 | 36 | #include "moc_testappender.cpp" 37 | -------------------------------------------------------------------------------- /tests/binaryloggertest/testappender.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTAPPENDER_H 2 | #define TESTAPPENDER_H 3 | 4 | #include "log4qt/appenderskeleton.h" 5 | 6 | #include 7 | 8 | class TestAppender : public Log4Qt::AppenderSkeleton 9 | { 10 | Q_OBJECT 11 | public: 12 | explicit TestAppender(QObject *parent = nullptr); 13 | TestAppender(const TestAppender &) = delete; 14 | TestAppender &operator=(const TestAppender &) = delete; 15 | 16 | QStringList list() const; 17 | QStringList clearList(); 18 | virtual bool requiresLayout() const override; 19 | 20 | protected: 21 | virtual void append(const Log4Qt::LoggingEvent &event) override; 22 | 23 | private: 24 | QStringList mMessages; 25 | }; 26 | 27 | #endif // TESTAPPENDER_H 28 | -------------------------------------------------------------------------------- /tests/dailyfileappendertest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Test REQUIRED) 2 | 3 | set(TEST_NAME dailyfileappendertest) 4 | 5 | set(dfa_SOURCES 6 | dailyfileappendertest.cpp 7 | ) 8 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 9 | add_executable(${TEST_NAME} ${dfa_SOURCES}) 10 | target_link_libraries(dailyfileappendertest log4qt Qt${QT_VERSION_MAJOR}::Test) 11 | 12 | add_test(NAME ${TEST_NAME} COMMAND $) 13 | -------------------------------------------------------------------------------- /tests/dailyfileappendertest/dailyfileappendertest.pro: -------------------------------------------------------------------------------- 1 | include(../tests.pri) 2 | 3 | QT += core testlib 4 | QT -= gui 5 | 6 | TARGET = dailyfileappendertest 7 | TEMPLATE = app 8 | 9 | SOURCES += dailyfileappendertest.cpp 10 | 11 | DESTDIR=../../bin 12 | 13 | LIBS += -L../../bin/ \ 14 | -llog4qt 15 | 16 | INCLUDEPATH += ../../src 17 | -------------------------------------------------------------------------------- /tests/filewatcher/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Test REQUIRED) 2 | 3 | set(l4qt_SOURCES 4 | tst_filewatchertest.cpp 5 | ) 6 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 7 | add_executable(filewatchertest ${l4qt_SOURCES}) 8 | target_link_libraries(filewatchertest log4qt Qt${QT_VERSION_MAJOR}::Test) 9 | 10 | add_test(NAME filewatchertest COMMAND $) 11 | -------------------------------------------------------------------------------- /tests/filewatcher/filewatcher.pro: -------------------------------------------------------------------------------- 1 | include(../tests.pri) 2 | 3 | QT += core testlib network 4 | QT -= gui 5 | 6 | TARGET = tst_filewatchertest 7 | CONFIG += console 8 | CONFIG -= app_bundle 9 | 10 | TEMPLATE = app 11 | DESTDIR=../../bin 12 | 13 | SOURCES += \ 14 | tst_filewatchertest.cpp 15 | 16 | DEFINES += SRCDIR=\\\"$$PWD/\\\" 17 | 18 | LIBS += -L../../bin/ \ 19 | -llog4qt 20 | 21 | INCLUDEPATH += ../../src 22 | -------------------------------------------------------------------------------- /tests/log4qttest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Test REQUIRED) 2 | 3 | set(l4qt_SOURCES 4 | log4qttest.cpp 5 | log4qttest.h 6 | ) 7 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 8 | add_executable(log4qttest ${l4qt_SOURCES}) 9 | target_link_libraries(log4qttest log4qt Qt${QT_VERSION_MAJOR}::Test) 10 | 11 | add_test(NAME log4qttest COMMAND $) 12 | -------------------------------------------------------------------------------- /tests/log4qttest/log4qttest.pro: -------------------------------------------------------------------------------- 1 | include(../tests.pri) 2 | 3 | TEMPLATE = app 4 | CONFIG += testlib \ 5 | c++14 6 | 7 | QT += core testlib network 8 | QT -= gui 9 | 10 | INCLUDEPATH += ../../src 11 | 12 | HEADERS += log4qttest.h 13 | SOURCES += log4qttest.cpp 14 | 15 | LIBS += -L../../bin \ 16 | -llog4qt 17 | 18 | DESTDIR = ../../bin 19 | -------------------------------------------------------------------------------- /tests/tests.pri: -------------------------------------------------------------------------------- 1 | include (../g++.pri) 2 | include (../build.pri) 3 | 4 | CONFIG += c++14 \ 5 | testcase \ 6 | no_testcase_installs 7 | 8 | mac { 9 | CONFIG -= app_bundle 10 | } 11 | 12 | win32 { 13 | CONFIG += console 14 | } 15 | 16 | DEFINES += QT_DEPRECATED_WARNINGS 17 | 18 | msvc { 19 | QMAKE_CXXFLAGS += -wd4267 20 | } 21 | -------------------------------------------------------------------------------- /tests/tests.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | SUBDIRS += log4qttest \ 4 | binaryloggertest \ 5 | dailyfileappendertest \ 6 | filewatcher 7 | --------------------------------------------------------------------------------