abumq / easyloggingpp

C++ logging library. It is powerful, supports asynchronous low latency, extendable, light-weight, fast performing, thread and type safe and consists of many built-in features. It provides ability to write logs in your own customized format. It also provide support for logging your classes, third-party libraries, STL and third-party containers etc.
MIT License
3.75k stars 918 forks source link

Printf style logger crashes when in multi-threaded mode #536

Open mobileben opened 7 years ago

mobileben commented 7 years ago

I'm writing some code for the Mac as was going to potentially use easyloggingpp. I was experimenting with the library, but found that there is an assertion hit in the locked_guard code. It looks like the dtor is being called twice.

Assertion failed: (e == 0), function unlock, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/libcxx/libcxx-307.5/src/mutex.cpp, line 102.

These dtors are being called at the exit of the function

template <typename T>
inline void Logger::log(Level level, const T& log) {
  base::threading::ScopedLock scopedLock(lock());
  log_(level, 0, log);
}

I'm running Xcode 8.3.1. I have defined

-DELPP_THREAD_SAFE
-DELPP_FORCE_USE_STD_THREAD

My test code is pretty simple. The macros work fine.

    //LOG(INFO) << "First log message";
    //LOG(WARNING) << "This is a warning";
    el::Logger *defLogger = el::Loggers::getLogger("default");
    defLogger->warn("Printf style");

I don't have any configuration defined.

monicuti commented 7 years ago

I'm also having the same problem. Here is my sample code to try it:

//easylogging defines //#define ELPP_DEFAULT_LOG_FILE

define ELPP_NO_DEFAULT_LOG_FILE //dont create log file by default

define ELPP_THREAD_SAFE

define ELPP_FORCE_USE_STD_THREAD

define ELPP_STL_LOGGING //define for default stl logger

include "easylogging++.h"

int main(int argc, char *argv[]) {

el::Logger* defaultLogger = el::Loggers::getLogger("default"); defaultLogger->info("testing easylogging");

}

simoc commented 2 years ago

The sample code in the comment above needs an INITIALIZE_EASYLOGGINGPP:

//easylogging defines
//#define ELPP_DEFAULT_LOG_FILE
#define ELPP_NO_DEFAULT_LOG_FILE //dont create log file by default
#define ELPP_THREAD_SAFE
#define ELPP_FORCE_USE_STD_THREAD
#define ELPP_STL_LOGGING //define for default stl logger
#include "easylogging++.h"

INITIALIZE_EASYLOGGINGPP

int main(int argc, char *argv[]) {

el::Logger* defaultLogger = el::Loggers::getLogger("default");
defaultLogger->info("testing easylogging");

}