easyloggingpp
easyloggingpp copied to clipboard
The logger call virtual destructor when writting logs
Hi,
I encounter a problem when starting my C++ code. The logger caused a segmentation fault. After checking backtrace using gdb, I saw that a simple LOG(INFO) sentence in my code calls the virtual destructor. To this end, Logger::Level will become a very large negative number, which results in a segmentation fault.
I tried to run the code, sometimes it is executed normally and the log entry in my code call the function of Writer (marked as 1 in the above pic.). sometimes it leads to segmentation fault by calling the function ~Writer (marked as 2 in the above pic).
The log entry in my code is as following pic. shows
My C++ project is a multi-thread one. In each thread there exists log entries, and I declare following settings before the entry of main function in main.cpp
"INITIALIZE_EASYLOGGINGPP
#define ELPP_THREAD_SAFE
#define ELPP_QT_LOGGING"
And the settings of config file is:
- GLOBAL: FORMAT = "%datetime{%Y-%M-%d %H:%m:%s,%g} %fbase:%line [%level] %msg" FILENAME = "../logs/my123.log" ENABLED = true TO_FILE = true TO_STANDARD_OUTPUT = true SUBSECOND_PRECISION = 3 PERFORMANCE_TRACKING = true MAX_LOG_FILE_SIZE = 1048576000 ## 100MB - Comment starts with two hashes (##) LOG_FLUSH_THRESHOLD = 200 ## Flush after every 100 logs
Can you please indicate what leads to the unexpected segmentation fault based on the information I provide.
Thanks in advance.
I think the solution is define macros in cmakelists.txt instead of in main.cpp. This is explained in the readme file of the repository.
After doing the following in CMakeLists.txt
target_compile_definitions(logger_lib PUBLIC ELPP_THREAD_SAFE), I want to compile easylogging as a sub module lib for my project.
I still encounter the segmentation fault when using LOG(INFO) << "xxxx";
any suggestions?