Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

The logger call virtual destructor when writting logs #861

Open

Description

@xhtsansiro

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.

Activity

  1. xhtsansiro commented on Dec 19, 2024

    @xhtsansiro
    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.

  2. xhtsansiro commented on Dec 19, 2024

    @xhtsansiro
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions