aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/before_exit.cpp7
-rw-r--r--src/core/GpgCoreInit.cpp11
-rw-r--r--src/core/GpgCoreInit.h8
-rw-r--r--src/init.cpp22
-rw-r--r--src/main.cpp20
-rw-r--r--src/signal.cpp8
-rw-r--r--src/ui/GpgFrontendUIInit.cpp21
-rw-r--r--src/ui/GpgFrontendUIInit.h12
8 files changed, 89 insertions, 20 deletions
diff --git a/src/before_exit.cpp b/src/before_exit.cpp
index be655616..31c56354 100644
--- a/src/before_exit.cpp
+++ b/src/before_exit.cpp
@@ -33,10 +33,5 @@
*
*/
void before_exit() {
-#ifdef WINDOWS
- // Under VisualStudio, this must be called before main finishes to workaround
- // a known VS issue
- spdlog::drop_all();
- spdlog::shutdown();
-#endif
+
}
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp
index 977bb50c..840b2b87 100644
--- a/src/core/GpgCoreInit.cpp
+++ b/src/core/GpgCoreInit.cpp
@@ -43,7 +43,7 @@ namespace GpgFrontend {
* @brief setup logging system and do proper initialization
*
*/
-void InitLoggingSystem() {
+void InitCoreLoggingSystem() {
using namespace boost::posix_time;
using namespace boost::gregorian;
@@ -81,6 +81,15 @@ void InitLoggingSystem() {
spdlog::set_default_logger(core_logger);
}
+void ShutdownCoreLoggingSystem() {
+#ifdef WINDOWS
+ // Under VisualStudio, this must be called before main finishes to workaround
+ // a known VS issue
+ spdlog::drop_all();
+ spdlog::shutdown();
+#endif
+}
+
void ResetGpgFrontendCore() { reset_gpgfrontend_core(); }
void init_gpgfrontend_core() {
diff --git a/src/core/GpgCoreInit.h b/src/core/GpgCoreInit.h
index 77942b56..41e04d60 100644
--- a/src/core/GpgCoreInit.h
+++ b/src/core/GpgCoreInit.h
@@ -37,7 +37,13 @@ namespace GpgFrontend {
* @brief
*
*/
-void GPGFRONTEND_CORE_EXPORT InitLoggingSystem();
+void GPGFRONTEND_CORE_EXPORT InitCoreLoggingSystem();
+
+/**
+ * @brief
+ *
+ */
+void GPGFRONTEND_CORE_EXPORT ShutdownCoreLoggingSystem();
/**
* @brief
diff --git a/src/init.cpp b/src/init.cpp
index 6aa2084e..6109fa47 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -37,6 +37,19 @@
#include "GpgFrontendBuildInfo.h"
#include "core/function/GlobalSettingStation.h"
+#ifdef WINDOWS
+int setenv(const char *name, const char *value, int overwrite)
+{
+ int errcode = 0;
+ if(!overwrite) {
+ size_t envsize = 0;
+ errcode = getenv_s(&envsize, NULL, 0, name);
+ if(errcode || envsize) return errcode;
+ }
+ return _putenv_s(name, value);
+}
+#endif
+
void init_logging_system() {
using namespace boost::posix_time;
using namespace boost::gregorian;
@@ -68,6 +81,15 @@ void init_logging_system() {
spdlog::set_default_logger(main_logger);
}
+void shutdown_logging_system() {
+#ifdef WINDOWS
+ // Under VisualStudio, this must be called before main finishes to workaround
+ // a known VS issue
+ spdlog::drop_all();
+ spdlog::shutdown();
+#endif
+}
+
void init_global_path_env() {
auto& settings =
GpgFrontend::GlobalSettingStation::GetInstance().GetUISettings();
diff --git a/src/main.cpp b/src/main.cpp
index 38c17d2a..98c02a0e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -74,6 +74,12 @@ extern void before_exit();
extern void init_logging_system();
/**
+ * @brief initialize the logging system.
+ *
+ */
+extern void shutdown_logging_system();
+
+/**
* @brief init global PATH env
*
*/
@@ -107,7 +113,10 @@ int main(int argc, char* argv[]) {
init_logging_system();
// init the logging system for core
- GpgFrontend::InitLoggingSystem();
+ GpgFrontend::InitCoreLoggingSystem();
+
+ // init the logging system for ui
+ GpgFrontend::UI::InitUILoggingSystem();
// change path to search for related
init_global_path_env();
@@ -165,6 +174,15 @@ int main(int argc, char* argv[]) {
} while (return_from_event_loop_code == DEEP_RESTART_CODE ||
return_from_event_loop_code == CRASH_CODE);
+
+ // shutdown the logging system for ui
+ GpgFrontend::UI::ShutdownUILoggingSystem();
+
+ // shutdown the logging system for core
+ GpgFrontend::ShutdownCoreLoggingSystem();
+
+
+
// log for debug
SPDLOG_INFO("GpgFrontend about to exit.");
diff --git a/src/signal.cpp b/src/signal.cpp
index 09ac48c0..da4dfb39 100644
--- a/src/signal.cpp
+++ b/src/signal.cpp
@@ -43,7 +43,8 @@ extern jmp_buf recover_env;
*/
void handle_signal(int sig) {
static int _repeat_handle_num = 1, last_sig = sig;
- SPDLOG_DEBUG("signal caught {}", sig);
+ // SPDLOG_DEBUG("signal caught {}", sig);
+ std::cout << "signal caught" << sig;
if (last_sig == sig)
_repeat_handle_num++;
@@ -51,9 +52,8 @@ void handle_signal(int sig) {
_repeat_handle_num = 1, last_sig = sig;
if (_repeat_handle_num > 3) {
- SPDLOG_DEBUG(
- "The same signal appears three times, execute the termination "
- "operation. ");
+ std::cout << "The same signal appears three times,"
+ << "execute the termination operation." << sig;
exit(-1);
}
diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp
index 999e597a..940cf82b 100644
--- a/src/ui/GpgFrontendUIInit.cpp
+++ b/src/ui/GpgFrontendUIInit.cpp
@@ -50,8 +50,6 @@ extern void init_logging_system();
extern void init_locale();
void InitGpgFrontendUI(QApplication* app) {
- // init logging system
- init_logging_system();
// init locale
init_locale();
@@ -131,7 +129,7 @@ int RunGpgFrontendUI(QApplication* app) {
return app->exec();
}
-void init_logging_system() {
+void InitUILoggingSystem() {
using namespace boost::posix_time;
using namespace boost::gregorian;
@@ -168,6 +166,15 @@ void init_logging_system() {
spdlog::set_default_logger(ui_logger);
}
+void ShutdownUILoggingSystem() {
+#ifdef WINDOWS
+ // Under VisualStudio, this must be called before main finishes to workaround
+ // a known VS issue
+ spdlog::drop_all();
+ spdlog::shutdown();
+#endif
+}
+
/**
* @brief setup the locale and load the translations
*
@@ -202,7 +209,7 @@ void init_locale() {
SPDLOG_DEBUG("project name: {}", PROJECT_NAME);
SPDLOG_DEBUG(
"locales path: {}",
- GpgFrontend::GlobalSettingStation::GetInstance().GetLocaleDir().c_str());
+ GpgFrontend::GlobalSettingStation::GetInstance().GetLocaleDir().u8string());
#ifndef WINDOWS
if (!lang.empty()) {
@@ -210,14 +217,14 @@ void init_locale() {
// set LC_ALL
auto* locale_name = setlocale(LC_ALL, lc.c_str());
- if (locale_name == nullptr) SPDLOG_WARN("set LC_ALL failed: {}", lc);
+ if (locale_name == nullptr) SPDLOG_WARN("set LC_ALL failed, lc: {}", lc);
auto language = getenv("LANGUAGE");
// set LANGUAGE
std::string language_env = language == nullptr ? "en" : language;
language_env.insert(0, lang + ":");
SPDLOG_DEBUG("language env: {}", language_env);
if (setenv("LANGUAGE", language_env.c_str(), 1)) {
- SPDLOG_WARN("set LANGUAGE failed", language_env);
+ SPDLOG_WARN("set LANGUAGE {} failed", language_env);
};
}
#else
@@ -226,7 +233,7 @@ void init_locale() {
// set LC_ALL
auto* locale_name = setlocale(LC_ALL, lc.c_str());
- if (locale_name == nullptr) SPDLOG_WARN("set LC_ALL failed", lc);
+ if (locale_name == nullptr) SPDLOG_WARN("set LC_ALL failed, lc: {}", lc);
auto language = getenv("LANGUAGE");
// set LANGUAGE
diff --git a/src/ui/GpgFrontendUIInit.h b/src/ui/GpgFrontendUIInit.h
index 9b490c0f..0e68aa57 100644
--- a/src/ui/GpgFrontendUIInit.h
+++ b/src/ui/GpgFrontendUIInit.h
@@ -40,6 +40,18 @@ namespace GpgFrontend::UI {
void GPGFRONTEND_UI_EXPORT InitGpgFrontendUI(QApplication *);
/**
+ * @brief
+ *
+ */
+void GPGFRONTEND_UI_EXPORT InitUILoggingSystem();
+
+/**
+ * @brief
+ *
+ */
+void GPGFRONTEND_UI_EXPORT ShutdownUILoggingSystem();
+
+/**
* @brief run main window
*/
int GPGFRONTEND_UI_EXPORT RunGpgFrontendUI(QApplication *);