g3log: g3Log Crashes the Application
If I initialize and log in sample cpp program having main method, it works properly but when I integrated in my dll project where there is no main method but I have method which I call firstly where i have followed the same code as explained in “https://github.com/KjellKod/g3log/issues/88#issuecomment-219030139”. It generates the log properly but immediately my java’s GUI system get crashed and I get the same error. Please help me to get rid of this.
namespace {
static std::once_flag g_initLogger;
static std::unique_ptr g_logger;
static std::unique_ptr g_loggerHandle;
} // namespace
void InitializeLogging(const std::string& logPrefix, const std::string& logPath) {
std::call_once(g_initLogger, [&] {
g_logger = g3::LogWorker::createLogWorker();
g_loggerHandle = g_logger->addDefaultLogger(logPrefix, logPath);
g3::initializeLogging(g_logger.get());
});
}
bool IsLoggerEnabled() {
return g3::internal::isLoggingInitialized();
}
void ShutdownLogging() {
//g3::internal::shutDownLogging(); // HERE I HAVE commented as I calls internally
g_logger.reset();
}
I CALL ABOVE METHODS IN MY METHOD WHICH I CALL IT FROM MY GUI TOOL BUILT IN JAVA
JNIEXPORT jobjectArray JNICALL Java_com_mydll_loadDLLGetVersion(JNIEnv *env, jobject thisObj)
{
int versionNumber = 0;
string resultStr;
jobjectArray jresultStr = (*env).NewObjectArray(3, (*env).FindClass(“java/lang/String”), NULL);
try
{
// Tried initializing here too however it is crashing
/*
auto worker = g3::LogWorker::createLogWorker();
auto handle = worker->addDefaultLogger(“MyG3Log_”, “D:\\G3Logs\\”);
g3::initializeLogging(worker.get());
*/
InitializeLogging(“MyG3Log_”, “D:\\G3Logs\\”);
LOG(INFO) << "Hello1";
LOG(INFO) << "Hello2";
LOG(INFO) << "Hello3";
LOG(INFO) << "Hello4";
LOG(INFO) << "Hello5";
LOG(INFO) << "Hello6";
LOG(INFO) << "Hello7";
ShutdownLogging();
}
}
catch (exception& e)
{
if(handleDLL != NULL) {
UnloadDLLAPI(handleDLL);
}
resultStr += ";";
resultStr += e.what();
}
return jresultStr;
}
I GET BELOW ERROR FROM g3Log
g3log g3FileSink shutdown at: 15:42:22
Log file at: [D:/G3Logs/MyG3Log_20190307-154222.log]
FATAL CALL but logger is NOT initialized
CAUSE: EXCEPTION_ACCESS_VIOLATION
Message:
2019/03/07 15:42:56
***** FATAL EXCEPTION RECEIVED *******
***** Vectored Exception Handler: Received fatal exception EXCEPTION_ACCESS_VIOLATION PID: 13048
******* STACKDUMP *******
stack dump [0]
stack dump [1]
stack dump [2]
stack dump [3]
stack dump [4]
stack dump [5]
stack dump [6]
stack dump [7]
stack dump [8]
stack dump [9]
stack dump [10]
stack dump [11]
stack dump [12]
stack dump [13]
stack dump [14]
stack dump [15]
I initialized the worker in the method however it crashed the application by throwing fatal errors. I tried to look up all your forums and documentation but i found nothing. As per my understanding i have implemented g3log like below :
Mymethod(){
Step 1. Initialized worker
Strp 2. Log statement to print logs in file.
Step 3. Worker.reset() or g3::internal::shutDownLogging()
// my other application related businesses logic
}
Please accept my sincere apologies as I am new to CPP and I tried to find everything in your source code but all time it crashed my application.
Please help.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 27 (14 by maintainers)
g3log has never promised to make anything crash-free. It is
crash safein that it accounts for some type of crashes and dumps the reason for the crash. Avoiding to crash would be a very bad idea.Good luck