Merge pull request #4138

7f8bdeb easylogging++: make the logger handle early/late logging (moneromooo-monero)
bc8cbdb stack_trace: print stack traces on stdout if the logger isn't live (moneromooo-monero)
This commit is contained in:
luigi1111 2018-08-15 17:19:04 -05:00
commit 88369c6685
No known key found for this signature in database
GPG key ID: F4ACA0183641E010
3 changed files with 27 additions and 5 deletions

View file

@ -2092,6 +2092,17 @@ void VRegistry::setFromArgs(const base::utils::CommandLineArgs* commandLineArgs)
# define ELPP_DEFAULT_LOGGING_FLAGS 0x0 # define ELPP_DEFAULT_LOGGING_FLAGS 0x0
#endif // !defined(ELPP_DEFAULT_LOGGING_FLAGS) #endif // !defined(ELPP_DEFAULT_LOGGING_FLAGS)
// Storage // Storage
el::base::type::StoragePointer getresetELPP(bool reset)
{
static el::base::type::StoragePointer p(new el::base::Storage(el::LogBuilderPtr(new el::base::DefaultLogBuilder())));
if (reset)
p = NULL;
return p;
}
el::base::type::StoragePointer el::base::Storage::getELPP()
{
return getresetELPP(false);
}
#if ELPP_ASYNC_LOGGING #if ELPP_ASYNC_LOGGING
Storage::Storage(const LogBuilderPtr& defaultLogBuilder, base::IWorker* asyncDispatchWorker) : Storage::Storage(const LogBuilderPtr& defaultLogBuilder, base::IWorker* asyncDispatchWorker) :
#else #else
@ -2140,6 +2151,7 @@ Storage::Storage(const LogBuilderPtr& defaultLogBuilder) :
Storage::~Storage(void) { Storage::~Storage(void) {
ELPP_INTERNAL_INFO(4, "Destroying storage"); ELPP_INTERNAL_INFO(4, "Destroying storage");
getresetELPP(true);
#if ELPP_ASYNC_LOGGING #if ELPP_ASYNC_LOGGING
ELPP_INTERNAL_INFO(5, "Replacing log dispatch callback to synchronous"); ELPP_INTERNAL_INFO(5, "Replacing log dispatch callback to synchronous");
uninstallLogDispatchCallback<base::AsyncLogDispatchCallback>(std::string("AsyncLogDispatchCallback")); uninstallLogDispatchCallback<base::AsyncLogDispatchCallback>(std::string("AsyncLogDispatchCallback"));

View file

@ -2766,6 +2766,8 @@ class Storage : base::NoCopy, public base::threading::ThreadSafe {
return it->second; return it->second;
} }
static el::base::type::StoragePointer getELPP();
private: private:
base::RegisteredHitCounters* m_registeredHitCounters; base::RegisteredHitCounters* m_registeredHitCounters;
base::RegisteredLoggers* m_registeredLoggers; base::RegisteredLoggers* m_registeredLoggers;
@ -2798,7 +2800,7 @@ class Storage : base::NoCopy, public base::threading::ThreadSafe {
} }
}; };
extern ELPP_EXPORT base::type::StoragePointer elStorage; extern ELPP_EXPORT base::type::StoragePointer elStorage;
#define ELPP el::base::elStorage #define ELPP el::base::Storage::getELPP()
class DefaultLogDispatchCallback : public LogDispatchCallback { class DefaultLogDispatchCallback : public LogDispatchCallback {
protected: protected:
void handle(const LogDispatchData* data); void handle(const LogDispatchData* data);
@ -4628,10 +4630,9 @@ el::base::debug::CrashHandler elCrashHandler(ELPP_USE_DEF_CRASH_HANDLER); \
} }
#if ELPP_ASYNC_LOGGING #if ELPP_ASYNC_LOGGING
# define INITIALIZE_EASYLOGGINGPP ELPP_INIT_EASYLOGGINGPP(new el::base::Storage(el::LogBuilderPtr(new el::base::DefaultLogBuilder()),\ # define INITIALIZE_EASYLOGGINGPP ELPP_INIT_EASYLOGGINGPP(NULL)
new el::base::AsyncDispatchWorker()))
#else #else
# define INITIALIZE_EASYLOGGINGPP ELPP_INIT_EASYLOGGINGPP(new el::base::Storage(el::LogBuilderPtr(new el::base::DefaultLogBuilder()))) # define INITIALIZE_EASYLOGGINGPP ELPP_INIT_EASYLOGGINGPP(NULL)
#endif // ELPP_ASYNC_LOGGING #endif // ELPP_ASYNC_LOGGING
#define INITIALIZE_NULL_EASYLOGGINGPP \ #define INITIALIZE_NULL_EASYLOGGINGPP \
namespace el {\ namespace el {\

View file

@ -49,7 +49,16 @@
#undef MONERO_DEFAULT_LOG_CATEGORY #undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "stacktrace" #define MONERO_DEFAULT_LOG_CATEGORY "stacktrace"
#define ST_LOG(x) CINFO(el::base::Writer,el::base::DispatchAction::FileOnlyLog,MONERO_DEFAULT_LOG_CATEGORY) << x #define ST_LOG(x) \
do { \
auto elpp = ELPP; \
if (elpp) { \
CINFO(el::base::Writer,el::base::DispatchAction::FileOnlyLog,MONERO_DEFAULT_LOG_CATEGORY) << x; \
} \
else { \
std::cout << x << std::endl; \
} \
} while(0)
// from https://stackoverflow.com/questions/11665829/how-can-i-print-stack-trace-for-caught-exceptions-in-c-code-injection-in-c // from https://stackoverflow.com/questions/11665829/how-can-i-print-stack-trace-for-caught-exceptions-in-c-code-injection-in-c