aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/GpgFrontendUIInit.cpp
diff options
context:
space:
mode:
authorSaturn&Eric <[email protected]>2023-02-25 11:49:54 +0000
committerGitHub <[email protected]>2023-02-25 11:49:54 +0000
commitaf1cd680f2496629026ba27707cef2afd860f5f9 (patch)
tree78e78450893e98b8828cc41010e377c1561e5f34 /src/ui/GpgFrontendUIInit.cpp
parentfix: improve manual (diff)
parentfeat: use aqt to install qt in ci build (diff)
downloadGpgFrontend-af1cd680f2496629026ba27707cef2afd860f5f9.tar.gz
GpgFrontend-af1cd680f2496629026ba27707cef2afd860f5f9.zip
Merge pull request #91 from saturneric/dev/2.0.10/main
Develop 2.1.0.1
Diffstat (limited to '')
-rw-r--r--src/ui/GpgFrontendUIInit.cpp109
1 files changed, 59 insertions, 50 deletions
diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp
index 5cbca31b..6e41f81f 100644
--- a/src/ui/GpgFrontendUIInit.cpp
+++ b/src/ui/GpgFrontendUIInit.cpp
@@ -28,6 +28,11 @@
#include "GpgFrontendUIInit.h"
+#include <spdlog/async.h>
+#include <spdlog/common.h>
+#include <spdlog/sinks/rotating_file_sink.h>
+#include <spdlog/sinks/stdout_color_sinks.h>
+
#include "core/function/GlobalSettingStation.h"
#include "core/thread/CtxCheckTask.h"
#include "core/thread/TaskRunnerGetter.h"
@@ -39,18 +44,12 @@
#include "core/function/GlobalSettingStation.h"
#endif
-// init easyloggingpp library
-INITIALIZE_EASYLOGGINGPP
-
namespace GpgFrontend::UI {
extern void init_logging_system();
extern void init_locale();
void InitGpgFrontendUI(QApplication* app) {
- // init logging system
- init_logging_system();
-
// init locale
init_locale();
@@ -88,15 +87,15 @@ void InitGpgFrontendUI(QApplication* app) {
waiting_dialog_label->setWordWrap(true);
waiting_dialog->setLabel(waiting_dialog_label);
waiting_dialog->resize(420, 120);
- app->connect(init_ctx_task, &Thread::CtxCheckTask::SignalTaskFinished,
+ app->connect(init_ctx_task, &Thread::CtxCheckTask::SignalTaskEnd,
waiting_dialog, [=]() {
- LOG(INFO) << "Gpg context loaded";
+ SPDLOG_DEBUG("gpg context loaded");
waiting_dialog->finished(0);
waiting_dialog->deleteLater();
});
app->connect(waiting_dialog, &QProgressDialog::canceled, [=]() {
- LOG(INFO) << "cancel clicked";
+ SPDLOG_DEBUG("cancel clicked");
app->quit();
exit(0);
});
@@ -108,8 +107,8 @@ void InitGpgFrontendUI(QApplication* app) {
// new local event looper
QEventLoop looper;
- app->connect(init_ctx_task, &Thread::CtxCheckTask::SignalTaskFinished,
- &looper, &QEventLoop::quit);
+ app->connect(init_ctx_task, &Thread::CtxCheckTask::SignalTaskEnd, &looper,
+ &QEventLoop::quit);
// start the thread to load the gpg context
Thread::TaskRunnerGetter::GetInstance().GetTaskRunner()->PostTask(
@@ -123,46 +122,56 @@ int RunGpgFrontendUI(QApplication* app) {
// create main window and show it
auto main_window = std::make_unique<GpgFrontend::UI::MainWindow>();
main_window->Init();
- LOG(INFO) << "Main window inited";
+ SPDLOG_DEBUG("main window inited");
main_window->show();
// start the main event loop
return app->exec();
}
-void init_logging_system() {
+void InitUILoggingSystem() {
using namespace boost::posix_time;
using namespace boost::gregorian;
- el::Loggers::addFlag(el::LoggingFlag::AutoSpacing);
- el::Loggers::addFlag(el::LoggingFlag::ColoredTerminalOutput);
- el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
-
- el::Configurations defaultConf;
- defaultConf.setToDefault();
+ // get the log directory
+ auto logfile_path = (GlobalSettingStation::GetInstance().GetLogDir() / "ui");
+ logfile_path.replace_extension(".log");
- // apply settings
- defaultConf.setGlobally(el::ConfigurationType::Format,
- "%datetime %level [ui] {%func} -> %msg");
+ // sinks
+ std::vector<spdlog::sink_ptr> sinks;
+ sinks.push_back(std::make_shared<spdlog::sinks::stderr_color_sink_mt>());
+ sinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>(
+ logfile_path.u8string(), 1048576 * 32, 32));
- // apply settings no written to file
- defaultConf.setGlobally(el::ConfigurationType::ToFile, "false");
+ // thread pool
+ spdlog::init_thread_pool(1024, 2);
- // apply settings
- el::Loggers::reconfigureLogger("default", defaultConf)->reconfigure();
+ // logger
+ auto ui_logger = std::make_shared<spdlog::async_logger>(
+ "ui", begin(sinks), end(sinks), spdlog::thread_pool());
+ ui_logger->set_pattern(
+ "[%H:%M:%S.%e] [T:%t] [%=4n] %^[%=8l]%$ [%s:%#] [%!] -> %v (+%ius)");
- // get the log directory
- auto logfile_path = (GlobalSettingStation::GetInstance().GetLogDir() /
- to_iso_string(second_clock::local_time()));
- logfile_path.replace_extension(".log");
- defaultConf.setGlobally(el::ConfigurationType::Filename,
- logfile_path.u8string());
+#ifdef DEBUG
+ ui_logger->set_level(spdlog::level::trace);
+#else
+ ui_logger->set_level(spdlog::level::info);
+#endif
- // apply settings written to file
- defaultConf.setGlobally(el::ConfigurationType::ToFile, "false");
+ // flush policy
+ ui_logger->flush_on(spdlog::level::err);
+ spdlog::flush_every(std::chrono::seconds(5));
- el::Loggers::reconfigureLogger("default", defaultConf);
+ // register it as default logger
+ spdlog::set_default_logger(ui_logger);
+}
- LOG(INFO) << _("log file path") << logfile_path;
+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
}
/**
@@ -187,20 +196,20 @@ void init_locale() {
// sync the settings to the file
GpgFrontend::GlobalSettingStation::GetInstance().SyncSettings();
- LOG(INFO) << "current system locale" << setlocale(LC_ALL, nullptr);
+ SPDLOG_DEBUG("current system locale: {}", setlocale(LC_ALL, nullptr));
// read from settings file
std::string lang;
if (!general.lookupValue("lang", lang)) {
- LOG(ERROR) << _("could not read properly from configure file");
+ SPDLOG_ERROR(_("could not read properly from configure file"));
};
- LOG(INFO) << "lang from settings" << lang;
- LOG(INFO) << "project name" << PROJECT_NAME;
- LOG(INFO) << "locales path"
- << GpgFrontend::GlobalSettingStation::GetInstance()
+ SPDLOG_DEBUG("lang from settings: {}", lang);
+ SPDLOG_DEBUG("project name: {}", PROJECT_NAME);
+ SPDLOG_DEBUG("locales path: {}",
+ GpgFrontend::GlobalSettingStation::GetInstance()
.GetLocaleDir()
- .c_str();
+ .u8string());
#ifndef WINDOWS
if (!lang.empty()) {
@@ -208,14 +217,14 @@ void init_locale() {
// set LC_ALL
auto* locale_name = setlocale(LC_ALL, lc.c_str());
- if (locale_name == nullptr) LOG(WARNING) << "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 + ":");
- LOG(INFO) << "language env" << language_env;
+ SPDLOG_DEBUG("language env: {}", language_env);
if (setenv("LANGUAGE", language_env.c_str(), 1)) {
- LOG(WARNING) << "set LANGUAGE failed" << language_env;
+ SPDLOG_WARN("set LANGUAGE {} failed", language_env);
};
}
#else
@@ -224,16 +233,16 @@ void init_locale() {
// set LC_ALL
auto* locale_name = setlocale(LC_ALL, lc.c_str());
- if (locale_name == nullptr) LOG(WARNING) << "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 + ":");
language_env.insert(0, "LANGUAGE=");
- LOG(INFO) << "language env" << language_env;
+ SPDLOG_DEBUG("language env: {}", language_env);
if (putenv(language_env.c_str())) {
- LOG(WARNING) << "set LANGUAGE failed" << language_env;
+ SPDLOG_WARN("set LANGUAGE {} failed", language_env);
};
}
#endif
@@ -246,4 +255,4 @@ void init_locale() {
textdomain(PROJECT_NAME);
}
-} // namespace GpgFrontend::UI \ No newline at end of file
+} // namespace GpgFrontend::UI