FAQ actually misses that point. Let me answer it here and if this answer looks exhaustive then I will add it to FAQ.
The same instance of the log4cpp::Category object (a logger) can be used from different threads simultaneously without explicit synchronization. Concurrent access to the appenders will be prevented by the logger object itself. It will lock internal mutex each time when it comes to writing into appenders. So, it is safe, for example, to write from the multiple threads to the same logger which appends to the same file.
Although, if you configure log4cpp in such a way that two different loggers append to the same appender (file), then there will be no way for the framework to arrange proper addition and things can get mixed up. So this way of configuration is not recommended.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Additional related question: The documentation also describes configure options --with-omnithreads and --with-pthreads. But it isn't clear what "enable multi-threading support" means, and whether log4cpp is/isn't thread safe with/without these options.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
--with-omnithreads and --with-pthreads look to be some ancient stuff.
Currently, these options are not recognized by configure script on modern systems like Ubuntu 12.04.
I guess --with-pthreads option was supposed to turn on -pthread option for gcc compiler which in turn would tell a compiler to build and link with multithreaded runtime libraries. As of now -pthreads is added to gcc flags with or without this option (on Ubuntu).
Although, that may not be true for the older/not-linux systems, where --with-pthreads flag still may be valuable.
"Enable multi-threading support" means that compiler should link the code against multithreaded runtime libraries.
Last edit: Alexander Perepelkin 2013-12-06
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello Craig,
FAQ actually misses that point. Let me answer it here and if this answer looks exhaustive then I will add it to FAQ.
The same instance of the log4cpp::Category object (a logger) can be used from different threads simultaneously without explicit synchronization. Concurrent access to the appenders will be prevented by the logger object itself. It will lock internal mutex each time when it comes to writing into appenders. So, it is safe, for example, to write from the multiple threads to the same logger which appends to the same file.
Although, if you configure log4cpp in such a way that two different loggers append to the same appender (file), then there will be no way for the framework to arrange proper addition and things can get mixed up. So this way of configuration is not recommended.
That's really informative, thanks.
Additional related question: The documentation also describes configure options
--with-omnithreads
and--with-pthreads
. But it isn't clear what "enable multi-threading support" means, and whether log4cpp is/isn't thread safe with/without these options.--with-omnithreads and --with-pthreads look to be some ancient stuff.
Currently, these options are not recognized by configure script on modern systems like Ubuntu 12.04.
I guess --with-pthreads option was supposed to turn on -pthread option for gcc compiler which in turn would tell a compiler to build and link with multithreaded runtime libraries. As of now -pthreads is added to gcc flags with or without this option (on Ubuntu).
Although, that may not be true for the older/not-linux systems, where --with-pthreads flag still may be valuable.
"Enable multi-threading support" means that compiler should link the code against multithreaded runtime libraries.
Last edit: Alexander Perepelkin 2013-12-06