log4cplus is a simple to use C++ logging API providing thread-safe, flexible, and arbitrarily granular control over log management and configuration. It is modelled after the Java log4j API.

Overview

% log4cplus README

Short Description

log4cplus is a simple to use C++17 logging API providing thread--safe, flexible, and arbitrarily granular control over log management and configuration. It is modeled after the Java log4j API.

Latest Project Information

The latest up-to-date information for this project can be found at log4cplus SourceForge project pages or log4cplus wiki on SourceForge. Please submit bugs, patches, feature requests, etc., there, or on GitHub.

Mission statement

The aim of this project is to develop log4j--like logging framework for use in (primarily) C++. One of the major design goals is to avoid huge dependencies (like Boost) in the core functionality and to use standard C++ facilities instead. Where possible, the project takes inspiration from other logging libraries, beside from log4j (e.g., from log4net, log4cxx, log4cpp).

Platform support

log4cplus version 3.0 and beyond require C++17. log4cplus has been ported to and tested on the following platforms:

  • Linux/AMD64 with GCC version 8.3.0 (Ubuntu 8.3.0-6ubuntu1)
  • Linux/AMD64 with Clang version 8.0.0-3 (tags/RELEASE_800/final)
  • Windows/AMD64 with GCC version 4.8.2 (x86_64-posix-seh-rev3, Built by MinGW-W64 project) using CMake build system
  • Windows/AMD64 with GCC version 4.9.2 (tdm64-1) using CMake build system
  • Windows 7 with MS Visual Studio 2015
  • OpenBSD 5.6/AMD64 with GCC version 4.9.0
  • FreeBSD 10.1/i386 with Clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032)
  • NetBSD 6.1.5/AMD64 with GCC version 4.9.1
  • DragonflyBSD 4.0.1/AMD64 with GCC version 4.9.3 20141126 (prerelease) (FreeBSD Ports Collection)
  • OpenIndiana Hipster 2016.10 with GCC version 4.9.4

The testing on the above listed platforms has been done at some point in time with some version of source. Continuous testing is done only on Linux platform offered by Travis CI service.

The oldest Windows version that is supported by 2.x releases is Windows Vista.

The following platforms were supported by the 1.x series of log4cplus. They either do not have a reasonable C++17 capable compiler or have not been checked with log4cplus 3.x, yet:

  • Minix 3.3.0/i386 with Clang version 3.4 (branches/release_34) with --disable-threads
  • Linux/AMD64 with Intel Parallel Studio XE 2015, ICPC version 15.0.1
  • OpenSolaris with -library=stlport4
  • Solaris with -library=stlport4 and with -library=Cstd.
  • Solaris 5.10/Sparc
  • MacOS X 10.8
  • MacOS X 11.4.2
  • HP-UX (hppa2.0w-hp-hpux11.11)
  • Haiku R1 Alpha 4.1
  • AIX 5.3 with IBM XL C/C++ for AIX

Installation instruction

Generic Autotools installation instructions are in INSTALL file. The following are log4cplus specific instructions.

log4cplus uses Git sub-modules. Always use --recurse-submodules option when doing git clone.

Configure script options

--enable-debugging

This option is disabled by default. This option mainly affects GCC builds but it also has some limited effect on non-GCC builds. It turns on debugging information generation, undefines NDEBUG symbol and adds -fstack-check (GCC).

--enable-warnings

This option is enabled by default. It adds platform / compiler dependent warning options to compiler command line.

--enable-so-version

This option is enabled by default. It enables SO version decoration on resulting library file, e.g., the .2.0.0 in liblog4cplus-1.2.so.2.0.0.

--enable-release-version

This option is enabled by default. It enables release version decoration on the resulting library file, e.g., the -1.2 in liblog4cplus-1.2.so.2.0.0.

--enable-symbols-visibility-options

This option is enabled by default. It enables use of compiler and platform specific option for symbols visibility. See also the Visibility page on GCC Wiki.

--enable-profiling

This option is disabled by default. This option adds profiling information generation compiler option -pg to GCC and Sun CC / Solaris Studio builds.

--enable-threads

This option is enabled by default. It turns on detection of necessary compiler and linker flags that enable POSIX threading support.

While this detection usually works well, some platforms still need help with configuration by supplying additional flags to the configure script. One of the know deficiencies is Solaris Studio on Linux. See one of the later note for details.

--enable-tests

This option is enabled by default. It enables compilation of test executables.

--enable-unit-tests

This option is disabled by default. It enables compilation of unit tests along their units. These unit tests then can be executed through unit_tests test executable that is built during compilation.

--enable-implicit-initialization

This option is enabled by default. It enables implicit initialization of log4cplus. When it is turned off, log4cplus has to be explicitly initialized by calling either log4cplus::initialize() or by instantiating log4cplus::Initializer.

--enable-lto

This option is disabled by default. It enables LTO (Link-Time Optimization) builds.

--with-wchar_t-support

This option is enabled by default. When enabled, additional binaries will be built, marked with U suffix in file name and compiled with -DUNICODE=1 flag. In effect, these binaries assume that log4cplus::tchar is wchar_t.

--with-working-locale

This is one of three locale and wchar_tchar conversion related options. It is disabled by default.

It is know to work well with GCC on Linux. Other platforms generally have lesser locale support in their implementations of the C++ standard library. It is known not to work well on any BSDs.

See also docs/unicode.txt.

--with-working-c-locale

This is second of wchar_tchar conversion related options. It is disabled by default.

It is known to work well on most Unix--like platforms, including recent Cygwin.

--with-iconv

This is third of wchar_tchar conversion related options. It is disabled by default.

The conversion using iconv() function always uses "UTF-8" and "WCHAR_T" as source/target encoding. It is known to work well on platforms with GNU iconv. Different implementations of iconv() might not support "WCHAR_T" encoding selector.

Either system provided iconv() or library provided libiconv() are detected and accepted. Also both SUSv3 and GNU iconv() function signatures are accepted.

--with-qt

This option is disabled by default. It enables compilation of a separate shared library (liblog4cplusqt4debugappender) that implements Qt4DebugAppender. It requires Qt4 and pkg-config to be installed.

--with-qt5

This option is disabled by default. It enables compilation of a separate shared library (liblog4cplusqt5debugappender) that implements Qt5DebugAppender. It requires Qt5 and pkg-config to be available.

Notes

Compilation

On Unix--like platforms, log4cplus can be compiled using either autotools based build system or using CMake build system. The autotools based build system is considered to be primary for Unix--like platforms.

On Windows, the primary build system is Visual Studio 2015 solution and projects (msvc14/log4cplus.sln).

MinGW is supported by autotools based build system. CMake build system is supported as well and it should be used to compile log4cplus with older versions of Visual Studio or with less common compiler suites (e.g., Embarcadero, Code::Blocks, etc.).

Cygwin

Cygwin 2.5.x has a problem^pr64697 linking binaries that use language level thread-local storage and share thread-local variables across translation units. To avoid the issue language level thread-local storage is not used on Cygwin and traditional POSIX thread-local storage is used instead.

MinGW and MSVCRT version

log4cplus can use functions like _vsnprintf_s() (Microsoft's secure version of vsnprintf()). MinGW tool--chains (by default) link to the system MSVCRT.DLL. Unfortunately, older systems, like Windows XP, ship with MSVCRT.DLL that lacks these functions. It is possible to compile log4cplus with MinGW tool--chains but without using Microsoft's secure functions by defining __MSVCRT_VERSION__ to value less than 0x900 and vice versa.

$ ../configure CPPFLAGS="-D__MSVCRT_VERSION__=0x700"

Windows and Visual Studio

log4cplus uses C++11 thread and synchronization facilities. The synchronization facilities are implemented in Visual Studio C++ standard library in a way that utilizes global variables. Therefore it is impossible (due to "static initialization order fiasco") to use them outside main(). This issue manifests as a deadlock on exit during destruction of log4cplus' thread pool.

To overcome this limitation,

  • always use log4cplus::Initializer initializer; as the first thing in main();

  • never try to log from static/global objects constructors;

  • never try to log from static/global object destructors.

Defining the log4cplus::Initializer instance as the first thing in main() ensures that log4cplus is initialized. More importantly, it ensures that log4cplus shuts down before the execution leaves the main() function. log4cplus will try to automatically initialize at process startup and/or on DLL load, and will not tear down until all log4cplus:Initializer instances are destroyed.

Windows and rolling file Appenders

On Windows, the standard C++ file streams open files in way that underlying Win32 file HANDLE is not open with FILE_SHARE_DELETE flag. This flag, beside shared delete, allows renaming files that have handles open to them. This issue manifests as error code 13 when the file needs to be rolled over and it is still open by another process.

This is also bug #167 on SourceForge.

Windows and TLS

log4cplus uses thread--local storage (TLS) for NDC, MDC and to optimize use of some temporary objects. On Windows there are two ways to get TLS:

  1. using TlsAlloc(), etc., functions
  2. using __declspec(thread)

While method (2) generates faster code, it has some limitations prior to Windows Vista. If log4cplus.dll is loaded at run time using LoadLibrary() (or as a dependency of such loaded library), then accessing __declspec(thread) variables can cause general protection fault (GPF) errors. This is because Windows prior to Windows Vista do not extend the TLS for libraries loaded at run time using LoadLibrary(). To allow using the best available method, log4cplus enables the method (2) by checking _WIN32_WINNT >= 0x0600 condition, when compiling log4cplus targeted to Windows Vista or later.

Linking on Windows

If you are linking your application with DLL variant of log4cplus, define LOG4CPLUS_BUILD_DLL preprocessor symbol. This changes definition of LOG4CPLUS_EXPORT symbol to __declspec(dllimport).

Android, TLS and CMake

log4cplus uses thread--local storage (TLS, see "Windows and TLS" for details). On the Android platform, when log4cplus is being compiled using the android/android.toolchain.cmake, you might get errors featuring the __emutls symbol:

global-init.cxx:268:46: error: log4cplus::internal::__emutls_t._ZN9log4cplus8internal3ptdE causes a section type conflict with log4cplus::internal::ptd

To work around this issue, invoke CMake with -DANDROID_FUNCTION_LEVEL_LINKING:BOOL=OFF option.

Threads and signals

log4cplus is not safe to be used from asynchronous signals' handlers. This is a property of most threaded programmes in general. If you are going to use log4cplus in threaded application and if you want to use log4cplus from signal handlers then your only option is to block signals in all threads but one that will handle all signals. On POSIX platforms, this is possible using the sigwait() call. log4cplus enables this approach by blocking all signals in any threads created through its threads helpers.

IBM's XL C/C++ compiler

IBM's XL C/C++ compiler executable has many variants. To compile log4cplus with threading support specify one of the compiler variants that support threading using the CXX variable on configure script command line. E.g.:

$ ../configure --enable-threads CXX=xlC_r

AIX reentrancy problem

There appears to be a reentracy problem with AIX 5.3 and xlC 8 which can result into a deadlock condition in some circumstances. It is unknown whether the problem manifests with other versions of either the OS or the compiler, too. The problem was initially reported in a bug report #103.

The core of the problem is that IBM's/xlC's standard C++ IOStreams implementation uses global non recursive lock to protect some of its state. The application in the bug report was trying to do logging using log4cplus from inside overflow() member function of a class derived from std::streambuf class. log4cplus itself uses std::ostringstream. This resulted into an attempt to recursively lock the global non recursive lock and a deadlock.

Solaris / SunOS

Some older version of this operating system might have problems linking log4cplus due to missing __tls_get_addr in their unpatched state.

Solaris Studio

Solaris Studio compilers' default standard C++ library is very non-standard. It seems that it is not conforming enough in, e.g., Sun C++ 5.12 Linux_i386 2011/11/16 (missing std::time_t, etc.), but it works well enough on Solaris with Sun C++ 5.8 2005/10/13. Thus log4cplus adds -library=stlport4 to the CXXFLAGS environment variable, unless a switch matching -library=(stlport4|stdcxx4|Cstd) is already present there. If you want to override the default supplied by log4cplus, just set it into CXXFLAGS on configure script command line.

Solaris Studio supports the __func__ symbol which can be used by log4cplus to record function name in logged events. To enable this feature, add -features=extensions switch to CXXFLAGS for configure script. Subsequently, you will have to add this switch to your application's build flags as well.

Solaris Studio on GNU/Linux

The autotools and our configure.ac combo does not handle Solaris Studio compiler on Linux well enough and needs a little help with configuration of POSIX threads:

$ COMMON_FLAGS="-L/lib/x86_64-linux-gnu/ \
-L/usr/lib/x86_64-linux-gnu/ -mt=yes -O"

$ ../configure --enable-threads=yes \
CC=/opt/solarisstudio12.3/bin/cc \
CXX=/opt/solarisstudio12.3/bin/CC \
CFLAGS="$COMMON_FLAGS" \
CXXFLAGS="$COMMON_FLAGS" \
LDFLAGS="-lpthread"

HP-UX with aCC

It is necessary to turn on C++98 mode of aCC by providing the -AA flag:

$ ../configure --enable-threads=yes CXXFLAGS="-AA"

HP-UX with aCC on IA64

There is a problem on IA64 HP-UX with aCC (HP C/aC++ B3910B A.06.20). The problem manifests as unsatisfied symbols during linking of loggingserver:

ld: Unsatisfied symbol "virtual table of loggingserver::ClientThread" in file loggingserver.o

The problem appears to be a deficiency in aCC and its support of __declspec(dllexport). To work around this issue, add --disable-symbols-visibility-options to configure script command line:

$ ../configure --disable-symbols-visibility-options \
--enable-threads=yes CXXFLAGS="-AA"

Haiku

Haiku is supported with GCC 4+. The default GCC version in Haiku is set to version 2 (based on GCC 2.95.x). To change the default GCC version to version 4, please run setgcc gcc4 command. This is to avoid linking errors like this:

main.cpp:(.text.startup+0x54a): undefined reference to `_Unwind_Resume'

Running the command switches the current GCC version to version 4. This change is permanent and global. See also Haiku ticket #8368.

Qt4 / Win32 / MSVC

In order to use log4cplus in Qt4 programs it is necessary to set following option: Treat WChar_t As Built in Type: No (/Zc:wchar_t-)

Set this option for log4cplus project and Qt4DebugAppender project in MS Visual Studio. Remember to use Unicode versions of log4cplus libraries with Qt. It is also necessary to make clear distinction between debug and release builds of Qt project and log4cplus. Do not use log4cplus release library with debug version of Qt program and vice versa.

For registering Qt4DebugAppender library at runtime, call this function: log4cplus::Qt4DebugAppender::registerAppender()

Add these lines to qmake project file for using log4cplus and Qt4DebugAppender:

INCLUDEPATH += C:\log4cplus\include
win32 {
    CONFIG(debug, debug|release) {
        LIBS += -LC:\log4cplus\msvc14\Win32\bin.Debug_Unicode -llog4cplusUD
        LIBS += -LC:\log4cplus\msvc14\Win32\bin.Debug_Unicode -llog4cplus-Qt4DebugAppender
    } else {
        LIBS += -LC:\log4cplus\msvc14\Win32\bin.Release_Unicode -llog4cplusU
        LIBS += -LC:\log4cplus\msvc14\Win32\bin.Release_Unicode -llog4cplus-Qt4DebugAppender
    }
}

Qt / GCC

You might encounter the following error during compilation with --with-qt option:

qglobal.h:943: error: ISO C++ does not support 'long long'

This is caused by -pedantic option that log4cplus adds to CXXFLAGS when compiling with GCC. To work around this issue, add -Wno-long-long GCC option to CXXFLAGS.

OpenBSD

OpenBSD 5.2 and earlier have a bug in wcsftime() function in handling of %% and %N where N is not a supported formatter. This is fixed in OpenBSD 5.3 and later. This shows as failing timeformat_test when log4cplus is compiled with -DUNICODE in CXXFLAGS.

iOS support

iOS support is based on CMake build. Use the scripts in iOS directory. The iOS.cmake toolchain file was originally taken from ios-cmake project.

To build the library for iOS, being in current folder, perform the steps below. For ARMv7 architecture:

$ ./scripts/cmake_ios_armv7.sh
$ cmake --build ./build_armv7 --config "Release"
$ cmake --build ./build_armv7 --config "Debug"

For i386 architecture:

$ ./scripts/cmake_ios_i386.sh
$ cmake --build ./build_i386 --config "Release"
$ cmake --build ./build_i386 --config "Debug"

Some versions of the iOS and/or its SDK have problems with thread-local storage (TLS) and getting through CMake's environment detection phase. To work around these issues, make these changes:

Edit the iOS.cmake file and add these two lines.

set (CMAKE_CXX_COMPILER_WORKS TRUE)
set (CMAKE_C_COMPILER_WORKS TRUE)

Add these lines. Customize them accordingly:

set(MACOSX_BUNDLE_GUI_IDENTIFIER com.example)
set(CMAKE_MACOSX_BUNDLE YES)
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer")
set(IPHONEOS_ARCHS arm64)

If you have issues with TLS, also comment out these lines:

set(LOG4CPLUS_HAVE_TLS_SUPPORT 1)
set(LOG4CPLUS_THREAD_LOCAL_VAR "__thread")

LOG4CPLUS_*_FMT() and UNICODE

Beware, the %s specifier does not work the same way on Unix--like platforms as it does on Windows with Visual Studio. With Visual Studio the %s specifier changes its meaning conveniently by printing wchar_t string when used with wprintf() and char strings when used with printf(). On the other hand, Unix--like platforms keeps the meaning of printing char strings when used with both wprintf() and printf(). It is necessary to use %ls (C99) specifier or %S (SUSv2) specifier to print wchar_t strings on Unix--like platforms.

The common ground for both platforms appears to be use of %ls and wchar_t string to print strings with unmodified formatting string argument on both Unix--like platforms and Windows. The conversion of wchar_t back to char then depends on C locale.

Unsupported compilers and platforms

log4cplus does not support too old or broken C++ compilers. Since log4cplus version 3.0.0, it means it does not support any platform or compiler without decent C++17 support.

  • Visual Studio prior to 2015
  • GCC prior to 4.8

Bug reporting instructions

For successful resolution of reported bugs, it is necessary to provide enough information:

  • log4cplus

    • What is the exact release version or Git branch and revision?
    • What is the build system that you are building log4cplus with (Autotools, Visual Studio solution and its version, CMake).
    • Autotools -- Provide configure script parameters and environment variables, attach generated config.log and defines.hxx files.
    • CMake -- Provide build configuration (Release, Debug, RelWithDebInfo) and non--default CMAKE_* variables values.
    • Visual Studio -- Provide project configuration (Release, Release_Unicode, Debug, Debug_Unicode) and Visual Studio version.
    • Provide target OS and CPU. In case of MinGW, provide its exact compiler distribution -- TDM? Nuwen? Other?
  • log4cplus client application

    • Are you using shared library log4cplus or as static library log4cplus?
    • Is log4cplus linked into an executable or into a shared library (DLL or SO)?
    • If log4cplus is linked into a shared library, is this library loaded dynamically or not?
    • What library file you are linking your application with -- log4cplus.lib, log4cplusUSD.lib, liblog4cplus.dll.a, etc., on Windows?
    • Is your application is using Unicode/wchar_t or not?
    • Provide any error messages.
    • Provide stack trace.
    • Provide log4cplus properties/configuration files.
    • Provide a self--contained test case, if possible.

License

This library is licensed under the Apache Public License 2.0 and two clause BSD license. Please read the included LICENSE file for details.

Contributions

log4cplus (bug tracker, files, wiki) is hosted on SourceForge, except for log4cplus source, which is hosted on GitHub. This allows the project to integrate with Travis CI service offered by GitHub.

Patches

Anybody can contribute to log4cplus development. If you are contributing a source code change, use a reasonable form: a merge request of a Git branch or a patch file attached to a ticket in Bugs tracker or sent to log4cplus-devel mailing list. Unless it is obvious, always state what branch or release tarball is your patch based upon.

Formatting

Please use common sense. Follow the style of surrounding code. You can use the following Emacs style that is based on Microsoft's style as a guide line:

;; Custom MS like indentation style.
(c-add-style "microsoft"
             '("stroustrup"
               (c-offsets-alist
                (innamespace . -)
                (inline-open . 0)
                (inher-cont . c-lineup-multi-inher)
                (arglist-cont-nonempty . +)
                (template-args-cont . +))))

Tools

Build system

log4cplus supports multiple build systems (GNU Autoconf/Automake/Libtool aka Autotools, CMake and Visual Studio solution and project files).

Autotools is considered the primary build system on Unix--like platforms. However, CMake should still be usable on Unix--like platforms as well.

On Windows, it depends on compiler and tool-chain that you want to use. When using Visual Studio, use Visual Studio solution and project files. However, CMake build system should still work and produce useful results. When using some form of MinGW64 tool-chain, the CMake build system is considered primary and the Autotools based build system is unsupported. Use the MinGW Makefiles option and build with mingw-make (or similar). The MSYS Makefiles option is untested and unsupported.

Autotools

The Makefile.am files for this build systems are hand written. Some of them, however, are generated from Makefile.am.tpl and Makefile.am.def by GNU Autogen. This is to make adding new files to the source easier.

To regenerate Makefile.am files, configure script, testsuite script or any other part of the Autotools build system, use the scripts/doautoreconf.sh script from source root directory. It will invoke all the necessary tools in the correct order.

log4cplus closely follows Autoconf's, Automake's and Libtool's development and its master branch files are always generated using the latest available version of the tools.

Issues
  • mingw32 build not working

    mingw32 build not working

    I am trying to build on mingw32 and it appears that the Fls* functions aren't available in mingw32. Version 1.2.0 worked just fine on mingw32.

    This is with version 2.0.0-rc1.

    libtool: compile:  g++ -DHAVE_CONFIG_H -I./include -I./threadpool -I./include -I./catch/single_include -DCATCH_CONFIG_PREFIX_ALL=1 -DNDEBUG -DINSIDE_LOG4CPLUS -D_GNU_SOURCE=1 -U__STRICT_ANSI__ -DWIN32 -D_WIN32 -DMINGW_HAS_SECURE_API=1 -D_REENTRANT -DUNICODE -D_UNICODE -std=gnu++11 -Wall -fdiagnostics-show-caret -ftrack-macro-expansion -fdiagnostics-color=auto -Wextra -pedantic -Wstrict-aliasing -Wstrict-overflow -Woverloaded-virtual -Wundef -Wshadow -Wformat -Wnoexcept -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wno-variadic-macros -O2 -fvisibility=hidden -MT src/liblog4cplus_la-appender.lo -MD -MP -MF src/.deps/liblog4cplus_la-appender.Tpo -c src/appender.cxx  -DDLL_EXPORT -DPIC -o src/.libs/liblog4cplus_la-appender.o
    In file included from ./include/log4cplus/internal/internal.h:59:0,
                     from src/appender.cxx:29:
    ./include/log4cplus/thread/impl/tls.h: In function 'log4cplus::thread::impl::tls_key_type log4cplus::thread::impl::tls_init(log4cplus::thread::impl::tls_init_cleanup_func_type)':
    ./include/log4cplus/thread/impl/tls.h:119:45: error: 'FlsAlloc' was not declared in this scope
         DWORD const slot = FlsAlloc (cleanupfunc);
                                                 ^
    ./include/log4cplus/thread/impl/tls.h: In function 'void* log4cplus::thread::impl::tls_get_value(log4cplus::thread::impl::tls_key_type)':
    ./include/log4cplus/thread/impl/tls.h:132:26: error: 'FlsGetValue' was not declared in this scope
         return FlsGetValue (k);
                              ^
    ./include/log4cplus/thread/impl/tls.h: In function 'void log4cplus::thread::impl::tls_set_value(log4cplus::thread::impl::tls_key_type, log4cplus::thread::impl::tls_value_type)':
    ./include/log4cplus/thread/impl/tls.h:139:26: error: 'FlsSetValue' was not declared in this scope
         FlsSetValue (k, value);
                              ^
    ./include/log4cplus/thread/impl/tls.h: In function 'void log4cplus::thread::impl::tls_cleanup(log4cplus::thread::impl::tls_key_type)':
    ./include/log4cplus/thread/impl/tls.h:146:15: error: 'FlsFree' was not declared in this scope
         FlsFree (k);
                   ^
    ./include/log4cplus/thread/impl/tls.h: In function 'void* log4cplus::thread::impl::tls_get_value(log4cplus::thread::impl::tls_key_type)':
    ./include/log4cplus/thread/impl/tls.h:133:1: warning: control reaches end of non-void function [-Wreturn-type]
     }
     ^
    make[4]: *** [src/liblog4cplus_la-appender.lo] Error 1
    make[4]: Leaving directory `/d/workspace-jnlp/workspace/grex-bps-feature-branches/label/amd64-windows/bps/extlib/source/log4cplus-2.0.0-rc1'
    make[3]: *** [all-recursive] Error 1
    
    opened by jschewebbn 25
  • Application using log4cplus hangs on exit

    Application using log4cplus hangs on exit

    With relatively latest log4cplus version (commit from 04122015) I have encountered unexpected hang in my application upon exit. After two days of digging, I have found that ThreadPool destructor is called twice:

    Breakpoint 6, ~ThreadPool (this=0x6816d0, __in_chrg=<optimized out>)
        at threadpool/ThreadPool.h:178
    178            std::unique_lock<std::mutex> lock(queue_mutex);
    (gdb) bt
    #0  ~ThreadPool (this=0x6816d0, __in_chrg=<optimized out>)
        at threadpool/ThreadPool.h:178
    #1  operator() (this=<optimized out>, __ptr=0x6816d0)
        at /usr/include/c++/5/bits/unique_ptr.h:76
    #2  ~unique_ptr (this=0x6815a8, __in_chrg=<optimized out>)
        at /usr/include/c++/5/bits/unique_ptr.h:236
    #3  ~DefaultContext (this=0x6812b0, __in_chrg=<optimized out>)
        at src/global-init.cxx:127
    #4  log4cplus::(anonymous namespace)::destroy_default_context::~destroy_default_context (
        this=0x7ffff71562d6 <log4cplus::(anonymous namespace)::destroy_default_context_>, __in_chrg=<optimized out>) at src/global-init.cxx:162
    #5  0x00007ffff512a21f in __cxa_finalize (d=0x7ffff7151710)
        at cxa_finalize.c:55
    #6  0x00007ffff6f05873 in __do_global_dtors_aux ()
       from /usr/lib64/liblog4cplus-2.0.so.3
    #7  0x00007fffffffe010 in ?? ()
    #8  0x00007ffff7dea31f in _dl_fini () at dl-fini.c:253
    (gdb) c
    Continuing.
    [Thread 0x7fffeeb44700 (LWP 6151) exited]
    [Thread 0x7fffef345700 (LWP 6150) exited]
    

    As you can see, all worker threads have gone. And the second one:

    Program received signal SIGINT, Interrupt.
    __lll_lock_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:135
    135    2:    movl    %edx, %eax
    (gdb) bt
    #0  __lll_lock_wait ()
        at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:135
    #1  0x00007ffff5a40640 in [email protected]@GLIBC_2.3.2 ()
        at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S:136
    #2  0x00007ffff576abb9 in __gthread_cond_broadcast (__cond=<optimized out>)
        at /usr/src/debug/gcc-5.1.1-20150612/obj-x86_64-alt-linux/x86_64-alt-linux/libstdc++-v3/include/x86_64-alt-linux/bits/gthr-default.h:852
    #3  std::condition_variable::notify_all (this=<optimized out>)
        at ../../../../../libstdc++-v3/src/c++11/condition_variable.cc:73
    #4  0x00007ffff6f1c8f3 in ~ThreadPool (this=0x6826d0, 
        __in_chrg=<optimized out>) at threadpool/ThreadPool.h:180
    #5  operator() (this=<optimized out>, __ptr=0x6826d0)
        at /usr/include/c++/5/bits/unique_ptr.h:76
    #6  reset (__p=0x6826d0, this=<optimized out>)
        at /usr/include/c++/5/bits/unique_ptr.h:344
    #7  log4cplus::shutdownThreadPool () at src/global-init.cxx:282
    #8  0x00007ffff6f2116b in log4cplus::Hierarchy::shutdown (
        [email protected]=0x682358) at src/hierarchy.cxx:244
    #9  0x00007ffff6f21357 in log4cplus::Hierarchy::~Hierarchy (this=0x682358, 
        __in_chrg=<optimized out>) at src/hierarchy.cxx:81
    #10 0x00007ffff6f1cfa5 in ~DefaultContext (this=0x6822b0, 
        __in_chrg=<optimized out>) at src/global-init.cxx:127
    #11 log4cplus::(anonymous namespace)::destroy_default_context::~destroy_default_---Type <return> to continue, or q <return> to quit--- 
    context (this=<optimized out>, __in_chrg=<optimized out>)
        at src/global-init.cxx:162
    #12 0x00007ffff512a21f in __cxa_finalize (d=0x7ffff7151710)
        at cxa_finalize.c:55
    #13 0x00007ffff6f05873 in __do_global_dtors_aux ()
       from /usr/lib64/liblog4cplus-2.0.so.3
    #14 0x00007fffffffdff0 in ?? ()
    #15 0x00007ffff7dea31f in _dl_fini () at dl-fini.c:253
    

    As you can see log4cplus::Hierarchy::shutdown tries to destruct already destructed ThreadPool instance. It happens because of fields order in struct DefaultContext (from global-init.cxx):

    struct DefaultContext
    {
        log4cplus::thread::Mutex console_mutex;
        helpers::LogLog loglog;
        LogLevelManager log_level_manager;
        helpers::Time TTCCLayout_time_base;
        NDC ndc;
        MDC mdc;
        Hierarchy hierarchy;
        spi::AppenderFactoryRegistry appender_factory_registry;
        spi::LayoutFactoryRegistry layout_factory_registry;
        spi::FilterFactoryRegistry filter_factory_registry;
        spi::LocaleFactoryRegistry locale_factory_registry;
    #if ! defined (LOG4CPLUS_SINGLE_THREADED)
        std::unique_ptr<progschj::ThreadPool> thread_pool {new progschj::ThreadPool};
    #endif
    };
    

    thread_pool member is destructed before hierarchy member. As result, we are in trouble. Several solutions possible:

    1. change member order
    2. remove explicit ThreadPool shutdown from Hierarchy
    bug 
    opened by serlin74 23
  • make fails miserably

    make fails miserably

    Hi there :)

    I just wanted to start using log4cplus, because I really need a logging framework and it looks awesome. I need to use it on Windows 10 and I was able to run ./configure, but just with --disable-dependency-tracking because with just ./configure I got an error saying "Something went wrong bootstrapping makefile fragments for automatic dependency tracking. ..." When I now try to make I get this output:

    make
    make  all-recursive
    make[1]: Entering directory `/z/metaproc-research/UIAutomation/log4cplus-2.0.1'
    Making all in include
    make[2]: Entering directory `/z/metaproc-research/UIAutomation/log4cplus-2.0.1/include'
    make[2]: Nothing to be done for `all'.
    make[2]: Leaving directory `/z/metaproc-research/UIAutomation/log4cplus-2.0.1/include'
    make[2]: Entering directory `/z/metaproc-research/UIAutomation/log4cplus-2.0.1'
    g++ -DHAVE_CONFIG_H   -I./include -I./threadpool -I./include -I./catch/single_include -DCATCH_CONFIG_PREFIX_ALL=1 -DNDEBUG -D_GNU_SOURCE=1 -U__STRICT_ANSI__ -DWIN32 -D_WIN32 -DMINGW_HAS_SECURE_API=1 -D_REENTRANT  -g -O2 -Wall -fdiagnostics-show-caret -ftrack-macro-expansion -fdiagnostics-color=auto -Wextra -pedantic -Wstrict-aliasing -Wstrict-overflow -Woverloaded-virtual -Wc++14-compat -Wundef -Wshadow -Wformat -Wnoexcept -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wno-variadic-macros -fvisibility=hidden  -c -o simpleserver/loggingserver.o simpleserver/loggingserver.cxx
    In file included from ./include/log4cplus/configurator.h:27:0,
                     from simpleserver/loggingserver.cxx:24:
    ./include/log4cplus/thread/syncprims.h:75:38: error: 'recursive_mutex' in namespace 'std' does not name a type
         LOG4CPLUS_THREADED (mutable std::recursive_mutex mtx;)
                                          ^
    ./include/log4cplus/config.hxx:177:31: note: in definition of macro 'LOG4CPLUS_THREADED'
     #define LOG4CPLUS_THREADED(x) x
                                   ^
    In file included from ./include/log4cplus/helpers/pointer.h:38:0,
                     from ./include/log4cplus/appender.h:36,
                     from ./include/log4cplus/configurator.h:33,
                     from simpleserver/loggingserver.cxx:24:
    ./include/log4cplus/thread/syncprims.h:95:18: error: 'mutex' in namespace 'std' does not name a type
         mutable std::mutex mtx;
                      ^~~~~
    ./include/log4cplus/thread/syncprims.h:96:18: error: 'condition_variable' in namespace 'std' does not name a type
         mutable std::condition_variable cv;
                      ^~~~~~~~~~~~~~~~~~
    ./include/log4cplus/thread/syncprims.h:121:18: error: 'mutex' in namespace 'std' does not name a type
         mutable std::mutex mtx;
                      ^~~~~
    ./include/log4cplus/thread/syncprims.h:122:18: error: 'condition_variable' in namespace 'std' does not name a type
         mutable std::condition_variable cv;
                      ^~~~~~~~~~~~~~~~~~
    In file included from ./include/log4cplus/configurator.h:33:0,
                     from simpleserver/loggingserver.cxx:24:
    ./include/log4cplus/appender.h:317:14: error: 'mutex' in namespace 'std' does not name a type
             std::mutex in_flight_mutex;
                  ^~~~~
    ./include/log4cplus/appender.h:318:14: error: 'condition_variable' in namespace 'std' does not name a type
             std::condition_variable in_flight_condition;
                  ^~~~~~~~~~~~~~~~~~
    In file included from ./include/log4cplus/socketappender.h:36:0,
                     from simpleserver/loggingserver.cxx:25:
    ./include/log4cplus/thread/threads.h:85:21: error: 'thread' is not a member of 'std'
         std::unique_ptr<std::thread> thread;
                         ^~~
    ./include/log4cplus/thread/threads.h:85:21: note: suggested alternative:
    In file included from ./include/log4cplus/helpers/pointer.h:38:0,
                     from ./include/log4cplus/appender.h:36,
                     from ./include/log4cplus/configurator.h:33,
                     from simpleserver/loggingserver.cxx:24:
    ./include/log4cplus/thread/syncprims.h:38:33: note:   'log4cplus::thread'
     namespace log4cplus { namespace thread {
                                     ^~~~~~
    In file included from ./include/log4cplus/socketappender.h:36:0,
                     from simpleserver/loggingserver.cxx:25:
    ./include/log4cplus/thread/threads.h:85:21: error: 'thread' is not a member of 'std'
         std::unique_ptr<std::thread> thread;
                         ^~~
    ./include/log4cplus/thread/threads.h:85:21: note: suggested alternative:
    In file included from ./include/log4cplus/helpers/pointer.h:38:0,
                     from ./include/log4cplus/appender.h:36,
                     from ./include/log4cplus/configurator.h:33,
                     from simpleserver/loggingserver.cxx:24:
    ./include/log4cplus/thread/syncprims.h:38:33: note:   'log4cplus::thread'
     namespace log4cplus { namespace thread {
                                     ^~~~~~
    In file included from ./include/log4cplus/socketappender.h:36:0,
                     from simpleserver/loggingserver.cxx:25:
    ./include/log4cplus/thread/threads.h:85:32: error: template argument 1 is invalid
         std::unique_ptr<std::thread> thread;
                                    ^
    ./include/log4cplus/thread/threads.h:85:32: error: template argument 2 is invalid
    make[2]: *** [simpleserver/loggingserver.o] Error 1
    make[2]: Leaving directory `/z/metaproc-research/UIAutomation/log4cplus-2.0.1'
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/z/metaproc-research/UIAutomation/log4cplus-2.0.1'
    make: *** [all] Error 2`
    

    I'd really appreciate help, thanks in advance :)

    opened by LinaSchad 22
  • how build a server for appender

    how build a server for appender

    how build a server for appender, like SocketAppender has a test cxx, (tests/socket_test/main.cxx )

    Log4jUdpAppender can? AsyncAppender can ? SysLogAppender can?

    log4cplus provides ?

    bug question 
    opened by hlee13 19
  • `Time DailyRollingFileAppender::calculateNextRolloverTime(const Time& t)` not consider timezone

    `Time DailyRollingFileAppender::calculateNextRolloverTime(const Time& t)` not consider timezone

    if timezone is not UTC, then rollover won't happen at midnight! the bug happens when call round_time... function, as time_t=0 is not midnight.

        case DAILY:
            return round_time_and_add (t, Time (24 * 60 * 60));
    

    fix: use localtime() to get struct tm, manipulate it according to DailyRollingFileSchedule. re-assign it back to Time.

    
    static
    Time
    get_next_rollover_time (DailyRollingFileSchedule sch, const Time& t, bool use_gmtime = false)
    {
        Time result(t.sec(), 0);
    
        struct tm time;
        if (use_gmtime)
            result.gmtime(&time);
        else
            result.localtime(&time);
    
        time.tm_isdst = 0;
        switch (sch)
        {
        case MONTHLY:
            time.tm_mon += 1; //next month
            time.tm_mday = 1; //first day
            time.tm_hour = 0;
            time.tm_min = 0;
            time.tm_sec = 0;
            break;
    
        case WEEKLY:
            time.tm_mday += (7 - time.tm_wday); //next Sunday
            time.tm_hour = 0;
            time.tm_min = 0;
            time.tm_sec = 0;
            break;
    
        case DAILY:
            time.tm_mday += 1; //next day
            time.tm_hour = 0;
            time.tm_min = 0;
            time.tm_sec = 0;
            break;
    
        case TWICE_DAILY:
            if(time.tm_hour >= 12) {
                time.tm_mday += 1; //next day
                time.tm_hour = 0;
            }
            else {
                time.tm_hour = 12;
            }
            time.tm_min = 0;
            time.tm_sec = 0;
            break;
    
        case HOURLY:
            time.tm_min = 0;
            time.tm_sec = 0;
            break;
    
        case MINUTELY:
            time.tm_sec = 0;
            break;
        };
        result.setTime(&time);
    
        return result;
    }
    
    
    bug 
    opened by sangechen 16
  • Log4cplus cannot output Chinese

    Log4cplus cannot output Chinese

    I set up log4cplus Unicode and MTD, just like my project。 I tried

    std::locale::global(std::locale("chs"));
    std::locale lc("chs");
    pRollingFileAppender->imbue(lc);
    

    My environment: vs2015 ,log4cplus-1.2.1; MFC project

    l10n/i18n 
    opened by atu5554 15
  • Question: Plan on 2.0 release?

    Question: Plan on 2.0 release?

    The 1.2x release is not C++11 compatible (build fails when using GCC 5.4 and probably 6.x). It would be nice to have a stable, C++11 compatible version. Is there a 2.0 release (tag) planned soon?

    question 
    opened by biskit-eater 13
  • Crash on exit

    Crash on exit

    Hey, I am trying to get started with log4cplus. I'm using a simple CMake configuration where I'm creating an executable and adding log4cplus.I simply cloned the log4cplus and pulled the submodules. I build log4cplus as a shared library and with /MTd on Win7 x64 with Visual Studio 2013.

    Here is my code

    #include <log4cplus/logger.h>
    #include <log4cplus/loggingmacros.h>
    #include <log4cplus/configurator.h>
    #include <iomanip>
    
    int main()
    {
        log4cplus::initialize();
        log4cplus::BasicConfigurator config;
        config.configure();
    
    
        log4cplus::Logger logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("main"));
        LOG4CPLUS_INFO(logger, "This is a INFO message");
    
    
        return 0;
    }
    

    the executable crashes in Hierarchy::shutdown() in the line at waitUntilEmptyThreadPoolQueue()

    Here is the call stack

    >   log4cplusD.dll!mtx_do_lock(_Mtx_internal_imp_t * * mtx, const xtime * target) Line 49   C++
        log4cplusD.dll!_Mtx_lock(_Mtx_internal_imp_t * * mtx) Line 154  C++
        log4cplusD.dll!std::_Mtx_lockX(_Mtx_internal_imp_t * * _Mtx) Line 68    C++
        log4cplusD.dll!std::_Mutex_base::lock() Line 42 C++
        log4cplusD.dll!std::unique_lock<std::mutex>::unique_lock<std::mutex>(std::mutex & _Mtx) Line 220    C++
        log4cplusD.dll!progschj::ThreadPool::wait_until_empty() Line 192    C++
        log4cplusD.dll!log4cplus::waitUntilEmptyThreadPoolQueue() Line 298  C++
        log4cplusD.dll!log4cplus::Hierarchy::shutdown() Line 244    C++
        log4cplusD.dll!log4cplus::Hierarchy::~Hierarchy() Line 81   C++
        [External Code] 
        log4cplusD.dll!log4cplus::`anonymous namespace'::destroy_default_context::~destroy_default_context() Line 166   C++
        [External Code] 
    

    This issue might be really similar to #102

    question 
    opened by arkenthera 13
  • log4cplus-master and log4cplus-1.2.x When calling a static library, will crash.

    log4cplus-master and log4cplus-1.2.x When calling a static library, will crash.

    log4cplusS.lib
    log4cplusSD.lib
    log4cplusSU.lib
    log4cplusSUD.lib
    

    project use any one of those static library, it will crash.

    crash address: file: log4cplus-1.2.x\src\loglevel.cxx line48

    line45-63

    #define DEF_LL_STRING(_logLevel)                                        \
    static tstring const & _logLevel ## _STRING ()                          \
    {                                                                       \
        static tstring const str (LOG4CPLUS_TEXT (#_logLevel));             \
        return str;                                                         \
    }
    
    DEF_LL_STRING (OFF)
    DEF_LL_STRING (FATAL)
    DEF_LL_STRING (ERROR)
    DEF_LL_STRING (WARN)
    DEF_LL_STRING (INFO)
    DEF_LL_STRING (DEBUG)
    DEF_LL_STRING (TRACE)
    DEF_LL_STRING (ALL)
    DEF_LL_STRING (NOTSET)
    DEF_LL_STRING (UNKNOWN)
    
    #undef DEF_LL_STRING
    

    line117-129

    void
    initializeLogLevelStrings ()
    {
        OFF_STRING();
        FATAL_STRING();
        ERROR_STRING();
        WARN_STRING();
        INFO_STRING();
        DEBUG_STRING();
        TRACE_STRING();
        ALL_STRING();
        NOTSET_STRING();
    }
    
    bug 
    opened by CruiseYoung 13
  • [log4cplus-2.0.0-rc2] memory leak on exit

    [log4cplus-2.0.0-rc2] memory leak on exit

    Hello!

    How to reproduce the issue:

    Make some application with logger. For example: win8x64, release, static linkage with logger. Start the application as win-console application. Stop the application (Ctrl+C).

    The issue description:

    If application going to stop will be called

    log4cplus::`anonymous namespace'::destroy_default_context::~destroy_default_context() Line 168	C++
    

    and

    log4cplus::`anonymous namespace'::alloc_dc() Line 179	C++
    log4cplus::`anonymous namespace'::get_dc(bool alloc) Line 206	C++
    log4cplus::shutdownThreadPool() Line 286	C++
    log4cplus::Initializer::~Initializer() Line 115	C++
    
    

    alloc_dc() will create the context again. This context will not be destroyed. Well, we have memory leak. What do you think about a fix of problem?

    P.s. In debug mode we have assertion (default_context_state is DC_DESTROYED)

    
    alloc_dc ()
    {
        assert (! default_context);
        assert(default_context_state == DC_UNINITIALIZED);    <<<<---
    ...
    
    
    

    Best regards, Yuriy

    bug de-/initialization 
    opened by abronix 12
  • Memory leaks in 1.1.3-RC7, 1.2.0

    Memory leaks in 1.1.3-RC7, 1.2.0

    I've crated some basic app to test base functionality: logging with different levels via async file appender. This app was tested with memory&address sanitizers and valgrind. All tools reported about leaks. Reports attached. Seems this is some kind of degradation. I've been using some time ago 1.1.3-RC2 and there was clean output from sanitizers and valgrind. Reports for 1.1.3-RC7: asan-warnings.txt msan-warnings.txt valgrind-report.txt

    bug 
    opened by malirod 12
  • How to output log file hourly with a friendly file name and clean older files automatically?

    How to output log file hourly with a friendly file name and clean older files automatically?

    I want to split the outputs by hour and with a friendly file name such as a.log.2022-05-01-01, a.log.2022-05-01-02, a.log.2022-05-01-HH, here is my code:

    auto appender = new DailyRollingFileAppender(LOG4CPLUS_STRING_TO_TSTRING(logfile), HOURLY);
    

    But I found that more and more log files will be generated. It seems like log4cplus can only automatically delete old logs such as a.log.MaxBackupIndex, since my output files is not with format as a.log.N.

    How can I set up to automatically clear out expired files?

    opened by doufu3344 1
  • Does not build for Visual Studio 2022

    Does not build for Visual Studio 2022

    Does not build for Visual Studio 2022, 10756 errors Severity Code Description Project File Line Suppression State Error C2039 'basic_string_view': is not a member of 'std' log4cplus ...source\repos\log4cplus\include\log4cplus\tstring.h 42 Version 52dd360e04d0fcdadc87cc1874884d9bbc027f99 OS: Win11 Visual Studio 2022 (17.1.6) Build of solution after retarget to new Visual Studio version

    bug 
    opened by PeterFromSweden 5
  • log4cplus-1.2.2 DailyRollingFileAppender will create an empty file

    log4cplus-1.2.2 DailyRollingFileAppender will create an empty file

    Platform Version:centos7.6

    Property Configure File:

    log4cplus.rootLogger = TRACE, LogFile
    log4cplus.appender.LogFile=log4cplus::DailyRollingFileAppender
    log4cplus.appender.LogFile.Schedule=MINUTELY
    log4cplus.appender.LogFile.File=log/log.log
    log4cplus.appender.LogFile.Threshold=ALL
    log4cplus.appender.LogFile.Append=true
    log4cplus.appender.LogFile.ImmediateFlush=true
    log4cplus.appender.LogFile.CreateDirs=true
    log4cplus.appender.LogFile.layout=log4cplus::PatternLayout
    log4cplus.appender.LogFile.layout.ConversionPattern=%D{%Y-%m-%d %H:%M:%S.%Q} %-5p [%M] - %m %n
    

    Execute the program , ls -l ./log like:

    $ ls -l log
    总用量 4
    -rw-rw-r-- 1 lws lws    0 4月   6 14:43 log.log
    -rw-rw-r-- 1 lws lws 1007 4月   6 14:43 log.log.2022-04-06-14-43
    
    opened by just-for-meal 0
  • Modify appender log level at runtime

    Modify appender log level at runtime

    i have using cmake build log4cplus 2.0.7 version. I tried to create two appends: date and console. I have two controls. I want to reset the log level through the console at run time. How to ensure thread safety and reset the log level?

        void set_log_level(const log4cplus::tstring& name, log4cplus::LogLevel level){
            auto appender = logger_.getAppender(name);
            if(appender){
                // Is this thread safe
                appender->setThreshold(level);
            }
        }
    
        void add_daily_mode(std::string_view file_pattern, std::string_view pattern, uint8_t level) {
            log4cplus::helpers::Properties properties;
            properties.setProperty(LOG4CPLUS_TEXT("File"), "");
            properties.setProperty(LOG4CPLUS_TEXT("FilenamePattern"), file_pattern.data());
            properties.setProperty(LOG4CPLUS_TEXT("MaxHistory"), "9999");
            properties.setProperty(LOG4CPLUS_TEXT("CleanHistoryOnStart"), "false");
            properties.setProperty(LOG4CPLUS_TEXT("ImmediateFlush"), "true");
            properties.setProperty(LOG4CPLUS_TEXT("CreateDirs"), "true");
            properties.setProperty(LOG4CPLUS_TEXT("AsyncAppend"), "true");
            properties.setProperty(LOG4CPLUS_TEXT("RollOnClose"), "false");
            properties.setProperty(LOG4CPLUS_TEXT("Locale"), LOG4CPLUS_TEXT("en_US.UTF-8"));
            log4cplus::SharedAppenderPtr time(new log4cplus::TimeBasedRollingFileAppender(properties));
            time->setLayout(std::make_unique<log4cplus::PatternLayout>(pattern.data()));
            time->setName(LOG4CPLUS_TEXT("time_file"));
            time->setThreshold(level * 10000);
            logger_.addAppender(time);
        }
    
        void add_console_mode(std::string_view pattern, uint8_t level) {
            log4cplus::helpers::Properties properties;
            properties.setProperty(LOG4CPLUS_TEXT("AsyncAppend"), "true");
            properties.setProperty(LOG4CPLUS_TEXT("Locale"), LOG4CPLUS_TEXT("en_US.UTF-8"));
            log4cplus::SharedAppenderPtr console(new log4cplus::ConsoleAppender(properties));
            console->setLayout(std::make_unique<log4cplus::PatternLayout>(pattern.data()));
            console->setName(LOG4CPLUS_TEXT("console"));
            console->setThreshold(level * 10000);
            logger_.addAppender(console);
        }
    
    question 
    opened by jphz 2
  • RollingFileAppender is not working with 2.0.6

    RollingFileAppender is not working with 2.0.6

    Hi

    I'm using 2.0.6 in Windows 64 bit compiled as static library.

    My configuration is:

    log4cplus.rootLogger=DEBUG, ROLLING, STDOUT
    
    log4cplus.appender.STDOUT=log4cplus::ConsoleAppender
    log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout
    #See http://logging.apache.org/log4j/docs/api/org/apache/log4j/PatternLayout.html
    log4cplus.appender.STDOUT.layout.ConversionPattern=%D{%H:%M:%S} [%t] - %m%n
    
    log4cplus.appender.ROLLING=log4cplus::RollingFileAppender
    #MaxFileSize configures the maximum log file size. 
    log4cplus.appender.ROLLING.MaxFileSize=400Kb
    #MaxBackupIndex configures the number of backup log files.
    log4cplus.appender.ROLLING.MaxBackupIndex=5
    log4cplus.appender.ROLLING.layout=log4cplus::PatternLayout
    log4cplus.appender.ROLLING.layout.ConversionPattern=%D{%d/%m/%Y %H:%M:%S:%q} [%t] %-5p - %m [%-l]%n
    #File configures the log file path. if no path is specified the log will be created in MyDocuments folder. 
    log4cplus.appender.ROLLING.File=log.txt
    #log4cplus.appender.ROLLING.UseLockFile=true
    log4cplus.appender.ROLLING.ImmediateFlush=true
    

    I'm running a loop to write many log messages to see new log file is created, but I observe the following issues:

    1. My log file is not flushed each entry, but the file size stays 0 until I finish the program
    2. Additional log files are not created as expected when reaching 400 Kb with new name, but the single file is constantly overwritten.

    Please advice.

    Thanks a lot, Slava

    opened by SlavaC1 1
  • log4cplus:ERROR No appenders could be found for logger (root)  Error while run a program

    log4cplus:ERROR No appenders could be found for logger (root) Error while run a program

    hi,

    i have using vcpkg log4cplus 2.0.5 version. i tried sample for Day based log file creation.

    my sample program is

    	void  SetLogProperties(log4cplus::helpers::Properties& props)
    	{
    #define SET(propertyKey, propertyValue) props.setProperty(propertyKey, propertyValue)
    
    		static const char* pattern = "[%-6i][%-6t][%D{%Y-%m-%d %H:%M:%S.%q}] %-5p: %m%n";
    		
    
    		log4cplus::helpers::Properties p;
    		p.setProperty(LOG4CPLUS_TEXT("log4cplus.logger.Service"), LOG4CPLUS_TEXT("ALL"));
    		p.setProperty(LOG4CPLUS_TEXT("log4cplus.logger.Session"), LOG4CPLUS_TEXT("ALL"));
    		p.setProperty(LOG4CPLUS_TEXT("log4cplus.rootLogger"), LOG4CPLUS_TEXT("TRACE, consoleAppender, rollFileAppender"));
    		p.setProperty(LOG4CPLUS_TEXT("log4cplus.appender.consoleAppender"), LOG4CPLUS_TEXT("log4cplus::ConsoleAppender"));
    		p.setProperty(LOG4CPLUS_TEXT("log4cplus.appender.consoleAppender.layout"), LOG4CPLUS_TEXT("log4cplus::PatternLayout"));
    		p.setProperty(LOG4CPLUS_TEXT("log4cplus.appender.rollFileAppender"), LOG4CPLUS_TEXT("log4cplus::TimeBasedRollingFileAppender"));
    		p.setProperty(LOG4CPLUS_TEXT("log4cplus.appender.rollFileAppender.FilenamePattern"), LOG4CPLUS_TEXT(logFileName));
    		p.setProperty(LOG4CPLUS_TEXT("log4cplus.appender.rollFileAppender.RollOnClose"), LOG4CPLUS_TEXT("false"));
    		p.setProperty(LOG4CPLUS_TEXT("log4cplus.appender.rollFileAppender.Append"), LOG4CPLUS_TEXT("true"));
    		p.setProperty(LOG4CPLUS_TEXT("log4cplus.appender.rollFileAppender.MaxFileSize"), LOG4CPLUS_TEXT("5MB"));
    		p.setProperty(LOG4CPLUS_TEXT("log4cplus.appender.rollFileAppender.ImmediateFlsh"), LOG4CPLUS_TEXT("true"));
    		p.setProperty(LOG4CPLUS_TEXT("log4cplus.appender.rollFileAppender.MaxBackupIndex"), LOG4CPLUS_TEXT("100"));
    
    		p.setProperty(LOG4CPLUS_TEXT("log4cplus.appender.rollFileAppender.layout.ConversionPattern"), LOG4CPLUS_TEXT(pattern));
    
    
    
    	}
    
    	void InitializeLogger(std::string fileName)
    	{
    		{
    			log4cplus::initialize(); 
    			logFileName = "test_%d{yyyy-MM-dd}.log";
    			log4cplus::helpers::Properties props("");
    			if (props.size() == 0)
    				SetLogProperties(props);
    			log4cplus::PropertyConfigurator conf(props);
    			conf.configure();
    
    			log4cplus::Logger logger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT(""));
    
    
    #define LINFO(msg) LOG4CPLUS_INFO(logger, LOG4CPLUS_TEXT(msg));
    #define LDEBUG(msg) LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT(msg));
    #define LERROR(msg) LOG4CPLUS_ERROR(logger, LOG4CPLUS_TEXT(msg));
    #define LWARN(msg) LOG4CPLUS_WARN(logger, LOG4CPLUS_TEXT(msg));
    #define LTRACE(msg) LOG4CPLUS_TRACE(logger, LOG4CPLUS_TEXT(msg));
    #define LFATAL(msg) LOG4CPLUS_FATAL(logger, LOG4CPLUS_TEXT(msg));
    
    LINFO("LINFO");
    LERROR("LERROR");
    
    
    		}
    	}
    	 
    	int main()
    	{
    		InitializeLogger();
    	}
    	
    

    in this sample after executing LINFO("LINFO"); line, i have faced some error

    Error :

    
    log4cplus:ERROR No appenders could be found for logger (root).
    log4cplus:ERROR Please initialize the log4cplus system properly.
    
    

    and log file also not created . what i missed ? how to solve this error ?

    opened by vikirj 0
Releases(REL_2_0_7)
Mini-async-log-c - Mini async log C port. Now with C++ wrappers.

Description A C11/C++11 low-latency wait-free producer (when using Thread Local Storage) asynchronous textual data logger with type-safe strings. Base

null 66 Dec 7, 2021
Colorful Logging is a simple and efficient library allowing for logging and benchmarking.

Colorful-Logging "Colorful Logging" is a library allowing for simple and efficient logging as well for benchmarking. What can you use it for? -Obvious

Mateusz Antkiewicz 1 Feb 17, 2022
Cute Log is a C++ Library that competes to be a unique logging tool.

Cute Log Cute Log is a C++ Library that competes to be a unique logging tool. Version: 2 Installation Click "Code" on the main repo page (This one.).

null 4 Aug 12, 2021
Reckless logging. Low-latency, high-throughput, asynchronous logging library for C++.

Introduction Reckless is an extremely low-latency, high-throughput logging library. It was created because I needed to perform extensive diagnostic lo

Mattias Flodin 425 Jun 19, 2022
A revised version of NanoLog which writes human readable log file, and is easier to use.

NanoLogLite NanoLogLite is a revised version of NanoLog, and is easier to use without performance compromise. The major changes are: NanoLogLite write

Meng Rao 19 May 17, 2022
View and log aoe-api requests and responses

aoe4_socketspy View and log aoe-api requests and responses Part 1: https://www.codereversing.com/blog/archives/420 Part 2: https://www.codereversing.c

Alex Abramov 6 Apr 28, 2022
Portable, simple and extensible C++ logging library

Plog - portable, simple and extensible C++ logging library Pretty powerful logging library in about 1000 lines of code Introduction Hello log! Feature

Sergey Podobry 1.4k Jun 20, 2022
Compressed Log Processor (CLP) is a free tool capable of compressing text logs and searching the compressed logs without decompression.

CLP Compressed Log Processor (CLP) is a tool capable of losslessly compressing text logs and searching the compressed logs without decompression. To l

null 49 Jun 8, 2022
Example program using eBPF to log data being based in using shell pipes

Example program using eBPF to log data being based in using shell pipes (|)

pat_h/to/file 27 Mar 21, 2022
Log engine for c plus plus

PTCLogs library PTCLogs is a library for pretty and configurable logs. Installation To install the library (headers and .so file), clone this repo and

Pedro Tavares de Carvalho 12 May 20, 2022
Sagan - a multi-threads, high performance log analysis engine

Sagan - Sagan is a multi-threads, high performance log analysis engine. At it's core, Sagan similar to Suricata/Snort but with logs rather than network packets.

Quadrant Information Security 63 Jun 17, 2022
Minimalistic logging library with threads and manual callstacks

Minimalistic logging library with threads and manual callstacks

Sergey Kosarevsky 21 Jun 24, 2022
A Fast and Convenient C++ Logging Library for Low-latency or Real-time Environments

xtr What is it? XTR is a C++ logging library aimed at applications with low-latency or real-time requirements. The cost of log statements is minimised

null 8 Jun 6, 2022
Yet another logging library.

Blackhole - eating your logs with pleasure Blackhole is an attribute-based logger with strong focus on gaining maximum performance as possible for suc

Evgeny Safronov 186 Jun 10, 2022
C++ implementation of the Google logging module

Google Logging Library The Google Logging Library (glog) implements application-level logging. The library provides logging APIs based on C++-style st

Google 5.4k Jun 21, 2022
A lightweight C++ logging library

Loguru: a lightweight and flexible C++ logging library. At a glance Documentation Documentation can be found at https://emilk.github.io/loguru/index.h

Emil Ernerfeldt 1.4k Jun 20, 2022