Closed parikshitnangre closed 8 years ago
Warning has nothing to do with crash
We've seen cases like this when u have macro in one file not in other. Why don't people define it as compiler option? I don't understand
still it is crashing when I am setting as compiler option in Project Properties-->C/C++ --> Preprocessor - ELPP_THREAD_SAFE
does it crash when you use macro (LOG(WARNING)
)?
can you run this sample? What platform are you using? (compiler and OS specifically)
i am using windows and when i used LOG(WARNING) it doesnt crash.
Now i tried this very liitle code - and its crashing -
INITIALIZE_EASYLOGGINGPP void main() { el::Logger* mainLogger = el::Loggers::getLogger("main"); mainLogger->warn("abc"); }
and when i comment the line #define ELPP_THREAD_SAFE, it works well. Please tell me whats wrong.
try CLOG(WARN, "main") << "abc"
instead of mainLogger->warn("abc")
i tried CLOG(WARN, "main") << "abc";
compile errors - Error 1 error C2275: 'el::base::Writer' : illegal use of this type as an expression Error 2 error C3861: 'CWARN': identifier not found
what compiler is it? have you tried the sample i asked you to run?
also can you try to getLogger("default")
instead of getLogger("main")
in your original sample?
If this works then you have problem with registering the logger. try using valgrind to find whether it's getting enough memory to register new logger
this code also crashing -
INITIALIZE_EASYLOGGINGPP void main() { el::Logger* mainLogger = el::Loggers::getLogger("default"); mainLogger->warn("abc"); }
hmm what about pthread.cc sample? what compiler is this? what version of c++? what windows? if you don't provide enough details i'm afraid i won't be able to help you
windows 7 service pack 1 when i use std::cout << __cplusplus << endl; the output was 199711 and i am using default compiler of Visual studio 2013
CLOG(WARNING, "main") << "abc"; worked well with #define ELPP_THREAD_SAFE. But when i use mainLogger->warn("abc"); it crashes. Thanks for your help.
@mkhan3189 you ask "Why don't people define it as compiler option? I don't understand"
It's because the documentation does not even make it clear that these flags need to be #defined before including easylogging++.h and the documentation calls them "Configuration Macros" which is the wrong word for a pre-processor configuration constant, imho.
btw. I found this thread while trying to work out how to use these "macros"
I am re-opening this because I am also experiencing a crash when logging very fast from many (~72) threads.
It seems to be some sort of race condition. What makes me say that is that when I log the output to terminal, the program doesn't crash, but when I log to a file with shell redirection, it does crash.
Platform: ubuntu 14.04 x86-64 CPU : 8 core Intel(R) Core(TM) i7-4910MQ CPU @ 2.90GHz Compiler : clang++-3.6 Compile flags: -std=c++1 -g
This is not compiler-specific: the same crash also occurs when compiling with g++ version 4.8.4
Here are the flags all my code is compiled with:
-D_ELPP_THREAD_SAFE=1
-D_ELPP_DEBUG_ERRORS=1
-D_ELPP_STACKTRACE_ON_CRASH=1
-D_ELPP_FORCE_USE_STD_THREAD=1
-D_ELPP_LOGGING_FLAGS_FROM_ARG=1
Here's how I initialize the logging library:
INITIALIZE_EASYLOGGINGPP
static const char *getThreadId() {
static std::atomic_int pool;
static thread_local char tid[11];
if(0==tid[0]) {
sprintf(tid, "%04d", pool++);
}
return tid;
}
static void initLogging(
int argc,
char *argv[]
) {
el::Configurations conf;
conf.setGlobally(el::ConfigurationType::Format, "%datetime{%s.%g} %tid %levshort %loc %func: %msg");
el::Helpers::installCustomFormatSpecifier(el::CustomFormatSpecifier("%tid", getThreadId));
conf.set(el::Level::Trace, el::ConfigurationType::Enabled, "0");
conf.set(el::Level::Debug, el::ConfigurationType::Enabled, "1");
conf.set(el::Level::Verbose, el::ConfigurationType::Enabled, "0");
conf.set(el::Level::Info, el::ConfigurationType::Enabled, "1");
conf.set(el::Level::Warning, el::ConfigurationType::Enabled, "1");
conf.set(el::Level::Error, el::ConfigurationType::Enabled, "1");
conf.set(el::Level::Fatal, el::ConfigurationType::Enabled, "1");
conf.setGlobally(el::ConfigurationType::MillisecondsWidth, "6");
el::Loggers::reconfigureAllLoggers(conf);
START_EASYLOGGINGPP(argc, argv);
}
Here's a gdb stack dump of the crash
logLine=<unknown type in /home/emogenet/cncsim/cncsim, CU 0x5649bd, DIE 0x796df1>) at ./Log.h:4205
at ./Log.h:4179
Here's the offending line (line 4205) :
(gdb) l 4200 ELPP_INTERNAL_ERROR("Log file for [" << LevelHelper::convertToString(m_data->logMessage()->level()) << "] " 4201 << "has not been configured but [TO_FILE] is configured to TRUE. [Logger ID: " 4202 << m_data->logMessage()->logger()->id() << "]", false); 4203 } 4204 } 4205 if (m_data->logMessage()->logger()->m_typedConfigurations->toStandardOutput(m_data->logMessage()->level())) { 4206 if (ELPP->hasFlag(LoggingFlag::ColoredTerminalOutput)) 4207 m_data->logMessage()->logger()->logBuilder()->convertToColoredOutput(&logLine, m_data->logMessage()->level()); 4208 ELPP_COUT << ELPP_COUT_LINE(logLine);
Finally, to confirm the misbehavior, I ran it with valgrind. It spits a whole bunch of "Invalid read of size 8":
==2935== Invalid read of size 8 ==2935== at 0x607832: el::LogDispatchData::logMessage() const (Log.h:3343) ==2935== by 0x60A03D: el::base::DefaultLogDispatchCallback::dispatch(std::string&&) (Log.h:4205) ==2935== by 0x609E29: el::base::DefaultLogDispatchCallback::handle(el::LogDispatchData const_) (Log.h:4179) ==2935== by 0x41A83E: el::base::LogDispatcher::dispatch() (Log.h:4486) ==2935== by 0x41B679: el::base::Writer::triggerDispatch() (Log.h:5054) ==2935== by 0x41B431: el::base::Writer::processDispatch() (Log.h:5037) ==2935== by 0x41AB43: el::base::Writer::~Writer() (Log.h:4923) ==2935== by 0x615529: LoaderThread::LoaderThread(Eigen::Transform<float, 3, 2, 0> const&, std::string const&, STLObject_, unsigned char, unsigned char, unsigned char) (LoaderThread.h:41) ==2935== by 0x614B10: Piece::load() (Machine.cpp:33) ==2935== by 0x615397: Piece::draw() (Machine.h:34) ==2935== by 0x614F36: Part::draw() (Machine.cpp:64) ==2935== by 0x60233E: Machine::draw() (Machine.h:228) ==2935== Address 0x1bcc6a00 is not stack'd, malloc'd or (recently) free'd ==2935== ==2935== Invalid read of size 8 ==2935== at 0x607832: el::LogDispatchData::logMessage() const (Log.h:3343) ==2935== by 0x60A057: el::base::DefaultLogDispatchCallback::dispatch(std::string&&) (Log.h:4205) ==2935== by 0x609E29: el::base::DefaultLogDispatchCallback::handle(el::LogDispatchData const) (Log.h:4179) ==2935== by 0x41A83E: el::base::LogDispatcher::dispatch() (Log.h:4486) ==2935== by 0x41B679: el::base::Writer::triggerDispatch() (Log.h:5054) ==2935== by 0x41B431: el::base::Writer::processDispatch() (Log.h:5037) ==2935== by 0x41AB43: el::base::Writer::~Writer() (Log.h:4923) ==2935== by 0x615529: LoaderThread::LoaderThread(Eigen::Transform<float, 3, 2, 0> const&, std::string const&, STLObject**, unsigned char, unsigned char, unsigned char) (LoaderThread.h:41) ==2935== by 0x614B10: Piece::load() (Machine.cpp:33) ==2935== by 0x615397: Piece::draw() (Machine.h:34) ==2935== by 0x614F36: Part::draw() (Machine.cpp:64) ==2935== by 0x60233E: Machine::draw() (Machine.h:228) ==2935== Address 0x1bcc6a00 is not stack'd, malloc'd or (recently) free'd ==2935==
The offending line (3343) where the bad read occur:
inline const LogMessage* logMessage(void) const { return m_logMessage; }
Crash has nothing to do with thread as assert failure suggests, ypu remove file configuration somewhere but didnt unset to file config
If you look at this sample and uncomment lines in the end and run and if it crashes it's related to thread if not it's ur config that u change in one of the 72 threads
https://github.com/easylogging/easyloggingpp/blob/master/samples/STL/pthread.cpp
Crash has nothing to do with thread as assert failure suggests, ypu remove file configuration somewhere but didnt unset to file config
I never change the logging configuration after I set it in the main. I do not use external files for logging configuration, everything is done programatically. The only thing I do in the threads is something like : LOG(DEBUG) << "hello";
If you look at this sample and uncomment lines in the end and run and if it crashes it's related to thread if not it's ur config that u change in one of the 72 threads
I just downloaded the sample, and as you suggested, I uncommented the lines at the end and compiled it. The sample program has the exact same problem mine has:
Here's the stack dump under gdb:
Here's valgrind:
==28925== Thread 4:
==28925== Invalid read of size 1
==28925== at 0x4A0B0E2: strlen (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==28925== by 0x300ACBBD34: std::basic_string<char, std::char_traits
I am also having this problem running on Ubuntu 16.04 LTS. I am using G++ to compile. I am thinking it may be a compiler problem.
I confirm the behaviour on Ubuntu 16.04LTS using GCC 5.4.0.
std::system_error
on first log if using -DELPP_THREAD_SAFE
I'm also having trouble with this. Here is my complete source code:
#define ELPP_THREAD_SAFE
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
int main(int argc, char **argv) {
START_EASYLOGGINGPP(argc, argv);
LOG(INFO) << "My first info log using default logger";
return 0;
}
And this is what I get:
Process finished with exit code 11
I am facing crash when i use this macro. My code snippet looks like this -
define ELPP_THREAD_SAFE
define ELPP_NO_DEFAULT_LOG_FILE
include "../easylogging++.h"
when i build it, i get follwing warning - easylogging++.h(1029): warning C4100: 'ms' : unreferenced formal parameter
and i am very sure crash is due to the macro. As when i comment the line, //#define ELPP_THREAD_SAFE, crash goes off.
Is it because of the above warning ?
So please suggest what should i change/add ? Also the macro is ELPP_THREAD_SAFE & not _ELPP_THREAD_SAFE, but many times in answers i found it as _ELPP_THREAD_SAFE.