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.79k stars 927 forks source link

On crash, log line number and file in source code #400

Open khlitoshi opened 8 years ago

khlitoshi commented 8 years ago

Hi,

Sorry if this is not the right place to ask for this, I am in urgent need for an answer.

I need to get line number and filename in source code when unhandled exception occurs.

but I am getting this instead, which is the line number inside the logging library.

2016-08-09 11:43:29,968 WARN easylogging++.h 5627 Aborting application. Reason: Fatal log at [ c:\vsprojects\loglibtest\loglibtest\easylogging++.h : 5627 ]

Can anyone help me solve the issue. below is sample code I'm using


#define ELPP_THREAD_SAFE

#define ELPP_CUSTOM_COUT std::cerr
#include "easylogging++.h"
#define _ELPP_STACKTRACE_ON_CRASH

INITIALIZE_EASYLOGGINGPP

void myCrashHandler(int sig) 
{
    LOG(ERROR) << "Application crashed!";

    el::Helpers::logCrashReason(sig, true);
    el::Loggers::flushAll();
    el::Helpers::crashAbort(sig); // FOLLOWING LINE IS ABSOLUTELY NEEDED AT THE END IN ORDER TO ABORT APPLICATION
    el::Loggers::flushAll();
}

void main()
{
    el::Helpers::setCrashHandler(myCrashHandler);
    el::Loggers::addFlag(el::LoggingFlag::LogDetailedCrashReason);

    int* i;
    *i = 0; // Crash!

    return 0;
}
JasCodes commented 8 years ago

@mkhan3189 +1

maiconkist commented 8 years ago

Same problem with me:

CRASH HANDLED; Application has crashed due to [SIGSEGV] signal 2016-09-30 10:16:18,292 WARN [default] Aborting application. Reason: Fatal log at [/myuser/lib/easylogging++.h:5627]

andreivirtosu commented 7 years ago

+1

korst1k commented 7 years ago

I had the same problem: 2016-11-12 23:45:23.507321 F easylogging++.h:5627 CRASH HANDLED; Application has crashed due to [SIGSEGV] signal

Chrisliu0915 commented 7 years ago

+1

xserver commented 7 years ago

F [2017-02-08 19:06:10] [easylogging++.h:5627] CRASH HANDLED; Application has crashed due to [SIGSEGV] signal W [2017-02-08 19:06:10] [easylogging++.h:5627] Aborting application. Reason: Fatal log at [./inc/easylogging++.h:5627]

mikeleatila commented 6 years ago

I just rebooted my machine and the error is gone :)

doleron commented 3 years ago

Same behavior here:

2021-06-01 14:45:34,934666 - ERROR - Application crashed!
2021-06-01 14:45:34,934697 - FATAL - CRASH HANDLED; Application has crashed due to [SIGSEGV] signal
    Invalid access to memory
    Program is trying to read an invalid (unallocated, deleted or corrupted) or inaccessible memory.
    ======= Backtrace: =========

2021-06-01 14:45:34,934707 - WARNING - Aborting application. Reason: Fatal log at [/path/libs/easyloggingpp/src/easylogging++.cc:2884]

But in my case the Backtrace is empty. I have in my cmake lists:

add_definitions(-DELPP_NO_DEFAULT_LOG_FILE)
add_definitions(-DELPP_THREAD_SAFE)
add_definitions(-DELPP_FEATURE_CRASH_LOG)

target_compile_options(${PROJECT_NAME} PRIVATE -O3)

my gcc / OS are:

$ gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

Any ideas? Thanks!

Hammer2017 commented 3 months ago

I've checked the source code and it requires adding the macro definition add_definitions(-DHAVE_EXECINFO)