You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider following program (also added to samples)
#include <chrono>
#include <thread>
#include <future>
#include "easylogging++.h"
INITIALIZE_EASYLOGGINGPP
void f() {
std::async(std::launch::async, [&]() {
std::cout << "[internal] inside async()" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
LOG(INFO) << "This is from async";
});
}
class MyHandler : public el::LogDispatchCallback {
public:
void handle(const el::LogDispatchData* d) {
std::cout << "Message: " << d->logMessage()->message() << " [logger: " << d->logMessage()->logger()->id() << "]" << std::endl;
if (d->logMessage()->logger()->id() != "default") {
std::cout << "[internal] calling f()" << std::endl;
f();
}
}
};
int main(int,char**){
el::Loggers::addFlag(el::LoggingFlag::CreateLoggerAutomatically);
// el::Helpers::uninstallLogDispatchCallback<el::base::DefaultLogDispatchCallback>("DefaultLogDispatchCallback");
el::Helpers::installLogDispatchCallback<MyHandler>("MyHandler");
LOG(INFO)<<"The program has started!";
CLOG(INFO, "frommain") << "THis is another";
std::thread t1([](){
LOG(INFO) << "This is from thread";
});
t1.join();
LOG(INFO) << "Shutting down.";
return 0;
}
we should be able to use LOG(...) (i.e, default logger) in above case as we have custom handler. But because of global lock ELPP->lock() in LogDispatch this scenerio is not possible. We need to allow this scenerio
The expected output is
2017-10-12 13:55:48,712 INFO [default] The program has started!
Message: The program has started! [logger: default]
2017-10-12 13:55:48,713 INFO [frommain] THis is another
Message: THis is another [logger: frommain]
[internal] calling f()
[internal] inside async()
2017-10-12 13:55:49,716 INFO [default] This is from async
Message: This is from async [logger: default]
2017-10-12 13:55:49,717 INFO [default] This is from thread
Message: This is from thread [logger: default]
2017-10-12 13:55:49,717 INFO [default] Shutting down.
Message: Shutting down. [logger: default]
but we are getting a deadlock
2017-10-12 14:00:00,587 INFO [default] The program has started!
Message: The program has started! [logger: default]
2017-10-12 14:00:00,588 INFO [frommain] THis is another
Message: THis is another [logger: frommain]
[internal] calling f()
[internal] inside async()
... {no output after this}
Consider following program (also added to samples)
we should be able to use
LOG(...)
(i.e, default logger) in above case as we have custom handler. But because of global lockELPP->lock()
inLogDispatch
this scenerio is not possible. We need to allow this scenerioThe expected output is
but we are getting a deadlock
Documentation
In documentation it says
that is still true but above
if (d->logMessage()->logger()->id() != "default") {
should allow logging withdefault
logger inside the dispatch handlerThe text was updated successfully, but these errors were encountered: