Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The logger call virtual destructor when writting logs #861

Open
xhtsansiro opened this issue Dec 18, 2024 · 2 comments
Open

The logger call virtual destructor when writting logs #861

xhtsansiro opened this issue Dec 18, 2024 · 2 comments

Comments

@xhtsansiro
Copy link

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.

logger
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
logger2

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.

@xhtsansiro
Copy link
Author

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.

@xhtsansiro
Copy link
Author

xhtsansiro commented Dec 19, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant