diff options
author | Saturneric <[email protected]> | 2023-02-03 13:43:55 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2023-02-03 13:43:55 +0000 |
commit | 11d32517c2f6f538209c893c6b0b24572fba1a36 (patch) | |
tree | 0dac14bcad75d9c7c5b5723dc23e6409721966b4 | |
parent | feat: change logging framework to spdlog (diff) | |
download | GpgFrontend-11d32517c2f6f538209c893c6b0b24572fba1a36.tar.gz GpgFrontend-11d32517c2f6f538209c893c6b0b24572fba1a36.zip |
feat: change the log style in source files
71 files changed, 677 insertions, 700 deletions
diff --git a/src/GpgFrontend.h.in b/src/GpgFrontend.h.in index 2ef8ddc2..f441fb8f 100644 --- a/src/GpgFrontend.h.in +++ b/src/GpgFrontend.h.in @@ -57,6 +57,7 @@ // logging system +#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE #include <spdlog/spdlog.h> // build info diff --git a/src/before_exit.cpp b/src/before_exit.cpp index f13649db..70768e05 100644 --- a/src/before_exit.cpp +++ b/src/before_exit.cpp @@ -32,4 +32,4 @@ * @brief Actions performed before exiting the application * */ -void before_exit() { LOG(INFO) << "called"; } +void before_exit() { SPDLOG_INFO("called"); } diff --git a/src/core/GpgConstants.cpp b/src/core/GpgConstants.cpp index ff783872..4f781ece 100644 --- a/src/core/GpgConstants.cpp +++ b/src/core/GpgConstants.cpp @@ -53,9 +53,8 @@ const char* GpgFrontend::GpgConstants::GPG_FRONTEND_SHORT_CRYPTO_HEAD = gpgme_error_t GpgFrontend::check_gpg_error(gpgme_error_t err) { if (gpg_err_code(err) != GPG_ERR_NO_ERROR) { - LOG(ERROR) << "[" << _("Error") << gpg_err_code(err) << "]" << _("Source: ") - << gpgme_strsource(err) << _("Description: ") - << gpgme_strerror(err); + SPDLOG_ERROR("[error: {}] source: {} description: {}", gpg_err_code(err), + gpgme_strsource(err), gpgme_strerror(err)); } return err; } @@ -65,14 +64,13 @@ gpg_err_code_t GpgFrontend::check_gpg_error_2_err_code(gpgme_error_t err, auto err_code = gpg_err_code(err); if (err_code != gpg_err_code(predict)) { if (err_code == GPG_ERR_NO_ERROR) - LOG(WARNING) << "[" << _("Warning") << gpg_err_code(err) << "]" - << _("Source: ") << gpgme_strsource(err) - << _("Description: ") << gpgme_strerror(err) << _("Predict") - << gpgme_strerror(err); + SPDLOG_WARN("[Warning {}] Source: {} description: {} predict: {}", + gpg_err_code(err), gpgme_strsource(err), gpgme_strerror(err), + gpgme_strerror(err)); else - LOG(ERROR) << "[" << _("Error") << gpg_err_code(err) << "]" - << _("Source: ") << gpgme_strsource(err) << _("Description: ") - << gpgme_strerror(err) << _("Predict") << gpgme_strerror(err); + SPDLOG_ERROR("[Error {}] Source: {} description: {} predict: {}", + gpg_err_code(err), gpgme_strsource(err), gpgme_strerror(err), + gpgme_strerror(err)); } return err_code; } @@ -80,9 +78,9 @@ gpg_err_code_t GpgFrontend::check_gpg_error_2_err_code(gpgme_error_t err, gpgme_error_t GpgFrontend::check_gpg_error(gpgme_error_t err, const std::string& comment) { if (gpg_err_code(err) != GPG_ERR_NO_ERROR) { - LOG(ERROR) << "[" << _("Error") << gpg_err_code(err) << "]" << _("Source: ") - << gpgme_strsource(err) << _("Description: ") - << gpgme_strerror(err); + SPDLOG_WARN("[Error {}] Source: {} description: {} predict: {}", + gpg_err_code(err), gpgme_strsource(err), gpgme_strerror(err), + gpgme_strerror(err)); } return err; } @@ -201,6 +199,6 @@ GpgFrontend::GpgGenKeyResult GpgFrontend::_new_result( } void GpgFrontend::_result_ref_deletor::operator()(void* _result) { - DLOG(INFO) << _("Called") << _result; + SPDLOG_INFO("called {}", _result); if (_result != nullptr) gpgme_result_unref(_result); } diff --git a/src/core/GpgContext.cpp b/src/core/GpgContext.cpp index 59e21b84..bfc5b556 100644 --- a/src/core/GpgContext.cpp +++ b/src/core/GpgContext.cpp @@ -52,7 +52,7 @@ GpgContext::GpgContext(const GpgContextInitArgs &args) : args_(args) { if (_first) { /* Initialize the locale environment. */ - LOG(INFO) << "locale" << setlocale(LC_CTYPE, nullptr); + SPDLOG_INFO("locale: {}", setlocale(LC_CTYPE, nullptr)); info_.GpgMEVersion = gpgme_check_version(nullptr); gpgme_set_locale(nullptr, LC_CTYPE, setlocale(LC_CTYPE, nullptr)); #ifdef LC_MESSAGES @@ -84,15 +84,14 @@ GpgContext::GpgContext(const GpgContextInitArgs &args) : args_(args) { continue; } - LOG(INFO) << gpgme_get_protocol_name(engine_info->protocol) - << std::string(engine_info->file_name == nullptr - ? "null" - : engine_info->file_name) - << std::string(engine_info->home_dir == nullptr - ? "null" - : engine_info->home_dir) - << std::string(engine_info->version ? "null" - : engine_info->version); + SPDLOG_INFO( + "engine info: {} {} {} {}", + gpgme_get_protocol_name(engine_info->protocol), + std::string(engine_info->file_name == nullptr ? "null" + : engine_info->file_name), + std::string(engine_info->home_dir == nullptr ? "null" + : engine_info->home_dir), + std::string(engine_info->version ? "null" : engine_info->version)); switch (engine_info->protocol) { case GPGME_PROTOCOL_OpenPGP: @@ -134,7 +133,7 @@ GpgContext::GpgContext(const GpgContextInitArgs &args) : args_(args) { auto err = gpgme_ctx_set_engine_info(_ctx_ref.get(), GPGME_PROTOCOL_OpenPGP, info_.AppPath.c_str(), info_.DatabasePath.c_str()); - LOG(INFO) << "ctx set custom key db path:" << info_.DatabasePath; + SPDLOG_INFO("ctx set custom key db path: {}", info_.DatabasePath); assert(check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR); } @@ -146,10 +145,10 @@ GpgContext::GpgContext(const GpgContextInitArgs &args) : args_(args) { if (!check_passed) { this->good_ = false; - LOG(ERROR) << "Env check failed"; + SPDLOG_ERROR("env check failed"); return; } else { - LOG(INFO) << "gnupg version" << info_.GnupgVersion; + SPDLOG_INFO("gnupg version {}", info_.GnupgVersion); init_ctx(); good_ = true; } @@ -159,7 +158,7 @@ void GpgContext::init_ctx() { // Set Independent Database if (info_.GnupgVersion <= "2.0.0" && args_.independent_database) { info_.DatabasePath = args_.db_path; - LOG(INFO) << "custom key db path" << info_.DatabasePath; + SPDLOG_INFO("custom key db path {}", info_.DatabasePath); auto err = gpgme_ctx_set_engine_info(_ctx_ref.get(), GPGME_PROTOCOL_OpenPGP, info_.AppPath.c_str(), info_.DatabasePath.c_str()); @@ -195,7 +194,6 @@ void GpgContext::init_ctx() { // for unit test if (args_.test_mode) { - LOG(INFO) << "test mode"; if (info_.GnupgVersion >= "2.1.0") SetPassphraseCb(test_passphrase_cb); gpgme_set_status_cb(*this, test_status_cb, nullptr); } @@ -210,7 +208,7 @@ void GpgContext::SetPassphraseCb(gpgme_passphrase_cb_t cb) const { } gpgme_set_passphrase_cb(*this, cb, nullptr); } else { - LOG(ERROR) << "Not supported for gnupg version" << info_.GnupgVersion; + SPDLOG_ERROR("not supported for gnupg version: {}", info_.GnupgVersion); } } @@ -233,7 +231,7 @@ gpgme_error_t GpgContext::test_passphrase_cb(void *opaque, const char *uid_hint, gpgme_error_t GpgContext::test_status_cb(void *hook, const char *keyword, const char *args) { - LOG(INFO) << "keyword" << keyword; + SPDLOG_INFO("keyword {}", keyword); return GPG_ERR_NO_ERROR; } @@ -242,12 +240,15 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { GpgCommandExecutor::GetInstance().Execute( info_.GpgConfPath, {"--list-components"}, [=](int exit_code, const std::string &p_out, const std::string &p_err) { - LOG(INFO) << "gpgconf components exit_code" << exit_code - << "process stdout size" << p_out.size(); + SPDLOG_INFO( + "gpgconf components exit_code: {} process stdout size: {}", + exit_code, p_out.size()); if (exit_code != 0) { - LOG(ERROR) << "gpgconf execute error, process stderr:" << p_err - << ", process stdout:" << p_out; + SPDLOG_ERROR( + "gpgconf execute error, process stderr: {} ,process stdout: " + "{}", + p_err, p_out); return; } @@ -263,8 +264,8 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { for (const auto &line : line_split_list) { std::vector<std::string> info_split_list; boost::split(info_split_list, line, boost::is_any_of(":")); - LOG(INFO) << "gpgconf info line" << line << "info size" - << info_split_list.size(); + SPDLOG_INFO("gpgconf info line: {} info size: {}", line, + info_split_list.size()); if (info_split_list.size() != 3) continue; @@ -282,12 +283,14 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { GpgCommandExecutor::GetInstance().Execute( info_.GpgConfPath, {"--list-dirs"}, [=](int exit_code, const std::string &p_out, const std::string &p_err) { - LOG(INFO) << "gpgconf configurations exit_code" << exit_code - << "process stdout size" << p_out.size(); + SPDLOG_INFO( + "gpgconf configurations exit_code: {} process stdout size: {}", + exit_code, p_out.size()); if (exit_code != 0) { - LOG(ERROR) << "gpgconf execute error, process stderr:" << p_err - << ", process stdout:" << p_out; + SPDLOG_ERROR( + "gpgconf execute error, process stderr: {} process stdout: {}", + p_err, p_out); return; } @@ -299,8 +302,8 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { for (const auto &line : line_split_list) { std::vector<std::string> info_split_list; boost::split(info_split_list, line, boost::is_any_of(":")); - LOG(INFO) << "gpgconf info line" << line << "info size" - << info_split_list.size(); + SPDLOG_INFO("gpgconf info line: {} info size: {}", line, + info_split_list.size()); if (info_split_list.size() != 2) continue; @@ -310,8 +313,7 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { }); for (const auto &component : info_.ComponentsInfo) { - LOG(INFO) << "gpgconf check options ready" - << "component" << component.first; + SPDLOG_INFO("gpgconf check options ready", "component", component.first); if (component.first == "gpgme" || component.first == "gpgconf") continue; @@ -319,13 +321,15 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { info_.GpgConfPath, {"--check-options", component.first}, [=](int exit_code, const std::string &p_out, const std::string &p_err) { - LOG(INFO) << "gpgconf options exit_code" << exit_code - << "process stdout size" << p_out.size() << "component" - << component.first; + SPDLOG_INFO( + "gpgconf options exit_code: {} process stdout size: {} " + "component: {} ", + exit_code, p_out.size(), component.first); if (exit_code != 0) { - LOG(ERROR) << "gpgconf execute error, process stderr:" << p_err - << ", process stdout:" << p_out; + SPDLOG_ERROR( + "gpgconf execute error, process stderr: {} , process stdout:", + p_err, p_out); return; } @@ -338,8 +342,8 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { std::vector<std::string> info_split_list; boost::split(info_split_list, line, boost::is_any_of(":")); - LOG(INFO) << "gpgconf info line" << line << "info size" - << info_split_list.size(); + SPDLOG_INFO("gpgconf info line: {} info size: {}", line, + info_split_list.size()); if (info_split_list.size() != 6) continue; @@ -352,8 +356,7 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { } for (const auto &component : info_.ComponentsInfo) { - LOG(INFO) << "gpgconf list options ready" - << "component" << component.first; + SPDLOG_INFO("gpgconf list options ready", "component", component.first); if (component.first == "gpgme" || component.first == "gpgconf") continue; @@ -361,13 +364,15 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { info_.GpgConfPath, {"--list-options", component.first}, [=](int exit_code, const std::string &p_out, const std::string &p_err) { - LOG(INFO) << "gpgconf options exit_code" << exit_code - << "process stdout size" << p_out.size() << "component" - << component.first; + SPDLOG_INFO( + "gpgconf options exit_code: {} process stdout size: {} " + "component: {} ", + exit_code, p_out.size(), component.first); if (exit_code != 0) { - LOG(ERROR) << "gpgconf execute error, process stderr:" << p_err - << ", process stdout:" << p_out; + SPDLOG_ERROR( + "gpgconf execute error, process stderr: {} , process stdout:", + p_err, p_out); return; } @@ -380,8 +385,8 @@ const GpgInfo &GpgContext::GetInfo(bool refresh) { std::vector<std::string> info_split_list; boost::split(info_split_list, line, boost::is_any_of(":")); - LOG(INFO) << "gpgconf info line" << line << "info size" - << info_split_list.size(); + SPDLOG_INFO("gpgconf info line: {} info size: {}", line, + info_split_list.size()); if (info_split_list.size() != 10) continue; diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index 9ccc693d..d757c10c 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -25,16 +25,17 @@ * SPDX-License-Identifier: GPL-3.0-or-later * */ - #include "GpgCoreInit.h" +#include <spdlog/async.h> +#include <spdlog/common.h> +#include <spdlog/sinks/rotating_file_sink.h> +#include <spdlog/sinks/stdout_color_sinks.h> + #include "GpgFunctionObject.h" #include "core/GpgContext.h" #include "core/function/GlobalSettingStation.h" -// init easyloggingpp library -INITIALIZE_EASYLOGGINGPP - namespace GpgFrontend { /** @@ -45,36 +46,34 @@ void InitLoggingSystem() { 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(); - - // apply settings - defaultConf.setGlobally(el::ConfigurationType::Format, - "%datetime %level [core] {%func} -> %msg"); - - // apply settings no written to file - defaultConf.setGlobally(el::ConfigurationType::ToFile, "false"); - - // set the logger - el::Loggers::reconfigureLogger("default", defaultConf); - // get the log directory - auto logfile_path = (GlobalSettingStation::GetInstance().GetLogDir() / - to_iso_string(second_clock::local_time())); + auto logfile_path = + (GlobalSettingStation::GetInstance().GetLogDir() / "core"); logfile_path.replace_extension(".log"); - defaultConf.setGlobally(el::ConfigurationType::Filename, - logfile_path.u8string()); - - // apply settings written to file - defaultConf.setGlobally(el::ConfigurationType::ToFile, "true"); - - // set the logger - el::Loggers::reconfigureLogger("default", defaultConf); - LOG(INFO) << _("log file path") << logfile_path; + // 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, 8)); + + // thread pool + spdlog::init_thread_pool(1024, 2); + + // logger + auto core_logger = std::make_shared<spdlog::async_logger>( + "core", begin(sinks), end(sinks), spdlog::thread_pool()); + core_logger->set_pattern( + "[%H:%M:%S.%e] [T:%t] [%=4n] %^[%=8l]%$ [%s:%#] [%!] -> %v (+%ius)"); + +#ifdef DEBUG + core_logger->set_level(spdlog::level::trace); +#elif + core_logger->set_level(spdlog::level::info); +#endif + + // register it as default logger + spdlog::set_default_logger(core_logger); } void ResetGpgFrontendCore() { reset_gpgfrontend_core(); } @@ -89,12 +88,11 @@ void init_gpgfrontend_core() { use_custom_key_database_path = settings.lookup("general.use_custom_key_database_path"); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") - << _("use_custom_key_database_path"); + SPDLOG_ERROR("setting operation error: use_custom_key_database_path"); } - LOG(INFO) << "core loaded if use custom key databse path: " - << use_custom_key_database_path; + SPDLOG_INFO("core loaded if use custom key databse path: {}", + use_custom_key_database_path); std::string custom_key_database_path; try { @@ -104,11 +102,11 @@ void init_gpgfrontend_core() { settings.lookup("general.custom_key_database_path")); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("custom_key_database_path"); + SPDLOG_ERROR("setting operation error: custom_key_database_path"); } - LOG(INFO) << "core loaded custom key databse path: " - << custom_key_database_path; + SPDLOG_INFO("core loaded custom key databse path: {}", + custom_key_database_path); // init default channel GpgFrontend::GpgContext::CreateInstance( diff --git a/src/core/GpgFunctionObject.cpp b/src/core/GpgFunctionObject.cpp index 6ff83d72..3956e31e 100644 --- a/src/core/GpgFunctionObject.cpp +++ b/src/core/GpgFunctionObject.cpp @@ -34,8 +34,6 @@ #include <mutex> #include <shared_mutex> -#include "easylogging++.h" - void GpgFrontend::ChannelObject::SetChannel(int channel) { this->channel_ = channel; } @@ -79,8 +77,8 @@ std::vector<int> GpgFrontend::SingletonStorage::GetAllChannelId() { GpgFrontend::ChannelObject* GpgFrontend::SingletonStorage::SetObjectInChannel( int channel, std::unique_ptr<ChannelObject> p_obj) { { - LOG(TRACE) << "set channel:" << channel - << "instance address:" << &instances_map_; + SPDLOG_TRACE("set channel: {} instance address: {}", channel, + static_cast<void*>(&instances_map_)); assert(p_obj != nullptr); if (p_obj == nullptr) return nullptr; @@ -111,9 +109,8 @@ GpgFrontend::SingletonStorageCollection::GetSingletonStorage( std::unique_lock<std::shared_mutex> lock(storages_mutex_); storages_map_.insert({hash, std::make_unique<SingletonStorage>()}); } - LOG(TRACE) << "hash:" << hash << "created" - << "storage address:" << &storages_map_ - << "type_name : " << type_id.name(); + SPDLOG_TRACE("hash: {} created, storage address: {} type_name: {}", hash, + static_cast<void*>(&storages_map_), type_id.name()); continue; } else { return _it->second.get(); @@ -128,7 +125,8 @@ GpgFrontend::SingletonStorageCollection::GetInstance( if (force_refresh || instance == nullptr) { instance = new SingletonStorageCollection(); - LOG(INFO) << "new single storage collection created: " << instance; + SPDLOG_INFO("new single storage collection created: {}", + static_cast<void*>(instance)); } return instance; diff --git a/src/core/GpgGenKeyInfo.cpp b/src/core/GpgGenKeyInfo.cpp index f9065529..ba60c92a 100644 --- a/src/core/GpgGenKeyInfo.cpp +++ b/src/core/GpgGenKeyInfo.cpp @@ -38,7 +38,7 @@ void GpgFrontend::GenKeyInfo::SetAlgo( const GpgFrontend::GenKeyInfo::KeyGenAlgo &m_algo) { - LOG(INFO) << "set algo name" << m_algo.first; + SPDLOG_INFO("set algo name: {}", m_algo.first); // Check algo if supported std::string algo_args = m_algo.second; if (standalone_) { diff --git a/src/core/common/CoreCommonUtil.cpp b/src/core/common/CoreCommonUtil.cpp index 3b2b4007..a19994a6 100644 --- a/src/core/common/CoreCommonUtil.cpp +++ b/src/core/common/CoreCommonUtil.cpp @@ -31,7 +31,7 @@ namespace GpgFrontend { std::unique_ptr<CoreCommonUtil> CoreCommonUtil::instance_ = nullptr; ///<
CoreCommonUtil *CoreCommonUtil::GetInstance() {
- LOG(INFO) << "called";
+ SPDLOG_INFO("called");
if (instance_ == nullptr) {
instance_ = std::make_unique<CoreCommonUtil>();
}
diff --git a/src/core/function/ArchiveFileOperator.cpp b/src/core/function/ArchiveFileOperator.cpp index 64c7389e..d8a798fb 100644 --- a/src/core/function/ArchiveFileOperator.cpp +++ b/src/core/function/ArchiveFileOperator.cpp @@ -38,14 +38,14 @@ int copy_data(struct archive *ar, struct archive *aw) { r = archive_read_data_block(ar, &buff, &size, &offset); if (r == ARCHIVE_EOF) return (ARCHIVE_OK); if (r != ARCHIVE_OK) { - LOG(ERROR) << "archive_read_data_block() failed: " - << archive_error_string(ar); + SPDLOG_ERROR("archive_read_data_block() failed: {}", + archive_error_string(ar)); return (r); } r = archive_write_data_block(aw, buff, size, offset); if (r != ARCHIVE_OK) { - LOG(ERROR) << "archive_write_data_block() failed: " - << archive_error_string(aw); + SPDLOG_ERROR("archive_write_data_block() failed: {}", + archive_error_string(aw)); return (r); } } @@ -55,7 +55,7 @@ void GpgFrontend::ArchiveFileOperator::CreateArchive( const std::filesystem::path &base_path, const std::filesystem::path &archive_path, int compress, const std::vector<std::filesystem::path> &files) { - LOG(INFO) << "CreateArchive: " << archive_path.u8string(); + SPDLOG_INFO("CreateArchive: {}", archive_path.u8string()); auto current_base_path_backup = QDir::currentPath(); QDir::setCurrent(base_path.u8string().c_str()); @@ -74,7 +74,7 @@ void GpgFrontend::ArchiveFileOperator::CreateArchive( ssize_t len; int fd; - LOG(INFO) << "compress: " << compress; + SPDLOG_INFO("compress: {}", compress); a = archive_write_new(); switch (compress) { @@ -119,7 +119,7 @@ void GpgFrontend::ArchiveFileOperator::CreateArchive( #endif int r; - LOG(INFO) << "reading file: " << file.u8string(); + SPDLOG_INFO("reading file: {}", file.u8string()); #ifdef WINDOWS r = archive_read_disk_open_w(disk, file.wstring().c_str()); @@ -127,11 +127,11 @@ void GpgFrontend::ArchiveFileOperator::CreateArchive( r = archive_read_disk_open(disk, file.u8string().c_str()); #endif - LOG(INFO) << "read file done: " << file.u8string(); + SPDLOG_INFO("read file done: {}", file.u8string()); if (r != ARCHIVE_OK) { - LOG(ERROR) << "archive_read_disk_open() failed: " - << archive_error_string(disk); + SPDLOG_ERROR("{archive_read_disk_open() failed: {}", + archive_error_string(disk)); throw std::runtime_error("archive_read_disk_open() failed"); } @@ -143,8 +143,8 @@ void GpgFrontend::ArchiveFileOperator::CreateArchive( if (r == ARCHIVE_EOF) break; if (r != ARCHIVE_OK) { - LOG(ERROR) << "archive_read_next_header2() failed: " - << archive_error_string(disk); + SPDLOG_ERROR("archive_read_next_header2() failed: {}", + archive_error_string(disk)); throw std::runtime_error("archive_read_next_header2() failed"); } archive_read_disk_descend(disk); @@ -158,14 +158,14 @@ void GpgFrontend::ArchiveFileOperator::CreateArchive( auto entry_path = std::string(archive_entry_pathname_utf8(entry)); #endif - LOG(INFO) << "Adding: " << archive_entry_pathname_utf8(entry) << "size" - << archive_entry_size(entry) << " bytes" - << "file type" << archive_entry_filetype(entry); + SPDLOG_INFO("Adding: {} size: {} bytes: {} file type: {}", + archive_entry_pathname_utf8(entry), archive_entry_size(entry), + archive_entry_filetype(entry)); r = archive_write_header(a, entry); if (r < ARCHIVE_OK) { - LOG(ERROR) << "archive_write_header() failed: " - << archive_error_string(a); + SPDLOG_ERROR("archive_write_header() failed: {}", + archive_error_string(a)); throw std::runtime_error("archive_write_header() failed"); } if (r == ARCHIVE_FATAL) throw std::runtime_error("archive fatal"); @@ -193,7 +193,7 @@ void GpgFrontend::ArchiveFileOperator::CreateArchive( void GpgFrontend::ArchiveFileOperator::ExtractArchive( const std::filesystem::path &archive_path, const std::filesystem::path &base_path) { - LOG(INFO) << "ExtractArchive: " << archive_path.u8string(); + SPDLOG_INFO("ExtractArchive: {}", archive_path.u8string()); auto current_base_path_backup = QDir::currentPath(); QDir::setCurrent(base_path.u8string().c_str()); @@ -228,7 +228,7 @@ void GpgFrontend::ArchiveFileOperator::ExtractArchive( auto filename = archive_path.u8string(); if (!filename.empty() && filename == u8"-") { - LOG(ERROR) << "cannot read from stdin"; + SPDLOG_ERROR("cannot read from stdin"); } #ifdef WINDOWS if (archive_read_open_filename_w(a, archive_path.wstring().c_str(), 10240) != @@ -237,29 +237,29 @@ void GpgFrontend::ArchiveFileOperator::ExtractArchive( if (archive_read_open_filename(a, archive_path.u8string().c_str(), 10240) != ARCHIVE_OK) { #endif - LOG(ERROR) << "archive_read_open_filename() failed: " - << archive_error_string(a); + SPDLOG_ERROR("archive_read_open_filename() failed: {}", + archive_error_string(a)); throw std::runtime_error("archive_read_open_filename() failed"); } for (;;) { r = archive_read_next_header(a, &entry); if (r == ARCHIVE_EOF) break; if (r != ARCHIVE_OK) { - LOG(ERROR) << "archive_read_next_header() failed: " - << archive_error_string(a); + SPDLOG_ERROR("archive_read_next_header() failed: {}", + archive_error_string(a)); throw std::runtime_error("archive_read_next_header() failed"); } - LOG(INFO) << "Extracting: " << archive_entry_pathname(entry) << "size" - << archive_entry_size(entry) << " bytes" - << "file type" << archive_entry_filetype(entry); + SPDLOG_INFO("Adding: {} size: {} bytes: {} file type: {}", + archive_entry_pathname_utf8(entry), archive_entry_size(entry), + archive_entry_filetype(entry)); r = archive_write_header(ext, entry); if (r != ARCHIVE_OK) { - LOG(ERROR) << "archive_write_header() failed: " - << archive_error_string(ext); + SPDLOG_ERROR("archive_write_header() failed: {}", + archive_error_string(ext)); } else { r = copy_data(a, ext); if (r != ARCHIVE_OK) { - LOG(ERROR) << "copy_data() failed: " << archive_error_string(ext); + SPDLOG_ERROR("copy_data() failed: {}", archive_error_string(ext)); } } } @@ -285,8 +285,8 @@ void GpgFrontend::ArchiveFileOperator::ListArchive( 10240); // Note 1 if (r != ARCHIVE_OK) return; while (archive_read_next_header(a, &entry) == ARCHIVE_OK) { - LOG(INFO) << "File: " << archive_entry_pathname(entry); - LOG(INFO) << "File Path: " << archive_entry_pathname(entry); + SPDLOG_INFO("File: {}", archive_entry_pathname(entry)); + SPDLOG_INFO("File Path: {}", archive_entry_pathname(entry)); archive_read_data_skip(a); // Note 2 } r = archive_read_free(a); // Note 3 diff --git a/src/core/function/CharsetOperator.cpp b/src/core/function/CharsetOperator.cpp index 81c23388..5b14261f 100644 --- a/src/core/function/CharsetOperator.cpp +++ b/src/core/function/CharsetOperator.cpp @@ -28,6 +28,7 @@ #include "core/function/CharsetOperator.h" +#include <spdlog/spdlog.h> #include <unicode/ucnv.h> #include <unicode/ucsdet.h> #include <unicode/ustring.h> @@ -37,8 +38,6 @@ #include <memory> #include <string> -#include "easylogging++.h" - GpgFrontend::CharsetOperator::CharsetInfo GpgFrontend::CharsetOperator::Detect( const std::string &buffer) { const UCharsetMatch *ucm; @@ -47,17 +46,17 @@ GpgFrontend::CharsetOperator::CharsetInfo GpgFrontend::CharsetOperator::Detect( status = U_ZERO_ERROR; if (U_FAILURE(status)) { - LOG(ERROR) << "Failed to open charset detector: " << u_errorName(status); + SPDLOG_ERROR("failed to open charset detector: {}", u_errorName(status)); return {"unknown", "unknown", 0}; } - LOG(INFO) << "Detecting charset buffer:" << buffer.size() << "bytes"; + SPDLOG_INFO("detecting charset buffer: {} bytes", buffer.size()); status = U_ZERO_ERROR; ucsdet_setText(csd, buffer.data(), buffer.size(), &status); if (U_FAILURE(status)) { - LOG(ERROR) << "Failed to set text to charset detector: " - << u_errorName(status); + SPDLOG_ERROR("failed to set text to charset detector: {}", + u_errorName(status)); return {"unknown", "unknown", 0}; } @@ -78,7 +77,7 @@ GpgFrontend::CharsetOperator::CharsetInfo GpgFrontend::CharsetOperator::Detect( const char *language = ucsdet_getLanguage(ucm, &status); if (U_FAILURE(status)) return {name, "unknown", confidence}; - LOG(INFO) << "Detected charset: " << name << language << confidence; + SPDLOG_INFO("Detected charset: {} {} {}", name, language, confidence); return {name, language, confidence}; } @@ -89,14 +88,14 @@ bool GpgFrontend::CharsetOperator::Convert2Utf8(const std::string &buffer, const auto from_encode = std::string("utf-8"); const auto to_encode = from_charset_name; - LOG(INFO) << "Converting buffer:" << buffer.size(); + SPDLOG_INFO("Converting buffer: {}", buffer.size()); // test if the charset is supported UConverter *conv = ucnv_open(from_encode.c_str(), &status); ucnv_close(conv); if (U_FAILURE(status)) { - LOG(ERROR) << "Failed to open converter: " << u_errorName(status) << ":" - << from_encode; + SPDLOG_ERROR("failed to open converter: {}, from encode: {}", + u_errorName(status), from_encode); return false; } @@ -104,8 +103,8 @@ bool GpgFrontend::CharsetOperator::Convert2Utf8(const std::string &buffer, conv = ucnv_open(to_encode.c_str(), &status); ucnv_close(conv); if (U_FAILURE(status)) { - LOG(ERROR) << "Failed to open converter: " << u_errorName(status) << ":" - << to_encode; + SPDLOG_ERROR("failed to open converter: {}, to encode: {}", + u_errorName(status), to_encode); return false; } @@ -127,10 +126,10 @@ bool GpgFrontend::CharsetOperator::Convert2Utf8(const std::string &buffer, } if (U_FAILURE(status)) { - LOG(ERROR) << "Failed to convert to utf-8: " << u_errorName(status); + SPDLOG_ERROR("failed to convert to utf-8: {}", u_errorName(status)); return false; } - LOG(INFO) << "Converted buffer:" << out_buffer.size() << "bytes"; + SPDLOG_INFO("converted buffer: {} bytes", out_buffer.size()); return true; }
\ No newline at end of file diff --git a/src/core/function/DataObjectOperator.cpp b/src/core/function/DataObjectOperator.cpp index 2744c448..a476bdfe 100644 --- a/src/core/function/DataObjectOperator.cpp +++ b/src/core/function/DataObjectOperator.cpp @@ -36,7 +36,7 @@ #include "core/function/PassphraseGenerator.h" void GpgFrontend::DataObjectOperator::init_app_secure_key() { - LOG(INFO) << "Initializing application secure key"; + SPDLOG_INFO("initializing application secure key"); FileOperator::WriteFileStd(app_secure_key_path_, PassphraseGenerator::GetInstance().Generate(256)); std::filesystem::permissions( @@ -54,13 +54,13 @@ GpgFrontend::DataObjectOperator::DataObjectOperator(int channel) std::string key; if (!FileOperator::ReadFileStd(app_secure_key_path_.u8string(), key)) { - LOG(FATAL) << _("Failed to read app secure key file") - << app_secure_key_path_; - throw std::runtime_error(_("Failed to read app secure key file")); + SPDLOG_ERROR("failed to read app secure key file: {}", + app_secure_key_path_.u8string()); + throw std::runtime_error("failed to read app secure key file"); } hash_key_ = QCryptographicHash::hash(QByteArray::fromStdString(key), QCryptographicHash::Sha256); - LOG(INFO) << "App secure key loaded" << hash_key_.size() << "bytes"; + SPDLOG_INFO("app secure key loaded {} bytes", hash_key_.size()); if (!exists(app_data_objs_path_)) create_directory(app_data_objs_path_); } @@ -93,8 +93,8 @@ std::string GpgFrontend::DataObjectOperator::SaveDataObj( auto encoded = encryption.encode(QByteArray::fromStdString(to_string(value)), hash_key_); - LOG(INFO) << _("Saving data object") << _hash_obj_key << "to" << obj_path - << encoded.size() << "bytes"; + SPDLOG_INFO("saving data object {} to {} , size: {} bytes", _hash_obj_key, + obj_path.u8string(), encoded.size()); FileOperator::WriteFileStd(obj_path.u8string(), encoded.toStdString()); @@ -104,7 +104,7 @@ std::string GpgFrontend::DataObjectOperator::SaveDataObj( std::optional<nlohmann::json> GpgFrontend::DataObjectOperator::GetDataObject( const std::string& _key) { try { - LOG(INFO) << _("Get data object") << _key; + SPDLOG_INFO("get data object {}", _key); auto _hash_obj_key = QCryptographicHash::hash(hash_key_ + QByteArray::fromStdString(_key), QCryptographicHash::Sha256) @@ -114,33 +114,33 @@ std::optional<nlohmann::json> GpgFrontend::DataObjectOperator::GetDataObject( const auto obj_path = app_data_objs_path_ / _hash_obj_key; if (!std::filesystem::exists(obj_path)) { - LOG(ERROR) << _("Data object not found") << _key; + SPDLOG_ERROR("data object not found :{}", _key); return {}; } std::string buffer; if (!FileOperator::ReadFileStd(obj_path.u8string(), buffer)) { - LOG(ERROR) << _("Failed to read data object") << _key; + SPDLOG_ERROR("failed to read data object: {}", _key); return {}; } - LOG(INFO) << _("Data object found") << _key; + SPDLOG_INFO("data object found {}", _key); auto encoded = QByteArray::fromStdString(buffer); QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::ECB, QAESEncryption::Padding::ISO); - LOG(INFO) << _("Decrypting data object") << encoded.size() - << hash_key_.size(); + SPDLOG_INFO("decrypting data object {} , hash key size: {}", encoded.size(), + hash_key_.size()); auto decoded = encryption.removePadding(encryption.decode(encoded, hash_key_)); - LOG(INFO) << _("Data object decoded") << _key; + SPDLOG_INFO("data object decoded: {}", _key); return nlohmann::json::parse(decoded.toStdString()); } catch (...) { - LOG(ERROR) << _("Failed to get data object") << _key; + SPDLOG_ERROR("failed to get data object: {}", _key); return {}; } } diff --git a/src/core/function/FileOperator.cpp b/src/core/function/FileOperator.cpp index fcbdb91c..63599bd1 100644 --- a/src/core/function/FileOperator.cpp +++ b/src/core/function/FileOperator.cpp @@ -32,7 +32,7 @@ bool GpgFrontend::FileOperator::ReadFile(const QString& file_name, QByteArray& data) { QFile file(file_name); if (!file.open(QIODevice::ReadOnly)) { - LOG(ERROR) << "failed to open file" << file_name.toStdString(); + SPDLOG_ERROR("failed to open file: {}", file_name.toStdString()); return false; } data = file.readAll(); @@ -44,7 +44,7 @@ bool GpgFrontend::FileOperator::WriteFile(const QString& file_name, const QByteArray& data) { QFile file(file_name); if (!file.open(QIODevice::WriteOnly)) { - LOG(ERROR) << "failed to open file" << file_name.toStdString(); + SPDLOG_ERROR("failed to open file: {}", file_name.toStdString()); return false; } file.write(data); @@ -94,7 +94,7 @@ std::string GpgFrontend::FileOperator::CalculateHash( // md5 hash_md5.addData(buffer); auto md5 = hash_md5.result().toHex().toStdString(); - LOG(INFO) << "md5" << md5; + SPDLOG_INFO("md5 {}", md5); ss << " " << "md5" << _(": ") << md5 << std::endl; @@ -102,7 +102,7 @@ std::string GpgFrontend::FileOperator::CalculateHash( // sha1 hash_sha1.addData(buffer); auto sha1 = hash_sha1.result().toHex().toStdString(); - LOG(INFO) << "sha1" << sha1; + SPDLOG_INFO("sha1 {}", sha1); ss << " " << "sha1" << _(": ") << sha1 << std::endl; @@ -110,7 +110,7 @@ std::string GpgFrontend::FileOperator::CalculateHash( // sha1 hash_sha256.addData(buffer); auto sha256 = hash_sha256.result().toHex().toStdString(); - LOG(INFO) << "sha256" << sha256; + SPDLOG_INFO("sha256 {}", sha256); ss << " " << "sha256" << _(": ") << sha256 << std::endl; diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp index 7231ac9e..d9628026 100644 --- a/src/core/function/GlobalSettingStation.cpp +++ b/src/core/function/GlobalSettingStation.cpp @@ -34,12 +34,12 @@ void GpgFrontend::GlobalSettingStation::SyncSettings() noexcept { using namespace libconfig; try { ui_cfg_.writeFile(ui_config_path_.u8string().c_str()); - LOG(INFO) << _("Updated ui configuration successfully written to") - << ui_config_path_; + SPDLOG_INFO("updated ui configuration successfully written to {}", + ui_config_path_.u8string()); } catch (const FileIOException &fioex) { - LOG(ERROR) << _("I/O error while writing ui configuration file") - << ui_config_path_; + SPDLOG_ERROR("i/o error while writing ui configuration file: {}", + ui_config_path_.u8string()); } } @@ -48,14 +48,12 @@ GpgFrontend::GlobalSettingStation::GlobalSettingStation(int channel) noexcept using namespace std::filesystem; using namespace libconfig; - el::Loggers::addFlag(el::LoggingFlag::AutoSpacing); - - LOG(INFO) << _("App Path") << app_path_; - LOG(INFO) << _("App Configure Path") << app_configure_path_; - LOG(INFO) << _("App Data Path") << app_data_path_; - LOG(INFO) << _("App Log Path") << app_log_path_; - LOG(INFO) << _("App Locale Path") << app_locale_path_; - LOG(INFO) << _("App Conf Path") << ui_config_path_; + SPDLOG_INFO("app path: {}", app_path_.u8string()); + SPDLOG_INFO("app configure path: {}", app_configure_path_.u8string()); + SPDLOG_INFO("app data path: {}", app_data_path_.u8string()); + SPDLOG_INFO("app log path: {}", app_log_path_.u8string()); + SPDLOG_INFO("app locale path: {}", app_locale_path_.u8string()); + SPDLOG_INFO("app conf path: {}", ui_config_path_.u8string()); if (!is_directory(app_configure_path_)) create_directory(app_configure_path_); @@ -68,24 +66,23 @@ GpgFrontend::GlobalSettingStation::GlobalSettingStation(int channel) noexcept if (!exists(ui_config_path_)) { try { this->ui_cfg_.writeFile(ui_config_path_.u8string().c_str()); - LOG(INFO) << _("UserInterface configuration successfully written to") - << ui_config_path_; + SPDLOG_INFO("userInterface configuration successfully written to {}", + ui_config_path_.u8string()); } catch (const FileIOException &fioex) { - LOG(ERROR) - << _("I/O error while writing UserInterface configuration file") - << ui_config_path_; + SPDLOG_INFO("i/o error while writing UserInterface configuration file {}", + ui_config_path_.u8string()); } } else { try { this->ui_cfg_.readFile(ui_config_path_.u8string().c_str()); - LOG(INFO) << _("UserInterface configuration successfully read from") - << ui_config_path_; + SPDLOG_INFO("user interface configuration successfully read from {}", + ui_config_path_.u8string()); } catch (const FileIOException &fioex) { - LOG(ERROR) << _("I/O error while reading UserInterface configure file"); + SPDLOG_ERROR("i/o error while reading UserInterface configure file"); } catch (const ParseException &pex) { - LOG(ERROR) << _("Parse error at ") << pex.getFile() << ":" - << pex.getLine() << " - " << pex.getError(); + SPDLOG_ERROR("parse error at {} : {} - {}", pex.getFile(), pex.getLine(), + pex.getError()); } } } diff --git a/src/core/function/KeyPackageOperator.cpp b/src/core/function/KeyPackageOperator.cpp index 3779c64b..2dc786cf 100644 --- a/src/core/function/KeyPackageOperator.cpp +++ b/src/core/function/KeyPackageOperator.cpp @@ -39,7 +39,7 @@ namespace GpgFrontend { bool KeyPackageOperator::GeneratePassphrase( const std::filesystem::path& phrase_path, std::string& phrase) { phrase = PassphraseGenerator::GetInstance().Generate(256); - LOG(INFO) << "Generated passphrase: " << phrase.size() << " bytes"; + SPDLOG_INFO("generated passphrase: {} bytes", phrase.size()); return FileOperator::WriteFileStd(phrase_path, phrase); } @@ -47,12 +47,12 @@ bool KeyPackageOperator::GenerateKeyPackage( const std::filesystem::path& key_package_path, const std::string& key_package_name, KeyIdArgsListPtr& key_ids, std::string& phrase, bool secret) { - LOG(INFO) << "Generating key package: " << key_package_name; + SPDLOG_INFO("generating key package: {}", key_package_name); ByteArrayPtr key_export_data = nullptr; if (!GpgKeyImportExporter::GetInstance().ExportKeys(key_ids, key_export_data, secret)) { - LOG(ERROR) << "Failed to export keys"; + SPDLOG_ERROR("failed to export keys"); return false; } @@ -64,7 +64,7 @@ bool KeyPackageOperator::GenerateKeyPackage( QAESEncryption::Padding::ISO); auto encoded = encryption.encode(data, hash_key); - LOG(INFO) << "Writing key package: " << key_package_name; + SPDLOG_INFO("writing key package: {}", key_package_name); return FileOperator::WriteFileStd(key_package_path, encoded.toStdString()); } @@ -72,21 +72,21 @@ bool KeyPackageOperator::ImportKeyPackage( const std::filesystem::path& key_package_path, const std::filesystem::path& phrase_path, GpgFrontend::GpgImportInformation& import_info) { - LOG(INFO) << "Importing key package: " << key_package_path.u8string(); + SPDLOG_INFO("importing key package: {]", key_package_path.u8string()); std::string encrypted_data; FileOperator::ReadFileStd(key_package_path, encrypted_data); if (encrypted_data.empty()) { - LOG(ERROR) << "Failed to read key package: " << key_package_path.u8string(); + SPDLOG_ERROR("failed to read key package: {}", key_package_path.u8string()); return false; }; std::string passphrase; FileOperator::ReadFileStd(phrase_path, passphrase); - LOG(INFO) << "Passphrase: " << passphrase.size() << " bytes"; + SPDLOG_INFO("passphrase: {} bytes", passphrase.size()); if (passphrase.size() != 256) { - LOG(ERROR) << "Failed to read passphrase: " << phrase_path.u8string(); + SPDLOG_ERROR("failed to read passphrase: {}", phrase_path.u8string()); return false; } @@ -100,7 +100,7 @@ bool KeyPackageOperator::ImportKeyPackage( auto decoded = encryption.removePadding(encryption.decode(encoded, hash_key)); auto key_data = QByteArray::fromBase64(decoded); - LOG(INFO) << "key data" << key_data.size(); + SPDLOG_INFO("key data size: {}", key_data.size()); if (!key_data.startsWith(GpgConstants::PGP_PUBLIC_KEY_BEGIN) && !key_data.startsWith(GpgConstants::PGP_PRIVATE_KEY_BEGIN)) { return false; diff --git a/src/core/function/gpg/GpgAdvancedOperator.cpp b/src/core/function/gpg/GpgAdvancedOperator.cpp index 0ec447fe..dc48410e 100644 --- a/src/core/function/gpg/GpgAdvancedOperator.cpp +++ b/src/core/function/gpg/GpgAdvancedOperator.cpp @@ -57,8 +57,9 @@ bool GpgFrontend::GpgAdvancedOperator::ReloadGpgComponents() { if (exit_code == 0) { success = true; } else { - LOG(ERROR) << "gpgconf execute error, process stderr:" << p_err - << ", process stdout:" << p_out; + SPDLOG_ERROR( + "gpgconf execute error, process stderr: {}, process stdout: {}", + p_err, p_out); return; } }); @@ -74,8 +75,9 @@ bool GpgFrontend::GpgAdvancedOperator::RestartGpgComponents() { if (exit_code == 0) { success = true; } else { - LOG(ERROR) << "gpgconf execute error, process stderr:" << p_err - << ", process stdout:" << p_out; + SPDLOG_ERROR( + "gpgconf execute error, process stderr: {}, process stdout: {}", + p_err, p_out); return; } }); @@ -87,8 +89,9 @@ bool GpgFrontend::GpgAdvancedOperator::RestartGpgComponents() { success = true; } else { success = false; - LOG(ERROR) << "gpgconf execute error, process stderr:" << p_err - << ", process stdout:" << p_out; + SPDLOG_ERROR( + "gpgconf execute error, process stderr: {}, process stdout: {}", + p_err, p_out); return; } }); @@ -104,8 +107,9 @@ bool GpgFrontend::GpgAdvancedOperator::ResetConfigures() { if (exit_code == 0) { success = true; } else { - LOG(ERROR) << "gpgconf execute error, process stderr:" << p_err - << ", process stdout:" << p_out; + SPDLOG_ERROR( + "gpgconf execute error, process stderr: {}, process stdout: {}", + p_err, p_out); return; } }); diff --git a/src/core/function/gpg/GpgBasicOperator.cpp b/src/core/function/gpg/GpgBasicOperator.cpp index a2c5d81b..5f857375 100644 --- a/src/core/function/gpg/GpgBasicOperator.cpp +++ b/src/core/function/gpg/GpgBasicOperator.cpp @@ -178,15 +178,15 @@ gpgme_error_t GpgFrontend::GpgBasicOperator::EncryptSign( void GpgFrontend::GpgBasicOperator::SetSigners(KeyArgsList& signers) { gpgme_signers_clear(ctx_); for (const GpgKey& key : signers) { - DLOG(INFO) << "key" << key.GetFingerprint(); + SPDLOG_INFO("key fpr: {}", key.GetFingerprint()); if (key.IsHasActualSigningCapability()) { - DLOG(INFO) << "signer"; + SPDLOG_INFO("signer"); auto error = gpgme_signers_add(ctx_, gpgme_key_t(key)); check_gpg_error(error); } } if (signers.size() != gpgme_signers_count(ctx_)) - DLOG(INFO) << "No All Signers Added"; + SPDLOG_INFO("not all signers added"); } std::unique_ptr<GpgFrontend::KeyArgsList> diff --git a/src/core/function/gpg/GpgCommandExecutor.cpp b/src/core/function/gpg/GpgCommandExecutor.cpp index 0fe9b5c3..720388a0 100644 --- a/src/core/function/gpg/GpgCommandExecutor.cpp +++ b/src/core/function/gpg/GpgCommandExecutor.cpp @@ -37,12 +37,11 @@ void GpgFrontend::GpgCommandExecutor::Execute( std::string cmd, std::vector<std::string> arguments, std::function<void(int, std::string, std::string)> callback, std::function<void(QProcess *)> interact_func) { - LOG(INFO) << "called" - << "cmd" << cmd << "arguments size" << arguments.size(); + SPDLOG_INFO("called cmd {} arguments size: {}", cmd, arguments.size()); Thread::Task::TaskCallback result_callback = [](int rtn, Thread::Task::DataObjectPtr data_object) { - LOG(INFO) << "called"; + SPDLOG_INFO("called"); if (data_object->GetObjectSize() != 4) throw std::runtime_error("invalid data object size"); @@ -59,15 +58,15 @@ void GpgFrontend::GpgCommandExecutor::Execute( Thread::Task::TaskRunnable runner = [](GpgFrontend::Thread::Task::DataObjectPtr data_object) -> int { - LOG(INFO) << "process runner called, data object size" - << data_object->GetObjectSize(); + SPDLOG_INFO("process runner called, data object size: {}", + data_object->GetObjectSize()); if (data_object->GetObjectSize() != 4) throw std::runtime_error("invalid data object size"); // get arguments auto cmd = data_object->PopObject<std::string>(); - LOG(INFO) << "get cmd" << cmd; + SPDLOG_INFO("get cmd: {}", cmd); auto arguments = data_object->PopObject<std::vector<std::string>>(); auto interact_func = data_object->PopObject<std::function<void(QProcess *)>>(); @@ -76,20 +75,20 @@ void GpgFrontend::GpgCommandExecutor::Execute( cmd_process->setProcessChannelMode(QProcess::MergedChannels); QObject::connect(cmd_process, &QProcess::started, - []() -> void { LOG(INFO) << "process started"; }); + []() -> void { SPDLOG_INFO("process started"); }); QObject::connect( cmd_process, &QProcess::readyReadStandardOutput, [interact_func, cmd_process]() { interact_func(cmd_process); }); QObject::connect(cmd_process, &QProcess::errorOccurred, [=]() { - LOG(ERROR) << "error in executing command:" << cmd; + SPDLOG_ERROR("error in executing command: {}", cmd); }); QObject::connect(cmd_process, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), [=](int, QProcess::ExitStatus status) { if (status == QProcess::NormalExit) - LOG(INFO) << "succeed in executing command:" << cmd; + SPDLOG_INFO("succeed in executing command: {}", cmd); else - LOG(WARNING) << "error in executing command:" << cmd; + SPDLOG_WARN("error in executing command: {}", cmd); }); cmd_process->setProgram(QString::fromStdString(cmd)); @@ -99,7 +98,7 @@ void GpgFrontend::GpgCommandExecutor::Execute( q_arguments.append(QString::fromStdString(argument)); cmd_process->setArguments(q_arguments); - LOG(INFO) << "process execute ready"; + SPDLOG_INFO("process execute ready"); cmd_process->start(); cmd_process->waitForFinished(30); diff --git a/src/core/function/gpg/GpgKeyGetter.cpp b/src/core/function/gpg/GpgKeyGetter.cpp index 571e8797..0cb418a7 100644 --- a/src/core/function/gpg/GpgKeyGetter.cpp +++ b/src/core/function/gpg/GpgKeyGetter.cpp @@ -35,18 +35,16 @@ #include <utility> #include "GpgConstants.h" -#include "easylogging++.h" #include "model/GpgKey.h" GpgFrontend::GpgKeyGetter::GpgKeyGetter(int channel) : SingletonFunctionObject<GpgKeyGetter>(channel) { - LOG(INFO) << "called" - << "channel:" << channel; + SPDLOG_INFO("called channel: {}", channel); } GpgFrontend::GpgKey GpgFrontend::GpgKeyGetter::GetKey(const std::string& fpr, bool use_cache) { - LOG(INFO) << "called"; + SPDLOG_INFO("called"); // find in cache first if (use_cache) { @@ -57,7 +55,7 @@ GpgFrontend::GpgKey GpgFrontend::GpgKeyGetter::GetKey(const std::string& fpr, gpgme_key_t _p_key = nullptr; gpgme_get_key(ctx_, fpr.c_str(), &_p_key, 1); if (_p_key == nullptr) { - DLOG(WARNING) << "GpgKeyGetter GetKey Private _p_key Null fpr" << fpr; + SPDLOG_WARN("GpgKeyGetter GetKey Private _p_key Null fpr", fpr); return GetPubkey(fpr); } else { return GpgKey(std::move(_p_key)); @@ -74,8 +72,7 @@ GpgFrontend::GpgKey GpgFrontend::GpgKeyGetter::GetPubkey(const std::string& fpr, gpgme_key_t _p_key = nullptr; gpgme_get_key(ctx_, fpr.c_str(), &_p_key, 0); - if (_p_key == nullptr) - DLOG(WARNING) << "GpgKeyGetter GetKey _p_key Null" << fpr; + if (_p_key == nullptr) SPDLOG_WARN("GpgKeyGetter GetKey _p_key Null", fpr); return GpgKey(std::move(_p_key)); } @@ -83,21 +80,19 @@ GpgFrontend::KeyLinkListPtr GpgFrontend::GpgKeyGetter::FetchKey() { // get the lock std::lock_guard<std::mutex> lock(keys_cache_mutex_); - LOG(INFO) << "GpgKeyGetter FetchKey" - << "channel id:" << GetChannel(); + SPDLOG_INFO("channel id: {}", GetChannel()); auto keys_list = std::make_unique<GpgKeyLinkList>(); for (const auto& [key, value] : keys_cache_) { - LOG(INFO) << "FetchKey Id:" << value.GetId(); + SPDLOG_INFO("fetch key id: {}", value.GetId()); keys_list->push_back(value.Copy()); } return keys_list; } void GpgFrontend::GpgKeyGetter::FlushKeyCache() { - LOG(INFO) << "called" - << "channel id: " << GetChannel(); + SPDLOG_INFO("called channel id: {}", GetChannel()); // clear the keys cache keys_cache_.clear(); @@ -125,13 +120,14 @@ void GpgFrontend::GpgKeyGetter::FlushKeyCache() { gpg_key = GetKey(gpg_key.GetId(), false); } - LOG(INFO) << "LoadKey Fpr:" << gpg_key.GetFingerprint() - << "Id:" << gpg_key.GetId(); + SPDLOG_INFO("load key fpr: {} id: {}", gpg_key.GetFingerprint(), + gpg_key.GetId()); keys_cache_.insert({gpg_key.GetId(), std::move(gpg_key)}); } } - LOG(INFO) << "cache address:" << &keys_cache_ << "object address" << this; + SPDLOG_INFO("cache address: {} object address: {}", + static_cast<void*>(&keys_cache_), static_cast<void*>(this)); // for debug assert(check_gpg_error_2_err_code(err, GPG_ERR_EOF) == GPG_ERR_EOF); diff --git a/src/core/function/gpg/GpgKeyImportExporter.cpp b/src/core/function/gpg/GpgKeyImportExporter.cpp index 206282ae..dc744e09 100644 --- a/src/core/function/gpg/GpgKeyImportExporter.cpp +++ b/src/core/function/gpg/GpgKeyImportExporter.cpp @@ -91,8 +91,8 @@ bool GpgFrontend::GpgKeyImportExporter::ExportKeys(KeyIdArgsListPtr& uid_list, delete[] keys_array; - DLOG(INFO) << "exportKeys read_bytes" - << gpgme_data_seek(data_out, 0, SEEK_END); + SPDLOG_INFO("exportKeys read_bytes: {}", + gpgme_data_seek(data_out, 0, SEEK_END)); auto temp_out_buffer = data_out.Read2Buffer(); @@ -123,7 +123,7 @@ bool GpgFrontend::GpgKeyImportExporter::ExportKeys(const KeyArgsList& keys, */ bool GpgFrontend::GpgKeyImportExporter::ExportSecretKey( const GpgKey& key, ByteArrayPtr& out_buffer) const { - DLOG(INFO) << "Export Secret Key" << key.GetId().c_str(); + SPDLOG_INFO("export secret key: {}", key.GetId().c_str()); gpgme_key_t target_key[2] = {gpgme_key_t(key), nullptr}; @@ -144,8 +144,8 @@ bool GpgFrontend::GpgKeyImportExporter::ExportKey( GpgData data_out; auto err = gpgme_op_export(ctx_, key.GetId().c_str(), 0, data_out); - DLOG(INFO) << "exportKeys read_bytes" - << gpgme_data_seek(data_out, 0, SEEK_END); + SPDLOG_INFO("export keys read_bytes: {}", + gpgme_data_seek(data_out, 0, SEEK_END)); auto temp_out_buffer = data_out.Read2Buffer(); std::swap(out_buffer, temp_out_buffer); @@ -159,7 +159,7 @@ bool GpgFrontend::GpgKeyImportExporter::ExportKeyOpenSSH( auto err = gpgme_op_export(ctx_, key.GetId().c_str(), GPGME_EXPORT_MODE_SSH, data_out); - DLOG(INFO) << "read_bytes" << gpgme_data_seek(data_out, 0, SEEK_END); + SPDLOG_INFO("read_bytes: {}", gpgme_data_seek(data_out, 0, SEEK_END)); auto temp_out_buffer = data_out.Read2Buffer(); std::swap(out_buffer, temp_out_buffer); @@ -173,7 +173,7 @@ bool GpgFrontend::GpgKeyImportExporter::ExportSecretKeyShortest( auto err = gpgme_op_export(ctx_, key.GetId().c_str(), GPGME_EXPORT_MODE_MINIMAL, data_out); - DLOG(INFO) << "read_bytes" << gpgme_data_seek(data_out, 0, SEEK_END); + SPDLOG_INFO("read_bytes: {}", gpgme_data_seek(data_out, 0, SEEK_END)); auto temp_out_buffer = data_out.Read2Buffer(); std::swap(out_buffer, temp_out_buffer); diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp index 08103bbb..00c0a6c8 100644 --- a/src/core/function/gpg/GpgKeyOpera.cpp +++ b/src/core/function/gpg/GpgKeyOpera.cpp @@ -59,7 +59,7 @@ void GpgFrontend::GpgKeyOpera::DeleteKeys( GPGME_DELETE_ALLOW_SECRET | GPGME_DELETE_FORCE)); assert(gpg_err_code(err) == GPG_ERR_NO_ERROR); } else { - LOG(WARNING) << "GpgKeyOpera DeleteKeys get key failed" << tmp; + SPDLOG_WARN("GpgKeyOpera DeleteKeys get key failed", tmp); } } } @@ -84,7 +84,7 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::SetExpire( to_time_t(*expires) - system_clock::to_time_t(system_clock::now()); } - LOG(INFO) << key.GetId() << subkey_fpr << expires_time; + SPDLOG_INFO(key.GetId(), subkey_fpr, expires_time); GpgError err; if (key.GetFingerprint() == subkey_fpr || subkey_fpr.empty()) @@ -116,7 +116,7 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateKey( const char* userid = userid_utf8.c_str(); auto algo_utf8 = params->GetAlgo() + params->GetKeySizeStr(); - LOG(INFO) << "params" << params->GetAlgo() << params->GetKeySizeStr(); + SPDLOG_INFO("params: {} {}", params->GetAlgo(), params->GetKeySizeStr()); const char* algo = algo_utf8.c_str(); unsigned long expires = 0; @@ -129,7 +129,7 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateKey( GpgError err; - LOG(INFO) << "ctx version" << ctx_.GetInfo(false).GnupgVersion; + SPDLOG_INFO("ctx version, {}", ctx_.GetInfo(false).GnupgVersion); if (ctx_.GetInfo(false).GnupgVersion >= "2.1.0") { unsigned int flags = 0; @@ -141,7 +141,7 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateKey( if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - LOG(INFO) << "args: " << userid << algo << expires << flags; + SPDLOG_INFO("args: {}", userid, algo, expires, flags); err = gpgme_op_createkey(ctx_, userid, algo, 0, expires, nullptr, flags); @@ -170,7 +170,7 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateKey( ss << "</GnupgKeyParms>"; - DLOG(INFO) << "params" << std::endl << ss.str(); + SPDLOG_INFO("params: {}", ss.str()); err = gpgme_op_genkey(ctx_, ss.str().c_str(), nullptr, nullptr); } @@ -193,9 +193,8 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateSubkey( const GpgKey& key, const std::unique_ptr<GenKeyInfo>& params) { if (!params->IsSubKey()) return GPG_ERR_CANCELED; - LOG(INFO) << "generate subkey" - << "algo" << params->GetAlgo() << "key size" - << params->GetKeySizeStr(); + SPDLOG_INFO("generate subkey algo {} key size {}", params->GetAlgo(), + params->GetKeySizeStr()); auto algo_utf8 = (params->GetAlgo() + params->GetKeySizeStr()); const char* algo = algo_utf8.c_str(); @@ -216,8 +215,8 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateSubkey( flags |= GPGME_CREATE_NOPASSWD; - LOG(INFO) << "GpgFrontend::GpgKeyOpera::GenerateSubkey Args: " << key.GetId() - << algo << expires << flags; + SPDLOG_INFO("GpgFrontend::GpgKeyOpera::GenerateSubkey args: {} {} {} {}", + key.GetId(), algo, expires, flags); auto err = gpgme_op_createsubkey(ctx_, gpgme_key_t(key), algo, 0, expires, flags); @@ -227,7 +226,7 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::GenerateSubkey( GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::ModifyPassword( const GpgFrontend::GpgKey& key) { if (ctx_.GetInfo(false).GnupgVersion < "2.0.15") { - LOG(ERROR) << _("operator not support"); + SPDLOG_ERROR("operator not support"); return GPG_ERR_NOT_SUPPORTED; } auto err = gpgme_op_passwd(ctx_, gpgme_key_t(key), 0); @@ -236,7 +235,7 @@ GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::ModifyPassword( GpgFrontend::GpgError GpgFrontend::GpgKeyOpera::ModifyTOFUPolicy( const GpgFrontend::GpgKey& key, gpgme_tofu_policy_t tofu_policy) { if (ctx_.GetInfo(false).GnupgVersion < "2.1.10") { - LOG(ERROR) << _("operator not support"); + SPDLOG_ERROR("operator not support"); return GPG_ERR_NOT_SUPPORTED; } auto err = gpgme_op_tofu_policy(ctx_, gpgme_key_t(key), tofu_policy); diff --git a/src/core/function/gpg/GpgUIDOperator.cpp b/src/core/function/gpg/GpgUIDOperator.cpp index 33c29fa4..5b92b86d 100644 --- a/src/core/function/gpg/GpgUIDOperator.cpp +++ b/src/core/function/gpg/GpgUIDOperator.cpp @@ -65,7 +65,7 @@ bool GpgFrontend::GpgUIDOperator::AddUID(const GpgFrontend::GpgKey& key, const std::string& name, const std::string& comment, const std::string& email) { - LOG(INFO) << "GpgFrontend::UidOperator::AddUID" << name << comment << email; + SPDLOG_INFO("GpgFrontend::UidOperator::AddUID", name, comment, email); auto uid = boost::format("%1%(%2%)<%3%>") % name % comment % email; return AddUID(key, uid.str()); } diff --git a/src/core/function/result_analyse/GpgEncryptResultAnalyse.cpp b/src/core/function/result_analyse/GpgEncryptResultAnalyse.cpp index 9b3b9700..a468e583 100644 --- a/src/core/function/result_analyse/GpgEncryptResultAnalyse.cpp +++ b/src/core/function/result_analyse/GpgEncryptResultAnalyse.cpp @@ -33,7 +33,7 @@ GpgFrontend::GpgEncryptResultAnalyse::GpgEncryptResultAnalyse( : error_(error), result_(std::move(result)) {} void GpgFrontend::GpgEncryptResultAnalyse::do_analyse() { - LOG(INFO) << _("Start Encrypt Result Analyse"); + SPDLOG_INFO("start encrypt result analyse"); stream_ << "[#] " << _("Encrypt Operation") << " "; diff --git a/src/core/function/result_analyse/GpgSignResultAnalyse.cpp b/src/core/function/result_analyse/GpgSignResultAnalyse.cpp index a47b8e3e..1660d08b 100644 --- a/src/core/function/result_analyse/GpgSignResultAnalyse.cpp +++ b/src/core/function/result_analyse/GpgSignResultAnalyse.cpp @@ -35,7 +35,7 @@ GpgFrontend::GpgSignResultAnalyse::GpgSignResultAnalyse(GpgError error, : error_(error), result_(std::move(result)) {} void GpgFrontend::GpgSignResultAnalyse::do_analyse() { - LOG(INFO) << _("Start Sign Result Analyse"); + SPDLOG_INFO("start sign result analyse"); stream_ << "[#] " << _("Sign Operation") << " "; @@ -49,14 +49,14 @@ void GpgFrontend::GpgSignResultAnalyse::do_analyse() { if (result_ != nullptr && (result_->signatures != nullptr || result_->invalid_signers != nullptr)) { - LOG(INFO) << _("Sign Result Analyse Getting Result"); + SPDLOG_INFO("sign result analyse getting result"); stream_ << "------------>" << std::endl; auto new_sign = result_->signatures; while (new_sign != nullptr) { stream_ << "[>]" << _("New Signature") << ": " << std::endl; - LOG(INFO) << _("Signers Fingerprint") << ": " << new_sign->fpr; + SPDLOG_INFO("signers fingerprint: ", new_sign->fpr); stream_ << " " << _("Sign Mode") << ": "; if (new_sign->type == GPGME_SIG_MODE_NORMAL) @@ -92,7 +92,7 @@ void GpgFrontend::GpgSignResultAnalyse::do_analyse() { new_sign = new_sign->next; } - LOG(INFO) << _("Sign Result Analyse Getting Invalid Signer"); + SPDLOG_INFO("sign result analyse getting invalid signer"); auto invalid_signer = result_->invalid_signers; diff --git a/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp b/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp index 79eb5282..d246900e 100644 --- a/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp +++ b/src/core/function/result_analyse/GpgVerifyResultAnalyse.cpp @@ -39,7 +39,7 @@ GpgFrontend::GpgVerifyResultAnalyse::GpgVerifyResultAnalyse( : error_(error), result_(std::move(result)) {} void GpgFrontend::GpgVerifyResultAnalyse::do_analyse() { - LOG(INFO) << _("started"); + SPDLOG_INFO("started"); stream_ << "[#] " << _("Verify Operation") << " "; diff --git a/src/core/thread/FileReadTask.cpp b/src/core/thread/FileReadTask.cpp index 3a235390..1ac23a89 100644 --- a/src/core/thread/FileReadTask.cpp +++ b/src/core/thread/FileReadTask.cpp @@ -26,8 +26,6 @@ #include "core/thread/FileReadTask.h" -#include <utility> - namespace GpgFrontend::UI { FileReadTask::FileReadTask(std::string path) { @@ -48,18 +46,18 @@ void FileReadTask::Run() { SetFinishAfterRun(false); if (is_regular_file(read_file_path_)) { - LOG(INFO) << "read open file" << read_file_path_; + SPDLOG_INFO("read open file: {}", read_file_path_.u8string()); target_file_.setFileName( QString::fromStdString(read_file_path_.u8string())); target_file_.open(QIODevice::ReadOnly); if (!(target_file_.isOpen() && target_file_.isReadable())) { - LOG(ERROR) << "file not open or not readable"; + SPDLOG_ERROR("file not open or not readable"); if (target_file_.isOpen()) target_file_.close(); return; } - LOG(INFO) << "started reading" << read_file_path_; + SPDLOG_INFO("started reading: {}", read_file_path_.u8string()); read_bytes(); } else { emit SignalFileBytesReadEnd(); @@ -70,10 +68,10 @@ void FileReadTask::read_bytes() { QByteArray read_buffer; if (!target_file_.atEnd() && (read_buffer = target_file_.read(buffer_size_)).size() > 0) { - LOG(INFO) << "read bytes" << read_buffer.size(); + SPDLOG_INFO("read bytes: {}", read_buffer.size()); emit SignalFileBytesRead(std::move(read_buffer)); } else { - LOG(INFO) << "read bytes end"; + SPDLOG_INFO("read bytes end"); emit SignalFileBytesReadEnd(); // finish task emit SignalTaskFinished(); @@ -81,7 +79,7 @@ void FileReadTask::read_bytes() { } FileReadTask::~FileReadTask() { - LOG(INFO) << "close file" << read_file_path_; + SPDLOG_INFO("close file: {}", read_file_path_.u8string()); if (target_file_.isOpen()) target_file_.close(); } diff --git a/src/core/thread/Task.cpp b/src/core/thread/Task.cpp index 669334d5..87be7a10 100644 --- a/src/core/thread/Task.cpp +++ b/src/core/thread/Task.cpp @@ -34,10 +34,9 @@ #include <utility> #include "core/thread/TaskRunner.h" -#include "easylogging++.h" GpgFrontend::Thread::Task::Task() : uuid_(generate_uuid()) { - LOG(TRACE) << "Task" << uuid_ << "created"; + SPDLOG_TRACE("task {} created", uuid_); init(); } @@ -47,8 +46,8 @@ GpgFrontend::Thread::Task::Task(TaskCallback callback, callback_(std::move(callback)), callback_thread_(QThread::currentThread()), data_object_(data_object) { - LOG(TRACE) << "Task" << uuid_ << "created with callback" - << "callback_thread_: " << callback_thread_; + SPDLOG_TRACE("task {} created with callback, callback_thread_: {}", uuid_, + static_cast<void *>(callback_thread_)); init(); } @@ -60,13 +59,12 @@ GpgFrontend::Thread::Task::Task(TaskRunnable runnable, TaskCallback callback, callback_thread_(QThread::currentThread()), data_object_(data_object) { init(); - LOG(TRACE) << "Task" << uuid_ << "created with runnable and callback" - << "callback_thread_: " << callback_thread_; + SPDLOG_TRACE( + "task {} created with runnable and callback, callback_thread_: {}", uuid_, + static_cast<void *>(callback_thread_)); } -GpgFrontend::Thread::Task::~Task() { - LOG(TRACE) << "Task" << uuid_ << "destroyed"; -} +GpgFrontend::Thread::Task::~Task() { SPDLOG_TRACE("task {} destroyed", uuid_); } std::string GpgFrontend::Thread::Task::GetUUID() const { return uuid_; } @@ -81,7 +79,8 @@ void GpgFrontend::Thread::Task::init() { } void GpgFrontend::Thread::Task::before_finish_task() { - LOG(TRACE) << "Task" << uuid_ << "finished"; + SPDLOG_TRACE("task {} finished", uuid_); + try { if (callback_) { bool if_invoke = QMetaObject::invokeMethod( @@ -90,19 +89,19 @@ void GpgFrontend::Thread::Task::before_finish_task() { callback(rtn, data_object); }); if (!if_invoke) { - LOG(ERROR) << "failed to invoke callback"; + SPDLOG_ERROR("failed to invoke callback"); } } } catch (std::exception &e) { - LOG(ERROR) << "exception caught: " << e.what(); + SPDLOG_ERROR("exception caught: {}", e.what()); } catch (...) { - LOG(ERROR) << "unknown exception caught"; + SPDLOG_ERROR("unknown exception caught"); } emit SignalTaskPostFinishedDone(); } void GpgFrontend::Thread::Task::run() { - LOG(TRACE) << "Task" << uuid_ << "started"; + SPDLOG_TRACE("task {} started", uuid_); Run(); if (finish_after_run_) emit SignalTaskFinished(); } @@ -112,7 +111,7 @@ void GpgFrontend::Thread::Task::Run() { bool if_invoke = QMetaObject::invokeMethod( this, [=]() { return runnable_(data_object_); }, &rtn_); if (!if_invoke) { - LOG(ERROR) << "Qt invokeMethod failed"; + SPDLOG_ERROR("qt invokeMethod failed"); } } } @@ -126,8 +125,8 @@ GpgFrontend::Thread::Task::DataObject::get_heap_ptr(size_t bytes_size) { GpgFrontend::Thread::Task::DataObject::~DataObject() { if (!data_objects_.empty()) - LOG(WARNING) << "data_objects_ is not empty" - << "address:" << this; + SPDLOG_WARN("data_objects_ is not empty", + "address:", static_cast<void *>(this)); while (!data_objects_.empty()) { free_heap_ptr(data_objects_.top()); data_objects_.pop(); @@ -139,8 +138,9 @@ size_t GpgFrontend::Thread::Task::DataObject::GetObjectSize() { } void GpgFrontend::Thread::Task::DataObject::free_heap_ptr(Destructor *ptr) { - LOG(TRACE) << "p_obj: " << ptr->p_obj << "destructor: " << ptr->destroy - << "DataObject:" << this; + SPDLOG_TRACE("p_obj: {} data object: {}", + static_cast<const void *>(ptr->p_obj), + static_cast<void *>(this)); if (ptr->destroy != nullptr) { ptr->destroy(ptr->p_obj); } diff --git a/src/core/thread/Task.h b/src/core/thread/Task.h index 163e1507..413a54fd 100644 --- a/src/core/thread/Task.h +++ b/src/core/thread/Task.h @@ -78,7 +78,7 @@ class GPGFRONTEND_CORE_EXPORT Task : public QObject, public QRunnable { */ template <typename T> void AppendObject(T &&obj) { - DLOG(TRACE) << "called:" << this; + SPDLOG_TRACE("called: {}", static_cast<void *>(this)); auto *obj_dstr = this->get_heap_ptr(sizeof(T)); new ((void *)obj_dstr->p_obj) T(std::forward<T>(obj)); @@ -102,11 +102,11 @@ class GPGFRONTEND_CORE_EXPORT Task : public QObject, public QRunnable { */ template <typename T> void AppendObject(T *obj) { - DLOG(TRACE) << "called:" << this; + SPDLOG_TRACE("called: {}", static_cast<void *>(this)); auto *obj_dstr = this->get_heap_ptr(sizeof(T)); auto *ptr_heap = new ((void *)obj_dstr->p_obj) T(std::move(*obj)); if (std::is_class_v<T>) { - LOG(TRACE) << "is class"; + SPDLOG_TRACE("is class"); auto destructor = [](const void *x) { static_cast<const T *>(x)->~T(); }; @@ -125,7 +125,7 @@ class GPGFRONTEND_CORE_EXPORT Task : public QObject, public QRunnable { */ template <typename T> T PopObject() { - DLOG(TRACE) << "called:" << this; + SPDLOG_TRACE("called: {}", static_cast<void *>(this)); if (data_objects_.empty()) throw std::runtime_error("No object to pop"); auto *obj_dstr = data_objects_.top(); auto *heap_ptr = (T *)obj_dstr->p_obj; diff --git a/src/core/thread/TaskRunner.cpp b/src/core/thread/TaskRunner.cpp index ffbeb495..7be38f76 100644 --- a/src/core/thread/TaskRunner.cpp +++ b/src/core/thread/TaskRunner.cpp @@ -26,10 +26,8 @@ #include "core/thread/TaskRunner.h" -#include <exception> - #include "core/thread/Task.h" -#include "easylogging++.h" +#include "spdlog/spdlog.h" GpgFrontend::Thread::TaskRunner::TaskRunner() = default; @@ -39,7 +37,7 @@ void GpgFrontend::Thread::TaskRunner::PostTask(Task* task) { if (task == nullptr) return; std::string uuid = task->GetUUID(); - LOG(TRACE) << "Post Task" << uuid; + SPDLOG_TRACE("post task: {}", uuid); task->setParent(nullptr); task->moveToThread(this); @@ -61,15 +59,14 @@ void GpgFrontend::Thread::TaskRunner::PostTask(Task* task) { } [[noreturn]] void GpgFrontend::Thread::TaskRunner::run() { - LOG(TRACE) << "called" - << "thread id:" << QThread::currentThreadId(); + SPDLOG_TRACE("called, thread id: {}", QThread::currentThreadId()); while (true) { - LOG(TRACE) << "TaskRunner: A new cycle start"; + SPDLOG_TRACE("task runner: a new cycle start"); if (tasks.empty()) { - LOG(TRACE) << "TaskRunner: No tasks to run, trapping into event loop..."; + SPDLOG_TRACE("task runner: no tasks to run, trapping into event loop..."); exec(); } else { - LOG(TRACE) << "TaskRunner: Task queue size:" << tasks.size(); + SPDLOG_TRACE("task runner: task queue size:", tasks.size()); Task* task = nullptr; { @@ -81,19 +78,19 @@ void GpgFrontend::Thread::TaskRunner::PostTask(Task* task) { if (task != nullptr) { // Run the task - LOG(TRACE) << "TaskRunner: Running Task" << task->GetUUID(); + SPDLOG_TRACE("task runner: running task: {}", task->GetUUID()); try { task->run(); } catch (const std::exception& e) { - LOG(ERROR) << "TaskRunner: Exception in Task" << task->GetUUID() - << "Exception: " << e.what(); + SPDLOG_ERROR("task runner: exception in task: {} , exception: {}", + task->GetUUID(), e.what()); // destroy the task, remove the task from the pending tasks task->deleteLater(); pending_tasks_.erase(task->GetUUID()); } catch (...) { - LOG(ERROR) << "TaskRunner: Unknown Exception in Task" - << task->GetUUID(); + SPDLOG_ERROR("task runner: unknown exception in task: {}", + task->GetUUID()); // destroy the task, remove the task from the pending tasks task->deleteLater(); diff --git a/src/init.cpp b/src/init.cpp index c872170e..20f033e0 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -26,21 +26,38 @@ * */ +#include <spdlog/async.h> +#include <spdlog/common.h> +#include <spdlog/sinks/rotating_file_sink.h> +#include <spdlog/sinks/stdout_color_sinks.h> + #include "GpgFrontend.h" #include "GpgFrontendBuildInfo.h" #include "core/function/GlobalSettingStation.h" void init_logging_system() { - el::Loggers::addFlag(el::LoggingFlag::AutoSpacing); - el::Configurations defaultConf; - defaultConf.setToDefault(); - - // apply settings - defaultConf.setGlobally(el::ConfigurationType::Format, - "%datetime %level [main] %func %msg"); - // apply settings no written to file - defaultConf.setGlobally(el::ConfigurationType::ToFile, "false"); - - // set the logger - el::Loggers::reconfigureLogger("default", defaultConf); + using namespace boost::posix_time; + using namespace boost::gregorian; + + // sinks + std::vector<spdlog::sink_ptr> sinks; + sinks.push_back(std::make_shared<spdlog::sinks::stderr_color_sink_mt>()); + + // thread pool + spdlog::init_thread_pool(1024, 2); + + // logger + auto main_logger = std::make_shared<spdlog::async_logger>( + "core", begin(sinks), end(sinks), spdlog::thread_pool()); + main_logger->set_pattern( + "[%H:%M:%S.%e] [T:%t] [%=4n] %^[%=8l]%$ [%s:%#] [%!] -> %v (+%ius)"); + +#ifdef DEBUG + main_logger->set_level(spdlog::level::trace); +#elif + core_logger->set_level(spdlog::level::info); +#endif + + // register it as default logger + spdlog::set_default_logger(main_logger); } diff --git a/src/main.cpp b/src/main.cpp index 5f2ba02e..36c3c7e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,11 +40,6 @@ #include "ui/GpgFrontendUIInit.h" /** - * \brief initialize the easylogging++ library. - */ -INITIALIZE_EASYLOGGINGPP - -/** * \brief Store the jump buff and make it possible to recover from a crash. */ #ifdef FREEBSD @@ -124,7 +119,7 @@ int main(int argc, char* argv[]) { // create main window return_from_event_loop_code = GpgFrontend::UI::RunGpgFrontendUI(app); } else { - LOG(ERROR) << "recover from a crash"; + SPDLOG_ERROR("recover from a crash"); // when signal is caught, restart the main window auto* message_box = new QMessageBox( QMessageBox::Critical, _("A serious error has occurred"), @@ -137,7 +132,7 @@ int main(int argc, char* argv[]) { return_from_event_loop_code = CRASH_CODE; } - LOG(INFO) << "loop refresh"; + SPDLOG_INFO("loop refresh"); } while (return_from_event_loop_code == RESTART_CODE); // reset core diff --git a/src/signal.cpp b/src/signal.cpp index bd4cfdb1..424b97d5 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -43,7 +43,7 @@ extern jmp_buf recover_env; */ void handle_signal(int sig) { static int _repeat_handle_num = 1, last_sig = sig; - LOG(INFO) << "signal caught" << sig; + SPDLOG_INFO("signal caught {}", sig); if (last_sig == sig) _repeat_handle_num++; @@ -51,8 +51,9 @@ void handle_signal(int sig) { _repeat_handle_num = 1, last_sig = sig; if (_repeat_handle_num > 3) { - LOG(INFO) << "The same signal appears three times, execute the termination " - "operation. "; + SPDLOG_INFO( + "The same signal appears three times, execute the termination " + "operation. "); exit(-1); } diff --git a/src/ui/GpgFrontendApplication.cpp b/src/ui/GpgFrontendApplication.cpp index b1c5beed..e5f06ed8 100644 --- a/src/ui/GpgFrontendApplication.cpp +++ b/src/ui/GpgFrontendApplication.cpp @@ -75,7 +75,7 @@ bool GpgFrontendApplication::notify(QObject *receiver, QEvent *event) { try { app_done = QApplication::notify(receiver, event); } catch (const std::exception &ex) { - LOG(INFO) << "Exception caught in notify: " << ex.what(); + SPDLOG_INFO("exception caught in notify: {}", ex.what()); QMessageBox::information(nullptr, _("Standard Exception Thrown"), _("Oops, an standard exception was thrown " "during the running of the " @@ -83,7 +83,7 @@ bool GpgFrontendApplication::notify(QObject *receiver, QEvent *event) { "be the negligence of the programmer, " "please report this problem if you can.")); } catch (...) { - LOG(INFO) << "Unknown exception caught in notify"; + SPDLOG_INFO("unknown exception caught in notify"); QMessageBox::information( nullptr, _("Unhandled Exception Thrown"), _("Oops, an unhandled exception was thrown " diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp index 5cbca31b..0ebcd500 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,9 +44,6 @@ #include "core/function/GlobalSettingStation.h" #endif -// init easyloggingpp library -INITIALIZE_EASYLOGGINGPP - namespace GpgFrontend::UI { extern void init_logging_system(); @@ -90,13 +92,13 @@ void InitGpgFrontendUI(QApplication* app) { waiting_dialog->resize(420, 120); app->connect(init_ctx_task, &Thread::CtxCheckTask::SignalTaskFinished, waiting_dialog, [=]() { - LOG(INFO) << "Gpg context loaded"; + SPDLOG_INFO("gpg context loaded"); waiting_dialog->finished(0); waiting_dialog->deleteLater(); }); app->connect(waiting_dialog, &QProgressDialog::canceled, [=]() { - LOG(INFO) << "cancel clicked"; + SPDLOG_INFO("cancel clicked"); app->quit(); exit(0); }); @@ -123,7 +125,7 @@ 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_INFO("main window inited"); main_window->show(); // start the main event loop return app->exec(); @@ -133,36 +135,33 @@ void init_logging_system() { 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(); - - // apply settings - defaultConf.setGlobally(el::ConfigurationType::Format, - "%datetime %level [ui] {%func} -> %msg"); - - // apply settings no written to file - defaultConf.setGlobally(el::ConfigurationType::ToFile, "false"); - - // apply settings - el::Loggers::reconfigureLogger("default", defaultConf)->reconfigure(); - // get the log directory - auto logfile_path = (GlobalSettingStation::GetInstance().GetLogDir() / - to_iso_string(second_clock::local_time())); + auto logfile_path = (GlobalSettingStation::GetInstance().GetLogDir() / "ui"); logfile_path.replace_extension(".log"); - defaultConf.setGlobally(el::ConfigurationType::Filename, - logfile_path.u8string()); - // apply settings written to file - defaultConf.setGlobally(el::ConfigurationType::ToFile, "false"); - - el::Loggers::reconfigureLogger("default", defaultConf); + // 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)); + + // thread pool + spdlog::init_thread_pool(1024, 2); + + // logger + auto ui_logger = std::make_shared<spdlog::async_logger>( + "core", begin(sinks), end(sinks), spdlog::thread_pool()); + ui_logger->set_pattern( + "[%H:%M:%S.%e] [T:%t] [%=4n] %^[%=8l]%$ [%s:%#] [%!] -> %v (+%ius)"); + +#ifdef DEBUG + ui_logger->set_level(spdlog::level::trace); +#elif + core_logger->set_level(spdlog::level::info); +#endif - LOG(INFO) << _("log file path") << logfile_path; + // register it as default logger + spdlog::set_default_logger(ui_logger); } /** @@ -187,20 +186,19 @@ void init_locale() { // sync the settings to the file GpgFrontend::GlobalSettingStation::GetInstance().SyncSettings(); - LOG(INFO) << "current system locale" << setlocale(LC_ALL, nullptr); + SPDLOG_INFO("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() - .GetLocaleDir() - .c_str(); + SPDLOG_INFO("lang from settings: {}", lang); + SPDLOG_INFO("project name: {}", PROJECT_NAME); + SPDLOG_INFO( + "locales path: {}", + GpgFrontend::GlobalSettingStation::GetInstance().GetLocaleDir().c_str()); #ifndef WINDOWS if (!lang.empty()) { @@ -208,14 +206,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); 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_INFO("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 +222,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); 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_INFO("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 diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index db28b312..b84c1ad2 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -38,7 +38,6 @@ #include "core/thread/Task.h" #include "core/thread/TaskRunner.h" #include "core/thread/TaskRunnerGetter.h" -#include "easylogging++.h" #include "ui/SignalStation.h" #include "ui/dialog/WaitingDialog.h" #include "ui/struct/SettingsObject.h" @@ -72,7 +71,7 @@ void import_unknown_key_from_keyserver( auto key_ids = std::make_unique<KeyIdArgsList>(); auto *signature = verify_res.GetSignatures(); while (signature != nullptr) { - LOG(INFO) << "signature fpr" << signature->fpr; + SPDLOG_INFO("signature fpr: {}", signature->fpr); key_ids->push_back(signature->fpr); signature = signature->next; } @@ -103,7 +102,7 @@ void process_result_analyse(TextEdit *edit, InfoBoardWidget *info_board, void process_result_analyse(TextEdit *edit, InfoBoardWidget *info_board, const GpgResultAnalyse &result_analyse_a, const GpgResultAnalyse &result_analyse_b) { - LOG(INFO) << "process_result_analyse Started"; + SPDLOG_INFO("process_result_analyse Started"); info_board->AssociateTabWidget(edit->tab_widget_); @@ -148,7 +147,7 @@ CommonUtils *CommonUtils::GetInstance() { } CommonUtils::CommonUtils() : QWidget(nullptr) { - LOG(INFO) << "common utils created"; + SPDLOG_INFO("common utils created"); connect(CoreCommonUtil::GetInstance(), &CoreCommonUtil::SignalGnupgNotInstall, this, &CommonUtils::SignalGnupgNotInstall); @@ -214,8 +213,7 @@ void CommonUtils::SlotImportKeyFromClipboard(QWidget *parent) { } void CommonUtils::SlotExecuteCommand( - const std::string& cmd, - const QStringList &arguments, + const std::string &cmd, const QStringList &arguments, const std::function<void(QProcess *)> &interact_func) { QEventLoop looper; auto *cmd_process = new QProcess(&looper); @@ -226,19 +224,18 @@ void CommonUtils::SlotExecuteCommand( &QEventLoop::quit); connect(cmd_process, &QProcess::errorOccurred, &looper, &QEventLoop::quit); connect(cmd_process, &QProcess::started, - []() -> void { LOG(INFO) << "process started"; }); + []() -> void { SPDLOG_INFO("process started"); }); connect(cmd_process, &QProcess::readyReadStandardOutput, [interact_func, cmd_process]() { interact_func(cmd_process); }); - connect(cmd_process, &QProcess::errorOccurred, this, [=]() -> void { - LOG(ERROR) << "Error in Process"; - }); + connect(cmd_process, &QProcess::errorOccurred, this, + [=]() -> void { SPDLOG_ERROR("error in process"); }); connect(cmd_process, qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this, [=](int, QProcess::ExitStatus status) { if (status == QProcess::NormalExit) - LOG(INFO) << "succeed in executing command:" << cmd; + SPDLOG_INFO("succeed in executing command: {}", cmd); else - LOG(WARNING) << "error in executing command:" << cmd; + SPDLOG_WARN("error in executing command: {}", cmd); }); cmd_process->setProgram(QString::fromStdString(cmd)); @@ -247,7 +244,6 @@ void CommonUtils::SlotExecuteCommand( looper.exec(); } - void CommonUtils::SlotExecuteGpgCommand( const QStringList &arguments, const std::function<void(QProcess *)> &interact_func) { @@ -265,11 +261,11 @@ void CommonUtils::SlotExecuteGpgCommand( &WaitingDialog::deleteLater); connect(gpg_process, &QProcess::errorOccurred, &looper, &QEventLoop::quit); connect(gpg_process, &QProcess::started, - []() -> void { LOG(INFO) << "gpg process started"; }); + []() -> void { SPDLOG_INFO("gpg process started"); }); connect(gpg_process, &QProcess::readyReadStandardOutput, [interact_func, gpg_process]() { interact_func(gpg_process); }); connect(gpg_process, &QProcess::errorOccurred, this, [=]() -> void { - LOG(ERROR) << "Error in Process"; + SPDLOG_ERROR("Error in Process"); dialog->close(); QMessageBox::critical(nullptr, _("Failure"), _("Failed to execute command.")); @@ -319,10 +315,10 @@ void CommonUtils::SlotImportKeyFromKeyServer( target_keyserver = key_server_list[target_key_server_index].get<std::string>(); - LOG(INFO) << _("Set target Key Server to default Key Server") - << target_keyserver; + SPDLOG_INFO("set target key server to default Key Server: {}", + target_keyserver); } catch (...) { - LOG(ERROR) << _("Cannot read default_keyserver From Settings"); + SPDLOG_ERROR(_("Cannot read default_keyserver From Settings")); QMessageBox::critical( nullptr, _("Default Keyserver Not Found"), _("Cannot read default keyserver from your settings, " @@ -343,7 +339,7 @@ void CommonUtils::SlotImportKeyFromKeyServer( target_keyserver_url.scheme() + "://" + target_keyserver_url.host() + "/pks/lookup?op=get&search=0x" + key_id.c_str() + "&options=mr"); - LOG(INFO) << "request url" << req_url.toString().toStdString(); + SPDLOG_INFO("request url: {}", req_url.toString().toStdString()); // Waiting for reply QNetworkReply *reply = network_manager->get(QNetworkRequest(req_url)); @@ -396,7 +392,7 @@ void CommonUtils::SlotImportKeyFromKeyServer( } void CommonUtils::slot_update_key_status() { - LOG(INFO) << "called"; + SPDLOG_INFO("called"); auto refresh_task = new Thread::Task([](Thread::Task::DataObjectPtr) -> int { // flush key cache for all GpgKeyGetter Intances. diff --git a/src/ui/dialog/GeneralDialog.cpp b/src/ui/dialog/GeneralDialog.cpp index 6fd2f32c..69138dbd 100644 --- a/src/ui/dialog/GeneralDialog.cpp +++ b/src/ui/dialog/GeneralDialog.cpp @@ -39,7 +39,7 @@ GpgFrontend::UI::GeneralDialog::~GeneralDialog() = default; void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept { try { - LOG(INFO) << name_ << _("Called"); + SPDLOG_INFO(name_, _("Called")); SettingsObject general_windows_state(name_ + "_dialog_state"); @@ -60,8 +60,6 @@ void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept { size_ = {width, height}; if (this->parent() != nullptr) { - LOG(INFO) << "parent address" << this->parent(); - QPoint parent_pos = {0, 0}; QSize parent_size = {0, 0}; @@ -83,14 +81,13 @@ void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept { parent_size = parent_window->size(); } - LOG(INFO) << "parent pos x:" << parent_pos.x() - << "y:" << parent_pos.y(); + SPDLOG_INFO("parent pos x: {} y: {}", parent_pos.x(), parent_pos.y()); - LOG(INFO) << "parent size width:" << parent_size.width() - << "height:" << parent_size.height(); + SPDLOG_INFO("parent size width: {} height: {}", parent_size.width(), + parent_size.height()); - LOG(INFO) << "this dialog size width:" << size_.width() - << "height:" << size_.height(); + SPDLOG_INFO("this dialog size width: {} height: {}", size_.width(), + size_.height()); if (parent_pos != QPoint{0, 0}) { QPoint parent_center{parent_pos.x() + parent_size.width() / 2, @@ -110,14 +107,12 @@ void GpgFrontend::UI::GeneralDialog::slot_restore_settings() noexcept { } } catch (...) { - LOG(ERROR) << name_ << "error"; + SPDLOG_ERROR(name_, "error"); } } void GpgFrontend::UI::GeneralDialog::slot_save_settings() noexcept { try { - LOG(INFO) << name_ << _("Called"); - SettingsObject general_windows_state(name_ + "_dialog_state"); // window position and size @@ -132,7 +127,7 @@ void GpgFrontend::UI::GeneralDialog::slot_save_settings() noexcept { general_windows_state["window_save"] = true; } catch (...) { - LOG(ERROR) << name_ << "error"; + SPDLOG_ERROR(name_, "error"); } } @@ -142,8 +137,7 @@ void GpgFrontend::UI::GeneralDialog::setPosCenterOfScreen() { int screen_width = geo.width(); int screen_height = geo.height(); - LOG(INFO) << "primary screen available geometry" << screen_width - << screen_height; + SPDLOG_INFO("primary screen available geometry", screen_width, screen_height); pos_ = QPoint((screen_width - QWidget::width()) / 2, (screen_height - QWidget::height()) / 2); @@ -155,13 +149,13 @@ void GpgFrontend::UI::GeneralDialog::setPosCenterOfScreen() { * */ void GpgFrontend::UI::GeneralDialog::movePosition2CenterOfParent() { - LOG(INFO) << "parent pos x:" << parent_pos_.x() << "y:" << parent_pos_.y(); + SPDLOG_INFO("parent pos x: {} y: {}", parent_pos_.x(), parent_pos_.y()); - LOG(INFO) << "parent size width:" << parent_size_.width() - << "height:" << parent_size_.height(); + SPDLOG_INFO("parent size width: {}", parent_size_.width(), + "height:", parent_size_.height()); if (parent_pos_ != QPoint{0, 0} && parent_size_ != QSize{0, 0}) { - LOG(INFO) << "update current dialog position now"; + SPDLOG_INFO("update current dialog position now"); QPoint parent_center{parent_pos_.x() + parent_size_.width() / 2, parent_pos_.y() + parent_size_.height() / 2}; diff --git a/src/ui/dialog/WaitingDialog.cpp b/src/ui/dialog/WaitingDialog.cpp index a4412e57..f014ac3d 100644 --- a/src/ui/dialog/WaitingDialog.cpp +++ b/src/ui/dialog/WaitingDialog.cpp @@ -57,8 +57,8 @@ WaitingDialog::WaitingDialog(const QString& title, QWidget* parent) int screen_width = geo.width(); int screen_height = geo.height(); - LOG(INFO) << "primary screen available geometry" << screen_width - << screen_height; + SPDLOG_INFO("primary screen available geometry: {} {}", screen_width, + screen_height); auto pos = QPoint((screen_width - QWidget::width()) / 2, (screen_height - QWidget::height()) / 2); @@ -67,7 +67,7 @@ WaitingDialog::WaitingDialog(const QString& title, QWidget* parent) } else { auto pos = QPoint(parent->x() + (parent->width() - QWidget::width()) / 2, parent->y() + (parent->height() - QWidget::height()) / 2); - LOG(INFO) << "pos" << pos.x() << pos.y(); + SPDLOG_INFO("pos: {} {}", pos.x(), pos.y()); this->move(pos); } diff --git a/src/ui/dialog/Wizard.cpp b/src/ui/dialog/Wizard.cpp index 0f051874..1a18a0b3 100644 --- a/src/ui/dialog/Wizard.cpp +++ b/src/ui/dialog/Wizard.cpp @@ -52,7 +52,7 @@ Wizard::Wizard(QWidget* parent) : QWizard(parent) { try { next_page_id = settings.lookup("wizard.next_page"); } catch (...) { - LOG(ERROR) << _("Setting Operation Error"); + SPDLOG_ERROR("setting operation error"); } setStartId(next_page_id); @@ -60,7 +60,7 @@ Wizard::Wizard(QWidget* parent) : QWizard(parent) { } void Wizard::slot_wizard_accepted() { - LOG(INFO) << _("Called"); + SPDLOG_INFO("called"); // Don't show is mapped to show -> negation try { auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); @@ -75,7 +75,7 @@ void Wizard::slot_wizard_accepted() { } GlobalSettingStation::GetInstance().SyncSettings(); } catch (...) { - LOG(ERROR) << _("Setting Operation Error"); + SPDLOG_ERROR("setting operation error"); } if (field("openHelp").toBool()) { emit SignalOpenHelp("docu.html#content"); @@ -223,7 +223,7 @@ KeyGenPage::KeyGenPage(QWidget* parent) : QWizardPage(parent) { int KeyGenPage::nextId() const { return Wizard::Page_Conclusion; } void KeyGenPage::slot_generate_key_dialog() { - LOG(INFO) << "Try Opening KeyGenDialog"; + SPDLOG_INFO("try opening KeyGenDialog"); (new KeyGenDialog(this))->show(); wizard()->next(); } diff --git a/src/ui/dialog/help/AboutDialog.cpp b/src/ui/dialog/help/AboutDialog.cpp index 25ace162..3fc09ff1 100644 --- a/src/ui/dialog/help/AboutDialog.cpp +++ b/src/ui/dialog/help/AboutDialog.cpp @@ -52,7 +52,7 @@ AboutDialog::AboutDialog(int defaultIndex, QWidget* parent) tab_widget->addTab(update_tab_, _("Update")); connect(tab_widget, &QTabWidget::currentChanged, this, - [&](int index) { LOG(INFO) << "Current Index" << index; }); + [&](int index) { SPDLOG_INFO("current index: {}", index); }); if (defaultIndex < tab_widget->count() && defaultIndex >= 0) { tab_widget->setCurrentIndex(defaultIndex); @@ -203,7 +203,7 @@ UpdateTab::UpdateTab(QWidget* parent) : QWidget(parent) { void UpdateTab::getLatestVersion() { this->pb_->setHidden(false); - LOG(INFO) << _("try to get latest version"); + SPDLOG_INFO("try to get latest version"); auto* version_task = new VersionCheckTask(); diff --git a/src/ui/dialog/help/GnupgTab.cpp b/src/ui/dialog/help/GnupgTab.cpp index 8be35416..92e2786d 100644 --- a/src/ui/dialog/help/GnupgTab.cpp +++ b/src/ui/dialog/help/GnupgTab.cpp @@ -79,7 +79,7 @@ GpgFrontend::UI::GnupgTab::GnupgTab(QWidget* parent) } void GpgFrontend::UI::GnupgTab::process_software_info() { - LOG(INFO) << "called"; + SPDLOG_INFO("called"); auto ctx_info = GpgContext::GetInstance().GetInfo(true); diff --git a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp index 31183a34..7a8ec0ed 100644 --- a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp +++ b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp @@ -129,7 +129,7 @@ void KeyImportDetailDialog::create_general_info_box() { } void KeyImportDetailDialog::create_keys_table() { - LOG(INFO) << "KeyImportDetailDialog::create_keys_table() Called"; + SPDLOG_INFO("KeyImportDetailDialog::create_keys_table() Called"); keys_table_ = new QTableWidget(this); keys_table_->setRowCount(0); diff --git a/src/ui/dialog/import_export/KeyServerImportDialog.cpp b/src/ui/dialog/import_export/KeyServerImportDialog.cpp index 6430a22e..a018cdfc 100644 --- a/src/ui/dialog/import_export/KeyServerImportDialog.cpp +++ b/src/ui/dialog/import_export/KeyServerImportDialog.cpp @@ -177,8 +177,7 @@ QComboBox* KeyServerImportDialog::create_comboBox() { comboBox->setCurrentText(default_key_server.c_str()); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << "server_list" - << "default_server"; + SPDLOG_ERROR("setting operation error", "server_list", "default_server"); } return comboBox; @@ -253,8 +252,8 @@ void KeyServerImportDialog::slot_search() { void KeyServerImportDialog::slot_search_finished( QNetworkReply::NetworkError error, QByteArray buffer) { - LOG(INFO) << "Called" << error << buffer.size(); - LOG(INFO) << buffer.toStdString(); + SPDLOG_INFO("called {} {}", error, buffer.size()); + SPDLOG_INFO(buffer.toStdString()); keys_table_->clearContents(); keys_table_->setRowCount(0); @@ -262,7 +261,7 @@ void KeyServerImportDialog::slot_search_finished( auto stream = QTextStream(buffer); if (error != QNetworkReply::NoError) { - LOG(INFO) << "Error From Reply" << error; + SPDLOG_INFO("error from reply: {}", error); switch (error) { case QNetworkReply::ContentNotFoundError: @@ -440,8 +439,7 @@ void KeyServerImportDialog::SlotImport(const KeyIdArgsListPtr& keys) { target_keyserver = default_key_server; } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << "server_list" - << "default_server"; + SPDLOG_ERROR("setting operation error", "server_list", "default_server"); QMessageBox::critical( nullptr, _("Default Keyserver Not Found"), _("Cannot read default keyserver from your settings, " @@ -470,10 +468,10 @@ void KeyServerImportDialog::SlotImport(std::vector<std::string> key_ids, void KeyServerImportDialog::slot_import_finished( QNetworkReply::NetworkError error, QByteArray buffer) { - LOG(INFO) << _("Called"); + SPDLOG_INFO("called"); if (error != QNetworkReply::NoError) { - LOG(ERROR) << "Error From Reply" << buffer.toStdString(); + SPDLOG_ERROR("Error From Reply", buffer.toStdString()); if (!m_automatic_) { switch (error) { case QNetworkReply::ContentNotFoundError: diff --git a/src/ui/dialog/import_export/KeyUploadDialog.cpp b/src/ui/dialog/import_export/KeyUploadDialog.cpp index ad4be0cb..d8d2515e 100644 --- a/src/ui/dialog/import_export/KeyUploadDialog.cpp +++ b/src/ui/dialog/import_export/KeyUploadDialog.cpp @@ -41,7 +41,6 @@ KeyUploadDialog::KeyUploadDialog(const KeyIdArgsListPtr& keys_ids, QWidget* parent) : GeneralDialog(typeid(KeyUploadDialog).name(), parent), m_keys_(GpgKeyGetter::GetInstance().GetKeys(keys_ids)) { - auto* pb = new QProgressBar(); pb->setRange(0, 0); pb->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); @@ -71,7 +70,6 @@ void KeyUploadDialog::SlotUpload() { void KeyUploadDialog::slot_upload_key_to_server( const GpgFrontend::ByteArray& keys_data) { - std::string target_keyserver; try { @@ -88,11 +86,11 @@ void KeyUploadDialog::slot_upload_key_to_server( target_keyserver = key_server_list[default_key_server_index].get<std::string>(); - LOG(INFO) << _("Set target Key Server to default Key Server") - << target_keyserver; + SPDLOG_INFO("set target key server to default key server: {}", + target_keyserver); } catch (...) { - LOG(ERROR) << _("Cannot read default_keyserver From Settings"); + SPDLOG_ERROR(_("Cannot read default_keyserver From Settings")); QMessageBox::critical(nullptr, _("Default Keyserver Not Found"), _("Cannot read default keyserver from your settings, " "please set a default keyserver first")); @@ -139,11 +137,11 @@ void KeyUploadDialog::slot_upload_finished() { auto* reply = qobject_cast<QNetworkReply*>(sender()); QByteArray response = reply->readAll(); - LOG(INFO) << "Response: " << response.toStdString(); + SPDLOG_INFO("response: {}", response.toStdString()); auto error = reply->error(); if (error != QNetworkReply::NoError) { - LOG(INFO) << "Error From Reply" << reply->errorString().toStdString(); + SPDLOG_INFO("error from reply: {}", reply->errorString().toStdString()); QString message; switch (error) { case QNetworkReply::ContentNotFoundError: @@ -163,7 +161,7 @@ void KeyUploadDialog::slot_upload_finished() { } else { QMessageBox::information(this, _("Upload Success"), _("Upload Public Key Successfully")); - LOG(INFO) << "Success while contacting keyserver!"; + SPDLOG_INFO("success while contacting keyserver!"); } reply->deleteLater(); } diff --git a/src/ui/dialog/key_generate/KeygenDialog.cpp b/src/ui/dialog/key_generate/KeygenDialog.cpp index b7ba6369..3fd2a357 100644 --- a/src/ui/dialog/key_generate/KeygenDialog.cpp +++ b/src/ui/dialog/key_generate/KeygenDialog.cpp @@ -46,10 +46,10 @@ KeyGenDialog::KeyGenDialog(QWidget* parent) bool longer_expiration_date = false; try { longer_expiration_date = settings.lookup("general.longer_expiration_date"); - LOG(INFO) << "longer_expiration_date" << longer_expiration_date; + SPDLOG_INFO("longer_expiration_date: {}", longer_expiration_date); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("longer_expiration_date"); + SPDLOG_ERROR("setting operation error: longer_expiration_date"); } max_date_time_ = longer_expiration_date @@ -145,7 +145,7 @@ void KeyGenDialog::slot_key_gen_accept() { dialog->close(); - LOG(INFO) << "generate done"; + SPDLOG_INFO("generate done"); if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) { auto* msg_box = new QMessageBox((QWidget*)this->parent()); @@ -156,7 +156,7 @@ void KeyGenDialog::slot_key_gen_accept() { msg_box->setModal(true); msg_box->open(); - LOG(INFO) << "generate success"; + SPDLOG_INFO("generate success"); emit SignalKeyGenerated(); this->close(); @@ -252,7 +252,7 @@ void KeyGenDialog::slot_authentication_box_changed(int state) { } void KeyGenDialog::slot_activated_key_type(int index) { - qDebug() << "key type index changed " << index; + SPDLOG_INFO("key type index changed: {}", index); // check assert(gen_key_info_->GetSupportedKeyAlgo().size() > index); @@ -261,7 +261,7 @@ void KeyGenDialog::slot_activated_key_type(int index) { } void KeyGenDialog::refresh_widgets_state() { - qDebug() << "refresh_widgets_state called"; + SPDLOG_INFO("refresh_widgets_state called"); if (gen_key_info_->IsAllowEncryption()) key_usage_check_boxes_[0]->setCheckState(Qt::CheckState::Checked); diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp index afa768f0..661f63c6 100644 --- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp @@ -45,10 +45,10 @@ SubkeyGenerateDialog::SubkeyGenerateDialog(const KeyId& key_id, QWidget* parent) bool longer_expiration_date = false; try { longer_expiration_date = settings.lookup("general.longer_expiration_date"); - LOG(INFO) << "longer_expiration_date" << longer_expiration_date; + SPDLOG_INFO("longer expiration date: {}", longer_expiration_date); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("longer_expiration_date"); + SPDLOG_ERROR("setting operation error: longer_expiration_date"); } max_date_time_ = longer_expiration_date @@ -190,7 +190,7 @@ void SubkeyGenerateDialog::slot_expire_box_changed() { } void SubkeyGenerateDialog::refresh_widgets_state() { - LOG(INFO) << "refresh_widgets_state called"; + SPDLOG_INFO("refresh_widgets_state called"); if (gen_key_info_->IsAllowEncryption()) key_usage_check_boxes_[0]->setCheckState(Qt::CheckState::Checked); @@ -263,7 +263,7 @@ void SubkeyGenerateDialog::slot_key_gen_accept() { GpgError error; auto thread = QThread::create([&]() { - LOG(INFO) << "Thread Started"; + SPDLOG_INFO("thread started"); error = GpgKeyOpera::GetInstance().GenerateSubkey(key_, gen_key_info_); }); thread->start(); @@ -338,7 +338,7 @@ void SubkeyGenerateDialog::slot_authentication_box_changed(int state) { } void SubkeyGenerateDialog::slot_activated_key_type(int index) { - qDebug() << "key type index changed " << index; + SPDLOG_INFO("key type index changed: {}", index); // check assert(gen_key_info_->GetSupportedSubkeyAlgo().size() > index); diff --git a/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp index b4d2d688..75e5b0b9 100644 --- a/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairDetailTab.cpp @@ -35,8 +35,8 @@ namespace GpgFrontend::UI { KeyPairDetailTab::KeyPairDetailTab(const std::string& key_id, QWidget* parent) : QWidget(parent), key_(GpgKeyGetter::GetInstance().GetKey(key_id)) { - LOG(INFO) << key_.GetEmail() << key_.IsPrivateKey() << key_.IsHasMasterKey() - << key_.GetSubKeys()->front().IsPrivateKey(); + SPDLOG_INFO(key_.GetEmail(), key_.IsPrivateKey(), key_.IsHasMasterKey(), + key_.GetSubKeys()->front().IsPrivateKey()); owner_box_ = new QGroupBox(_("Owner")); key_box_ = new QGroupBox(_("Primary Key")); @@ -269,7 +269,7 @@ void KeyPairDetailTab::slot_refresh_key_info() { } void KeyPairDetailTab::slot_refresh_key() { - LOG(INFO) << _("called"); + SPDLOG_INFO("called"); // refresh the key GpgKey refreshed_key = GpgKeyGetter::GetInstance().GetKey(key_.GetId()); diff --git a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp index 77eba0bc..5755d2c2 100644 --- a/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairOperaTab.cpp @@ -296,7 +296,7 @@ void KeyPairOperaTab::slot_gen_revoke_cert() { // Code From Gpg4Win while (proc->canReadLine()) { const QString line = QString::fromUtf8(proc->readLine()).trimmed(); - LOG(INFO) << "line" << line.toStdString(); + SPDLOG_INFO("line: {}", line.toStdString()); if (line == QLatin1String("[GNUPG:] GET_BOOL gen_revoke.okay")) { proc->write("y\n"); } else if (line == QLatin1String("[GNUPG:] GET_LINE " @@ -336,7 +336,7 @@ void KeyPairOperaTab::slot_modify_tofu_policy() { this, _("Modify TOFU Policy(Default is Auto)"), _("Policy for the Key Pair:"), items, 0, false, &ok); if (ok && !item.isEmpty()) { - LOG(INFO) << "selected policy" << item.toStdString(); + SPDLOG_INFO("selected policy: {}", item.toStdString()); gpgme_tofu_policy_t tofu_policy = GPGME_TOFU_POLICY_AUTO; if (item == _("Policy Auto")) { tofu_policy = GPGME_TOFU_POLICY_AUTO; diff --git a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp index be67e5ca..e86d44db 100644 --- a/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairSubkeyTab.cpp @@ -35,8 +35,8 @@ namespace GpgFrontend::UI { KeyPairSubkeyTab::KeyPairSubkeyTab(const std::string& key_id, QWidget* parent) : QWidget(parent), key_(GpgKeyGetter::GetInstance().GetKey(key_id)) { - LOG(INFO) << key_.GetEmail() << key_.IsPrivateKey() << key_.IsHasMasterKey() - << key_.GetSubKeys()->front().IsPrivateKey(); + SPDLOG_INFO(key_.GetEmail(), key_.IsPrivateKey(), key_.IsHasMasterKey(), + key_.GetSubKeys()->front().IsPrivateKey()); create_subkey_list(); create_subkey_opera_menu(); @@ -165,7 +165,7 @@ void KeyPairSubkeyTab::create_subkey_list() { } void KeyPairSubkeyTab::slot_refresh_subkey_list() { - LOG(INFO) << "called"; + SPDLOG_INFO("called"); int row = 0; subkey_list_->setSelectionMode(QAbstractItemView::SingleSelection); @@ -177,9 +177,8 @@ void KeyPairSubkeyTab::slot_refresh_subkey_list() { this->buffered_subkeys_.push_back(std::move(sub_key)); } - LOG(INFO) << "buffered_subkeys_" - << "refreshed" - << "size" << this->buffered_subkeys_.size(); + SPDLOG_INFO("buffered_subkeys_ refreshed size", + this->buffered_subkeys_.size()); subkey_list_->setRowCount(buffered_subkeys_.size()); @@ -216,20 +215,18 @@ void KeyPairSubkeyTab::slot_refresh_subkey_list() { } } - LOG(INFO) << "subkey_list_ item" << row << "refreshed"; + SPDLOG_INFO("subkey_list_ item {} refreshed", row); row++; } - LOG(INFO) << "subkey_list_" - << "refreshed"; + SPDLOG_INFO("subkey_list_ refreshed"); if (subkey_list_->rowCount() > 0) { subkey_list_->selectRow(0); } - LOG(INFO) << "slot_refresh_subkey_list" - << "ended"; + SPDLOG_INFO("slot_refresh_subkey_list ended"); } void KeyPairSubkeyTab::slot_add_subkey() { @@ -318,7 +315,7 @@ void KeyPairSubkeyTab::create_subkey_opera_menu() { } void KeyPairSubkeyTab::slot_edit_subkey() { - LOG(INFO) << "Fpr" << get_selected_subkey().GetFingerprint(); + SPDLOG_INFO("fpr {}", get_selected_subkey().GetFingerprint()); auto dialog = new KeySetExpireDateDialog( key_.GetId(), get_selected_subkey().GetFingerprint(), this); @@ -344,7 +341,7 @@ const GpgSubKey& KeyPairSubkeyTab::get_selected_subkey() { return buffered_subkeys_[row]; } void KeyPairSubkeyTab::slot_refresh_key_info() { - LOG(INFO) << "called"; + SPDLOG_INFO("called"); key_ = GpgKeyGetter::GetInstance().GetKey(key_.GetId()); } diff --git a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp index caa4e3be..a73d091b 100644 --- a/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp +++ b/src/ui/dialog/keypair_details/KeyPairUIDTab.cpp @@ -225,7 +225,7 @@ void KeyPairUIDTab::slot_refresh_tofu_info() { continue; } auto tofu_infos = uid.GetTofuInfos(); - LOG(INFO) << "tofu info size" << tofu_infos->size(); + SPDLOG_INFO("tofu info size: {}", tofu_infos->size()); if (tofu_infos->empty()) { tofu_tabs_->hide(); } else { @@ -382,7 +382,7 @@ void KeyPairUIDTab::slot_del_uid() { if (ret == QMessageBox::Yes) { for (const auto& uid : *selected_uids) { - LOG(INFO) << "KeyPairUIDTab::slot_del_uid UID" << uid; + SPDLOG_INFO("uid: {}", uid); if (!GpgUIDOperator::GetInstance().RevUID(m_key_, uid)) { QMessageBox::critical( nullptr, _("Operation Failed"), @@ -574,7 +574,7 @@ void KeyPairUIDTab::slot_del_sign() { } } void KeyPairUIDTab::slot_refresh_key() { - LOG(INFO) << "called"; + SPDLOG_INFO("called"); // refresh the key GpgKey refreshed_key = GpgKeyGetter::GetInstance().GetKey(m_key_.GetId()); diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp index 2c10b895..721be11c 100644 --- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp +++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp @@ -57,16 +57,17 @@ KeySetExpireDateDialog::KeySetExpireDateDialog(const KeyId& key_id, } void KeySetExpireDateDialog::slot_confirm() { - LOG(INFO) << "Called" << ui_->dateEdit->date().toString().toStdString() - << ui_->timeEdit->time().toString().toStdString(); + SPDLOG_INFO("called: {} {}", ui_->dateEdit->date().toString().toStdString(), + ui_->timeEdit->time().toString().toStdString()); auto datetime = QDateTime(ui_->dateEdit->date(), ui_->timeEdit->time()); std::unique_ptr<boost::posix_time::ptime> expires = nullptr; if (ui_->noExpirationCheckBox->checkState() == Qt::Unchecked) { expires = std::make_unique<boost::posix_time::ptime>( boost::posix_time::from_time_t(datetime.toLocalTime().toTime_t())); - LOG(INFO) << "keyid" << m_key_.GetId() << m_subkey_ << *expires; + SPDLOG_INFO("keyid: {}", m_key_.GetId(), m_subkey_, + to_iso_string(*expires)); } else { - LOG(INFO) << "keyid" << m_key_.GetId() << m_subkey_ << "Non Expired"; + SPDLOG_INFO("keyid: {}", m_key_.GetId(), m_subkey_, "Non Expired"); } auto err = GpgKeyOpera::GetInstance().SetExpire(m_key_, m_subkey_, expires); @@ -98,10 +99,10 @@ void KeySetExpireDateDialog::init() { bool longer_expiration_date = false; try { longer_expiration_date = settings.lookup("general.longer_expiration_date"); - LOG(INFO) << "longer_expiration_date" << longer_expiration_date; + SPDLOG_INFO("longer_expiration_date: {}", longer_expiration_date); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("longer_expiration_date"); + SPDLOG_ERROR("setting operation error: longer_expiration_date"); } auto max_date_time = diff --git a/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp b/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp index 0f7de587..f582df0b 100644 --- a/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp +++ b/src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp @@ -104,19 +104,19 @@ KeyUIDSignDialog::KeyUIDSignDialog(const GpgKey& key, UIDArgsListPtr uid, } void KeyUIDSignDialog::slot_sign_key(bool clicked) { - LOG(INFO) << "Called"; + SPDLOG_INFO("called"); // Set Signers auto key_ids = m_key_list_->GetChecked(); auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids); - LOG(INFO) << "Key Info Got"; + SPDLOG_INFO("key info got"); auto expires = std::make_unique<boost::posix_time::ptime>( boost::posix_time::from_time_t(expires_edit_->dateTime().toTime_t())); - LOG(INFO) << "Sign Start"; + SPDLOG_INFO("sign start"); for (const auto& uid : *m_uids_) { - LOG(INFO) << "Sign UID" << uid; + SPDLOG_INFO("sign uid: {}", uid); // Sign For mKey if (!GpgKeyManager::GetInstance().SignKey(m_key_, *keys, uid, expires)) { QMessageBox::critical( diff --git a/src/ui/dialog/settings/SettingsAdvanced.cpp b/src/ui/dialog/settings/SettingsAdvanced.cpp index 516d4d02..e10b5dd1 100644 --- a/src/ui/dialog/settings/SettingsAdvanced.cpp +++ b/src/ui/dialog/settings/SettingsAdvanced.cpp @@ -60,7 +60,7 @@ void AdvancedTab::SetSettings() { bool stegano_checked = settings.lookup("advanced.stegano_checked"); if (stegano_checked) stegano_check_box_->setCheckState(Qt::Checked); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("stegano_checked"); + SPDLOG_ERROR("setting operation error: stegano_checked"); } try { @@ -69,8 +69,7 @@ void AdvancedTab::SetSettings() { if (auto_pubkey_exchange_checked) auto_pubkey_exchange_check_box_->setCheckState(Qt::Checked); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") - << _("auto_pubkey_exchange_checked"); + SPDLOG_ERROR("setting operation error: auto_pubkey_exchange_checked"); } } diff --git a/src/ui/dialog/settings/SettingsDialog.cpp b/src/ui/dialog/settings/SettingsDialog.cpp index 6737a512..68223637 100644 --- a/src/ui/dialog/settings/SettingsDialog.cpp +++ b/src/ui/dialog/settings/SettingsDialog.cpp @@ -108,19 +108,19 @@ void SettingsDialog::slot_set_restart_needed(int mode) { } void SettingsDialog::SlotAccept() { - LOG(INFO) << "Called"; + SPDLOG_INFO("called"); general_tab_->ApplySettings(); appearance_tab_->ApplySettings(); key_server_tab_->ApplySettings(); network_tab_->ApplySettings(); - LOG(INFO) << "apply done"; + SPDLOG_INFO("apply done"); // write settings to filesystem GlobalSettingStation::GetInstance().SyncSettings(); - LOG(INFO) << "restart needed" << get_restart_needed(); + SPDLOG_INFO("restart needed: {}", get_restart_needed()); if (get_restart_needed()) { emit SignalRestartNeeded(get_restart_needed()); } @@ -139,7 +139,7 @@ QHash<QString, QString> SettingsDialog::ListLanguages() { for (int i = 0; i < file_names.size(); ++i) { QString locale = file_names[i]; - LOG(INFO) << "locale" << locale.toStdString(); + SPDLOG_INFO("locale: {}", locale.toStdString()); if (locale == "." || locale == "..") continue; // this works in qt 4.8 diff --git a/src/ui/dialog/settings/SettingsGeneral.cpp b/src/ui/dialog/settings/SettingsGeneral.cpp index 7c7f254d..1c7b7c27 100644 --- a/src/ui/dialog/settings/SettingsGeneral.cpp +++ b/src/ui/dialog/settings/SettingsGeneral.cpp @@ -98,8 +98,8 @@ GeneralTab::GeneralTab(QWidget* parent) this, _("Open Directory"), {}, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); - LOG(INFO) << "key databse path selected" - << selected_custom_key_database_path.toStdString(); + SPDLOG_INFO("key databse path selected: {}", + selected_custom_key_database_path.toStdString()); if (!selected_custom_key_database_path.isEmpty()) { auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); @@ -139,7 +139,7 @@ void GeneralTab::SetSettings() { if (save_key_checked) ui_->saveCheckedKeysCheckBox->setCheckState(Qt::Checked); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("save_key_checked"); + SPDLOG_ERROR("setting operation error: save_key_checked"); } try { @@ -148,24 +148,24 @@ void GeneralTab::SetSettings() { if (clear_gpg_password_cache) ui_->clearGpgPasswordCacheCheckBox->setCheckState(Qt::Checked); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("clear_gpg_password_cache"); + SPDLOG_ERROR("setting operation error: clear_gpg_password_cache"); } try { bool longer_expiration_date = settings.lookup("general.longer_expiration_date"); - LOG(INFO) << "longer_expiration_date" << longer_expiration_date; + SPDLOG_INFO("longer_expiration_date: {}", longer_expiration_date); if (longer_expiration_date) ui_->longerKeyExpirationDateCheckBox->setCheckState(Qt::Checked); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("longer_expiration_date"); + SPDLOG_ERROR("setting operation error: longer_expiration_date"); } #ifdef MULTI_LANG_SUPPORT try { std::string lang_key = settings.lookup("general.lang"); QString lang_value = lang_.value(lang_key.c_str()); - LOG(INFO) << "lang settings current" << lang_value.toStdString(); + SPDLOG_INFO("lang settings current: {}", lang_value.toStdString()); if (!lang_.empty()) { ui_->langSelectBox->setCurrentIndex( ui_->langSelectBox->findText(lang_value)); @@ -173,27 +173,27 @@ void GeneralTab::SetSettings() { ui_->langSelectBox->setCurrentIndex(0); } } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("lang"); + SPDLOG_ERROR("setting operation error: lang"); } #endif try { bool confirm_import_keys = settings.lookup("general.confirm_import_keys"); - LOG(INFO) << "confirm_import_keys" << confirm_import_keys; + SPDLOG_INFO("confirm_import_keys: {}", confirm_import_keys); if (confirm_import_keys) ui_->importConfirmationCheckBox->setCheckState(Qt::Checked); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("confirm_import_keys"); + SPDLOG_ERROR("setting operation error: confirm_import_keys"); } try { bool non_ascii_when_export = settings.lookup("general.non_ascii_when_export"); - LOG(INFO) << "non_ascii_when_export" << non_ascii_when_export; + SPDLOG_INFO("non_ascii_when_export: {}", non_ascii_when_export); if (non_ascii_when_export) ui_->asciiModeCheckBox->setCheckState(Qt::Checked); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("non_ascii_when_export"); + SPDLOG_ERROR("setting operation error: non_ascii_when_export"); } try { @@ -202,8 +202,7 @@ void GeneralTab::SetSettings() { if (use_custom_key_database_path) ui_->keyDatabseUseCustomCheckBox->setCheckState(Qt::Checked); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") - << _("use_custom_key_database_path"); + SPDLOG_ERROR("setting operation error: use_custom_key_database_path"); } this->slot_update_custom_key_database_path_label( @@ -303,12 +302,11 @@ void GeneralTab::slot_update_custom_key_database_path_label(int state) { settings.lookup("general.custom_key_database_path")); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") - << _("custom_key_database_path"); + SPDLOG_ERROR("setting operation error: custom_key_database_path"); } - LOG(INFO) << "selected_custom_key_database_path from settings" - << custom_key_database_path; + SPDLOG_INFO("selected_custom_key_database_path from settings: {}", + custom_key_database_path); // set label value if (!custom_key_database_path.empty()) { diff --git a/src/ui/dialog/settings/SettingsKeyServer.cpp b/src/ui/dialog/settings/SettingsKeyServer.cpp index 365e19d4..558b3fcc 100644 --- a/src/ui/dialog/settings/SettingsKeyServer.cpp +++ b/src/ui/dialog/settings/SettingsKeyServer.cpp @@ -74,7 +74,7 @@ KeyserverTab::KeyserverTab(QWidget* parent) connect(ui_->keyServerListTable, &QTableWidget::itemChanged, [=](QTableWidgetItem* item) { - LOG(INFO) << "item edited" << item->column(); + SPDLOG_INFO("item edited: {}", item->column()); if (item->column() != 1) return; const auto row_size = ui_->keyServerListTable->rowCount(); // Update Actions @@ -137,7 +137,7 @@ void KeyserverTab::SetSettings() { key_server_str_list_.append(default_key_server.c_str()); default_key_server_ = QString::fromStdString(default_key_server); } catch (const std::exception& e) { - LOG(ERROR) << "Error reading key-server settings: " << e.what(); + SPDLOG_ERROR("Error reading key-server settings: ", e.what()); } } @@ -188,7 +188,7 @@ void KeyserverTab::ApplySettings() { } void KeyserverTab::slot_refresh_table() { - LOG(INFO) << "Start Refreshing Key Server Table"; + SPDLOG_INFO("start refreshing key server table"); ui_->keyServerListTable->blockSignals(true); ui_->keyServerListTable->setRowCount(key_server_str_list_.size()); diff --git a/src/ui/dialog/settings/SettingsNetwork.cpp b/src/ui/dialog/settings/SettingsNetwork.cpp index d4edae42..d3e4d199 100644 --- a/src/ui/dialog/settings/SettingsNetwork.cpp +++ b/src/ui/dialog/settings/SettingsNetwork.cpp @@ -76,28 +76,28 @@ void GpgFrontend::UI::NetworkTab::SetSettings() { std::string proxy_host = settings.lookup("proxy.proxy_host"); ui_->proxyServerAddressEdit->setText(proxy_host.c_str()); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("proxy_host"); + SPDLOG_ERROR("setting operation error: proxy_host"); } try { std::string std_username = settings.lookup("proxy.username"); ui_->usernameEdit->setText(std_username.c_str()); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("username"); + SPDLOG_ERROR("setting operation error: username"); } try { std::string std_password = settings.lookup("proxy.password"); ui_->passwordEdit->setText(std_password.c_str()); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("password"); + SPDLOG_ERROR("setting operation error: password"); } try { int port = settings.lookup("proxy.port"); ui_->portSpin->setValue(port); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("port"); + SPDLOG_ERROR("setting operation error: port"); } ui_->proxyTypeComboBox->setCurrentText("HTTP"); @@ -105,7 +105,7 @@ void GpgFrontend::UI::NetworkTab::SetSettings() { std::string proxy_type = settings.lookup("proxy.proxy_type"); ui_->proxyTypeComboBox->setCurrentText(proxy_type.c_str()); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("proxy_type"); + SPDLOG_ERROR("setting operation error: proxy_type"); } switch_ui_proxy_type(ui_->proxyTypeComboBox->currentText()); @@ -117,7 +117,7 @@ void GpgFrontend::UI::NetworkTab::SetSettings() { else ui_->enableProxyCheckBox->setCheckState(Qt::Unchecked); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("proxy_enable"); + SPDLOG_ERROR("setting operation error: proxy_enable"); } { @@ -134,7 +134,7 @@ void GpgFrontend::UI::NetworkTab::SetSettings() { else ui_->forbidALLCheckBox->setCheckState(Qt::Unchecked); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("forbid_all_connection"); + SPDLOG_ERROR("setting operation error: forbid_all_connection"); } ui_->prohibitUpdateCheck->setCheckState(Qt::Unchecked); @@ -146,12 +146,12 @@ void GpgFrontend::UI::NetworkTab::SetSettings() { else ui_->prohibitUpdateCheck->setCheckState(Qt::Unchecked); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("prohibit_update_checking"); + SPDLOG_ERROR("setting operation error: prohibit_update_checking"); } } void GpgFrontend::UI::NetworkTab::ApplySettings() { - LOG(INFO) << "called"; + SPDLOG_INFO("called"); auto &settings = GpgFrontend::GlobalSettingStation::GetInstance().GetUISettings(); @@ -225,7 +225,7 @@ void GpgFrontend::UI::NetworkTab::ApplySettings() { apply_proxy_settings(); - LOG(INFO) << "done"; + SPDLOG_INFO("done"); } void GpgFrontend::UI::NetworkTab::slot_test_proxy_connection_result() { @@ -270,7 +270,7 @@ void GpgFrontend::UI::NetworkTab::slot_test_proxy_connection_result() { waiting_dialog->deleteLater(); }); connect(waiting_dialog, &QProgressDialog::canceled, [=]() { - LOG(INFO) << "cancel clicked"; + SPDLOG_INFO("cancel clicked"); if (thread->isRunning()) thread->terminate(); }); diff --git a/src/ui/main_window/GeneralMainWindow.cpp b/src/ui/main_window/GeneralMainWindow.cpp index fb42d71a..98018c5f 100644 --- a/src/ui/main_window/GeneralMainWindow.cpp +++ b/src/ui/main_window/GeneralMainWindow.cpp @@ -47,7 +47,7 @@ void GpgFrontend::UI::GeneralMainWindow::closeEvent(QCloseEvent *event) { void GpgFrontend::UI::GeneralMainWindow::slot_restore_settings() noexcept { try { - LOG(INFO) << name_ << _("Called"); + SPDLOG_INFO(name_, _("Called")); SettingsObject general_windows_state(name_ + "_state"); @@ -75,7 +75,7 @@ void GpgFrontend::UI::GeneralMainWindow::slot_restore_settings() noexcept { size_ = {width, height}; if (this->parent() != nullptr) { - LOG(INFO) << "parent address" << this->parent(); + SPDLOG_INFO("parent address: {}", static_cast<void *>(this->parent())); QPoint parent_pos = {0, 0}; QSize parent_size = {0, 0}; @@ -92,11 +92,10 @@ void GpgFrontend::UI::GeneralMainWindow::slot_restore_settings() noexcept { parent_size = parent_window->size(); } - LOG(INFO) << "parent pos x:" << parent_pos.x() - << "y:" << parent_pos.y(); + SPDLOG_INFO("parent pos x: {} y: {}", parent_pos.x(), parent_pos.y()); - LOG(INFO) << "parent size width:" << parent_size.width() - << "height:" << parent_size.height(); + SPDLOG_INFO("parent size width: {} height: {}", parent_size.width(), + parent_size.height()); if (parent_pos != QPoint{0, 0}) { QPoint parent_center{parent_pos.x() + parent_size.width() / 2, @@ -116,7 +115,7 @@ void GpgFrontend::UI::GeneralMainWindow::slot_restore_settings() noexcept { int width = general_settings_state.Check("icon_size").Check("width", 24), height = general_settings_state.Check("icon_size").Check("height", 24); - LOG(INFO) << "icon_size" << width << height; + SPDLOG_INFO("icon size: {} {}", width, height); icon_size_ = {width, height}; font_size_ = general_settings_state.Check("font_size", 10); @@ -130,13 +129,13 @@ void GpgFrontend::UI::GeneralMainWindow::slot_restore_settings() noexcept { icon_style_ = toolButtonStyle(); } catch (...) { - LOG(ERROR) << name_ << "error"; + SPDLOG_ERROR(name_, "error"); } } void GpgFrontend::UI::GeneralMainWindow::slot_save_settings() noexcept { try { - LOG(INFO) << name_ << _("Called"); + SPDLOG_INFO(name_, _("Called")); SettingsObject general_windows_state(name_ + "_state"); @@ -166,6 +165,6 @@ void GpgFrontend::UI::GeneralMainWindow::slot_save_settings() noexcept { general_settings_state["icon_style"] = this->toolButtonStyle(); } catch (...) { - LOG(ERROR) << name_ << "error"; + SPDLOG_ERROR(name_, "error"); } } diff --git a/src/ui/main_window/KeyMgmt.cpp b/src/ui/main_window/KeyMgmt.cpp index 9df2b918..9183d9d7 100644 --- a/src/ui/main_window/KeyMgmt.cpp +++ b/src/ui/main_window/KeyMgmt.cpp @@ -431,7 +431,7 @@ void KeyMgmt::SlotExportAsOpenSSHFormat() { } void KeyMgmt::SlotImportKeyPackage() { - LOG(INFO) << "Importing key package..."; + SPDLOG_INFO("Importing key package..."); auto key_package_file_name = QFileDialog::getOpenFileName( this, _("Import Key Package"), {}, @@ -445,7 +445,7 @@ void KeyMgmt::SlotImportKeyPackage() { GpgImportInformation info; - LOG(INFO) << "Importing key package: " << key_package_file_name.toStdString(); + SPDLOG_INFO("importing key package: {}", key_package_file_name.toStdString()); if (KeyPackageOperator::ImportKeyPackage(key_package_file_name.toStdString(), key_file_name.toStdString(), info)) { diff --git a/src/ui/main_window/MainWindow.cpp b/src/ui/main_window/MainWindow.cpp index a5df66f0..aea84c32 100644 --- a/src/ui/main_window/MainWindow.cpp +++ b/src/ui/main_window/MainWindow.cpp @@ -109,7 +109,7 @@ void MainWindow::Init() noexcept { bool show_wizard = true; wizard.lookupValue("show_wizard", show_wizard); - LOG(INFO) << "wizard show_wizard" << show_wizard; + SPDLOG_INFO("wizard show_wizard: {}", show_wizard); if (show_wizard) { slot_start_wizard(); @@ -131,30 +131,29 @@ void MainWindow::Init() noexcept { // before application exit connect(qApp, &QCoreApplication::aboutToQuit, this, []() { - LOG(INFO) << "about to quit process started"; + SPDLOG_INFO("about to quit process started"); auto &settings = GlobalSettingStation::GetInstance().GetUISettings(); try { bool clear_gpg_password_cache = settings.lookup("general.clear_gpg_password_cache"); - + if (clear_gpg_password_cache) { if (GpgFrontend::GpgAdvancedOperator::GetInstance() .ClearGpgPasswordCache()) { - LOG(INFO) << "clear gpg password cache done"; + SPDLOG_INFO("clear gpg password cache done"); } else { - LOG(ERROR) << "clear gpg password cache error"; + SPDLOG_ERROR("clear gpg password cache error"); } } } catch (...) { - LOG(ERROR) << _("Setting Operation Error") - << _("clear_gpg_password_cache"); + SPDLOG_ERROR("setting operation error: clear_gpg_password_cache"); } }); } catch (...) { - LOG(FATAL) << _("Critical error occur while loading GpgFrontend."); + SPDLOG_ERROR(_("Critical error occur while loading GpgFrontend.")); QMessageBox::critical(nullptr, _("Loading Failed"), _("Critical error occur while loading GpgFrontend.")); QCoreApplication::quit(); @@ -163,10 +162,10 @@ void MainWindow::Init() noexcept { } void MainWindow::restore_settings() { - LOG(INFO) << _("Called"); + SPDLOG_INFO("called"); try { - LOG(INFO) << "restore settings key_server"; + SPDLOG_INFO("restore settings key_server"); SettingsObject key_server_json("key_server"); if (!key_server_json.contains("server_list") || @@ -202,7 +201,7 @@ void MainWindow::restore_settings() { import_button_->setToolButtonStyle(icon_style_); try { - LOG(INFO) << "restore settings default_key_checked"; + SPDLOG_INFO("restore settings default_key_checked"); // Checked Keys SettingsObject default_key_checked("default_key_checked"); @@ -210,13 +209,13 @@ void MainWindow::restore_settings() { auto key_ids_ptr = std::make_unique<KeyIdArgsList>(); for (auto &it : default_key_checked) { std::string key_id = it; - LOG(INFO) << "get checked key id" << key_id; + SPDLOG_INFO("get checked key id: {}", key_id); key_ids_ptr->push_back(key_id); } m_key_list_->SetChecked(std::move(key_ids_ptr)); } } catch (...) { - LOG(ERROR) << "restore default_key_checked failed"; + SPDLOG_ERROR("restore default_key_checked failed"); } prohibit_update_checking_ = false; @@ -224,16 +223,15 @@ void MainWindow::restore_settings() { prohibit_update_checking_ = settings.lookup("network.prohibit_update_checking"); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") - << _("prohibit_update_checking"); + SPDLOG_ERROR("setting operation error: prohibit_update_checking"); } } catch (...) { - LOG(ERROR) << "cannot resolve settings"; + SPDLOG_ERROR("cannot resolve settings"); } GlobalSettingStation::GetInstance().SyncSettings(); - LOG(INFO) << _("settings restored"); + SPDLOG_INFO("settings restored"); } void MainWindow::save_settings() { @@ -255,7 +253,7 @@ void MainWindow::save_settings() { settings["general"].remove("save_key_checked"); } } catch (...) { - LOG(ERROR) << "cannot save settings"; + SPDLOG_ERROR("cannot save settings"); }; GlobalSettingStation::GetInstance().SyncSettings(); diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp index 526c27c0..39326ad0 100644 --- a/src/ui/main_window/MainWindowFileSlotFunction.cpp +++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp @@ -67,7 +67,7 @@ bool path_pre_check(QWidget* parent, const QString& path) { */ bool process_tarball_into_directory(QWidget* parent, std::filesystem::path& path) { - LOG(INFO) << "Converting directory into tarball" << path; + SPDLOG_INFO("converting directory into tarball: {}", path.u8string()); auto selected_dir_path = std::filesystem::path(path); if (selected_dir_path.extension() != ".tar") { @@ -81,8 +81,8 @@ bool process_tarball_into_directory(QWidget* parent, auto target_path = selected_dir_path; target_path.replace_extension(".tar"); - LOG(INFO) << "base path" << base_path.u8string() << "target archive path" - << target_path.u8string(); + SPDLOG_INFO("base path: {} target archive path: {]", base_path.u8string(), + target_path.u8string()); bool if_error = false; process_operation(parent, _("Extracting Tarball"), @@ -101,7 +101,7 @@ bool process_tarball_into_directory(QWidget* parent, } path = target_path.u8string().c_str(); } catch (...) { - LOG(ERROR) << "decompress error"; + SPDLOG_ERROR("decompress error"); return false; } return true; @@ -125,8 +125,9 @@ bool process_directory_into_tarball(QWidget* parent, QString& path) { auto target_path = selected_dir_path; selected_dir_path.replace_extension(""); - LOG(INFO) << "base path" << base_path << "target archive path" - << target_path << "selected_dir_path" << selected_dir_path; + SPDLOG_INFO("base path: {} target archive path: {} selected_dir_path: {}", + base_path.u8string(), target_path.u8string(), + selected_dir_path.u8string()); bool if_error = false; process_operation(parent, _("Making Tarball"), @@ -145,7 +146,7 @@ bool process_directory_into_tarball(QWidget* parent, QString& path) { } path = target_path.u8string().c_str(); } catch (...) { - LOG(ERROR) << "compress error"; + SPDLOG_ERROR("compress error"); return false; } return true; @@ -156,7 +157,7 @@ void MainWindow::SlotFileEncrypt() { auto path = fileTreeView->GetSelected(); if (!path_pre_check(this, path)) { - LOG(ERROR) << "path pre check failed"; + SPDLOG_ERROR("path pre check failed"); return; } @@ -172,7 +173,7 @@ void MainWindow::SlotFileEncrypt() { try { non_ascii_when_export = settings.lookup("general.non_ascii_when_export"); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("non_ascii_when_export"); + SPDLOG_ERROR("setting operation error: non_ascii_when_export"); } // get file info @@ -395,7 +396,7 @@ void MainWindow::SlotFileSign() { try { non_ascii_when_export = settings.lookup("general.non_ascii_when_export"); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("non_ascii_when_export"); + SPDLOG_ERROR("setting operation error: non_ascii_when_export"); } auto _channel = GPGFRONTEND_DEFAULT_CHANNEL; @@ -474,7 +475,7 @@ void MainWindow::SlotFileVerify() { try { non_ascii_when_export = settings.lookup("general.non_ascii_when_export"); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("non_ascii_when_export"); + SPDLOG_ERROR("setting operation error: non_ascii_when_export"); } auto _channel = GPGFRONTEND_DEFAULT_CHANNEL; @@ -488,7 +489,8 @@ void MainWindow::SlotFileVerify() { data_file_path = sign_file_path.parent_path() / sign_file_path.stem(); } - LOG(INFO) << "sign_file_path" << sign_file_path << sign_file_path.extension(); + SPDLOG_INFO("sign_file_path: {} {}", sign_file_path.u8string(), + sign_file_path.extension().u8string()); if (in_path.extension() != ".gpg") { bool ok; @@ -511,8 +513,8 @@ void MainWindow::SlotFileVerify() { return; } - DLOG(INFO) << "data path" << data_file_path; - DLOG(INFO) << "sign path" << sign_file_path; + SPDLOG_INFO("data path: {}", data_file_path.u8string()); + SPDLOG_INFO("sign path: {}", sign_file_path.u8string()); GpgVerifyResult result = nullptr; gpgme_error_t error; @@ -585,7 +587,7 @@ void MainWindow::SlotFileEncryptSign() { try { non_ascii_when_export = settings.lookup("general.non_ascii_when_export"); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("non_ascii_when_export"); + SPDLOG_ERROR("setting operation error: non_ascii_when_export"); } // get file info @@ -697,7 +699,7 @@ void MainWindow::SlotFileDecryptVerify() { } else { out_path += ".out"; } - LOG(INFO) << "out path" << out_path; + SPDLOG_INFO("out path: {}", out_path.u8string()); if (QFile::exists(out_path.u8string().c_str())) { auto ret = diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 4a7f721a..e17ddaeb 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -341,7 +341,7 @@ void MainWindow::slot_verify() { auto buffer = data_object->PopObject<std::string>(); - LOG(INFO) << "Verify buffer: " << buffer.size(); + SPDLOG_INFO("verify buffer size: {}", buffer.size()); try { GpgVerifyResult verify_result = nullptr; @@ -430,11 +430,11 @@ void MainWindow::slot_encrypt_sign() { auto signer_keys = GpgKeyGetter::GetInstance().GetKeys(signer_key_ids); for (const auto& key : *keys) { - LOG(INFO) << "Keys " << key.GetEmail(); + SPDLOG_INFO("keys {}", key.GetEmail()); } for (const auto& signer : *signer_keys) { - LOG(INFO) << "Signers " << signer.GetEmail(); + SPDLOG_INFO("signers {}", signer.GetEmail()); } // data to transfer into task @@ -486,7 +486,6 @@ void MainWindow::slot_encrypt_sign() { auto sign_result = data_object->PopObject<GpgSignResult>(); auto tmp = data_object->PopObject<std::unique_ptr<ByteArray>>(); - LOG(INFO) << "GpgResultAnalyse Started"; auto encrypt_result_analyse = GpgEncryptResultAnalyse(error, std::move(encrypt_result)); auto sign_result_analyse = @@ -544,7 +543,7 @@ void MainWindow::slot_decrypt_verify() { data_object->AppendObject(std::move(decrypt_result)); data_object->AppendObject(std::move(error)); } catch (const std::runtime_error& e) { - LOG(ERROR) << e.what(); + SPDLOG_ERROR(e.what()); return -1; } return 0; @@ -660,10 +659,10 @@ void MainWindow::upload_key_to_server() { void MainWindow::SlotOpenFile(QString& path) { edit_->SlotOpenFile(path); } void MainWindow::slot_version_upgrade(const SoftwareVersion& version) { - LOG(INFO) << _("Called"); + SPDLOG_INFO("called"); if (!version.InfoValid()) { - LOG(INFO) << "Invalid version info"; + SPDLOG_INFO("invalid version info"); return; } diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp index 8961a33f..722be60a 100644 --- a/src/ui/main_window/MainWindowSlotUI.cpp +++ b/src/ui/main_window/MainWindowSlotUI.cpp @@ -104,13 +104,13 @@ void MainWindow::slot_open_settings_dialog() { auto dialog = new SettingsDialog(this); connect(dialog, &SettingsDialog::finished, this, [&]() -> void { - LOG(INFO) << "Setting Dialog Finished"; + SPDLOG_INFO("setting dialog finished"); SettingsObject general_settings_state("general_settings_state"); int width = general_settings_state.Check("icon_size").Check("width", 24), height = general_settings_state.Check("icon_size").Check("height", 24); - LOG(INFO) << "icon_size" << width << height; + SPDLOG_INFO("icon_size: {} {}", width, height); general_settings_state.Check("info_font_size", 10); @@ -184,7 +184,7 @@ void MainWindow::slot_cut_pgp_header() { } void MainWindow::SlotSetRestartNeeded(int mode) { - LOG(INFO) << "restart mode" << mode; + SPDLOG_INFO("restart mode: {}", mode); this->restart_needed_ = mode; } @@ -192,7 +192,7 @@ int MainWindow::get_restart_needed() const { return this->restart_needed_; } void MainWindow::SetCryptoMenuStatus( MainWindow::CryptoMenu::OperationType type) { - LOG(INFO) << "SetCryptoMenuStatus" << type; + SPDLOG_INFO("type: {}", type); // refresh status to disable all verify_act_->setDisabled(true); diff --git a/src/ui/struct/SettingsObject.cpp b/src/ui/struct/SettingsObject.cpp index 4a9aa7d6..f2fb4820 100644 --- a/src/ui/struct/SettingsObject.cpp +++ b/src/ui/struct/SettingsObject.cpp @@ -32,7 +32,7 @@ nlohmann::json& GpgFrontend::UI::SettingsObject::Check( const std::string& key, const nlohmann::json& default_value) { // check if the self null if (this->nlohmann::json::is_null()) { - LOG(INFO) << "SettingsObject is null, creating new one"; + SPDLOG_INFO("settings object is null, creating new one"); this->nlohmann::json::operator=(nlohmann::json::object()); } @@ -41,9 +41,9 @@ nlohmann::json& GpgFrontend::UI::SettingsObject::Check( this->nlohmann::json::at(key).is_null() || this->nlohmann::json::at(key).type_name() != default_value.type_name()) { - LOG(INFO) << "Added missing key: " << key; + SPDLOG_INFO("added missing key: {}", key); if (default_value.is_null()) { - LOG(WARNING) << "Default value is null, using empty object"; + SPDLOG_WARN("default value is null, using empty object"); this->nlohmann::json::operator[](key) = nlohmann::json::object(); } else { this->nlohmann::json::operator[](key) = default_value; @@ -51,7 +51,7 @@ nlohmann::json& GpgFrontend::UI::SettingsObject::Check( } return this->nlohmann::json::at(key); } catch (nlohmann::json::exception& e) { - LOG(ERROR) << e.what(); + SPDLOG_ERROR(e.what()); throw e; } } @@ -60,14 +60,14 @@ GpgFrontend::UI::SettingsObject GpgFrontend::UI::SettingsObject::Check( const std::string& key) { // check if the self null if (this->nlohmann::json::is_null()) { - LOG(INFO) << "SettingsObject is null, creating new one"; + SPDLOG_INFO("settings object is null, creating new one"); this->nlohmann::json::operator=(nlohmann::json::object()); } if (!nlohmann::json::contains(key) || this->nlohmann::json::at(key).is_null() || this->nlohmann::json::at(key).type() != nlohmann::json::value_t::object) { - LOG(INFO) << "Added missing key: " << key; + SPDLOG_INFO("added missing key: {}", key); this->nlohmann::json::operator[](key) = nlohmann::json::object(); } return SettingsObject{nlohmann::json::operator[](key), false}; @@ -76,21 +76,21 @@ GpgFrontend::UI::SettingsObject GpgFrontend::UI::SettingsObject::Check( GpgFrontend::UI::SettingsObject::SettingsObject(std::string settings_name) : settings_name_(std::move(settings_name)) { try { - LOG(INFO) << "Loading settings from: " << this->settings_name_; + SPDLOG_INFO("loading settings from: {}", this->settings_name_); auto _json_optional = GpgFrontend::DataObjectOperator::GetInstance().GetDataObject( settings_name_); if (_json_optional.has_value()) { - LOG(INFO) << "SettingsObject: " << settings_name_ << " loaded."; + SPDLOG_INFO("settings object: {} loaded.", settings_name_); nlohmann::json::operator=(_json_optional.value()); } else { - LOG(INFO) << "SettingsObject: " << settings_name_ << " not found."; + SPDLOG_INFO("settings object: {} not found.", settings_name_); nlohmann::json::operator=({}); } } catch (std::exception& e) { - LOG(ERROR) << e.what(); + SPDLOG_ERROR(e.what()); } } @@ -101,4 +101,4 @@ GpgFrontend::UI::SettingsObject::~SettingsObject() { if (!settings_name_.empty()) GpgFrontend::DataObjectOperator::GetInstance().SaveDataObj(settings_name_, *this); -} +}
\ No newline at end of file diff --git a/src/ui/struct/SoftwareVersion.cpp b/src/ui/struct/SoftwareVersion.cpp index 0059715a..a0ad594b 100644 --- a/src/ui/struct/SoftwareVersion.cpp +++ b/src/ui/struct/SoftwareVersion.cpp @@ -30,55 +30,54 @@ int GpgFrontend::UI::SoftwareVersion::version_compare(const std::string& a, const std::string& b) { + auto temp_a = a, temp_b = b; - auto temp_a = a, temp_b = b; + if (!temp_a.empty() && temp_a.front() == 'v') { + temp_a = temp_a.erase(0, 1); + SPDLOG_INFO("real version a: {}", temp_a); + } - if (!temp_a.empty() && temp_a.front() == 'v') { - temp_a = temp_a.erase(0, 1); - LOG(INFO) << "real version a" << temp_a; - } - - if (!temp_b.empty() && temp_b.front() == 'v') { - temp_b.erase(0, 1); - LOG(INFO) << "real version b" << temp_b; - } + if (!temp_b.empty() && temp_b.front() == 'v') { + temp_b.erase(0, 1); + SPDLOG_INFO("real version b: {}", temp_b); + } - // First, split the string. - std::vector<std::string> va, vb; - boost::split(va, temp_a, boost::is_any_of(".")); - boost::split(vb, temp_b, boost::is_any_of(".")); + // First, split the string. + std::vector<std::string> va, vb; + boost::split(va, temp_a, boost::is_any_of(".")); + boost::split(vb, temp_b, boost::is_any_of(".")); - // Compare the numbers step by step, but only as deep as the version - // with the least elements allows. - const int depth = - std::min(static_cast<int>(va.size()), static_cast<int>(vb.size())); - int ia = 0, ib = 0; - for (int i = 0; i < depth; ++i) { - try { - ia = boost::lexical_cast<int>(va[i]); - ib = boost::lexical_cast<int>(vb[i]); - } catch (boost::bad_lexical_cast& ignored) { - break; - } - if (ia != ib) break; + // Compare the numbers step by step, but only as deep as the version + // with the least elements allows. + const int depth = + std::min(static_cast<int>(va.size()), static_cast<int>(vb.size())); + int ia = 0, ib = 0; + for (int i = 0; i < depth; ++i) { + try { + ia = boost::lexical_cast<int>(va[i]); + ib = boost::lexical_cast<int>(vb[i]); + } catch (boost::bad_lexical_cast& ignored) { + break; } + if (ia != ib) break; + } - // Return the required number. - if (ia > ib) - return 1; - else if (ia < ib) - return -1; - else { - // In case of equal versions, assumes that the version - // with the most elements is the highest version. - if (va.size() > vb.size()) - return 1; - else if (va.size() < vb.size()) - return -1; - } + // Return the required number. + if (ia > ib) + return 1; + else if (ia < ib) + return -1; + else { + // In case of equal versions, assumes that the version + // with the most elements is the highest version. + if (va.size() > vb.size()) + return 1; + else if (va.size() < vb.size()) + return -1; + } - // Everything is equal, return 0. - return 0; + // Everything is equal, return 0. + return 0; } bool GpgFrontend::UI::SoftwareVersion::NeedUpgrade() const { diff --git a/src/ui/thread/ListedKeyServerTestTask.cpp b/src/ui/thread/ListedKeyServerTestTask.cpp index 9d4ca74d..71c7c0ba 100644 --- a/src/ui/thread/ListedKeyServerTestTask.cpp +++ b/src/ui/thread/ListedKeyServerTestTask.cpp @@ -44,20 +44,20 @@ void GpgFrontend::UI::ListedKeyServerTestTask::run() { size_t index = 0; for (const auto& url : urls_) { auto key_url = QUrl{url}; - LOG(INFO) << "key server request: " << key_url.host().toStdString(); + SPDLOG_INFO("key server request: {}", key_url.host().toStdString()); auto* network_reply = network_manager_->get(QNetworkRequest{key_url}); auto* timer = new QTimer(this); connect(network_reply, &QNetworkReply::finished, this, [this, index, network_reply]() { - LOG(INFO) << "key server domain reply" - << urls_[index].toStdString(); + SPDLOG_INFO("key server domain reply: {}", + urls_[index].toStdString()); this->slot_process_network_reply(index, network_reply); }); connect(timer, &QTimer::timeout, this, [this, index, network_reply]() { - LOG(INFO) << "timeout for key server" << urls_[index].toStdString(); + SPDLOG_INFO("timeout for key server: {}", urls_[index].toStdString()); if (network_reply->isRunning()) { network_reply->abort(); this->slot_process_network_reply(index, network_reply); diff --git a/src/ui/thread/ProxyConnectionTestThread.cpp b/src/ui/thread/ProxyConnectionTestThread.cpp index 062f4774..068afedf 100644 --- a/src/ui/thread/ProxyConnectionTestThread.cpp +++ b/src/ui/thread/ProxyConnectionTestThread.cpp @@ -31,13 +31,13 @@ void GpgFrontend::UI::ProxyConnectionTestThread::run() { auto proxies_list = QNetworkProxyFactory::systemProxyForQuery(npq); if (proxies_list.isEmpty()) { - LOG(INFO) << "no proxy applied"; + SPDLOG_INFO("no proxy applied"); } else { - LOG(INFO) << "proxies list hostname" - << proxies_list.front().hostName().toStdString(); + SPDLOG_INFO("proxies list hostname: {}", + proxies_list.front().hostName().toStdString()); } - LOG(INFO) << "proxies list size" << proxies_list.size(); + SPDLOG_INFO("proxies list size: {}", proxies_list.size()); auto manager = std::make_unique<QNetworkAccessManager>(nullptr); QNetworkRequest url_request; diff --git a/src/ui/thread/VersionCheckTask.cpp b/src/ui/thread/VersionCheckTask.cpp index 7de3b511..99094891 100644 --- a/src/ui/thread/VersionCheckTask.cpp +++ b/src/ui/thread/VersionCheckTask.cpp @@ -49,7 +49,7 @@ void VersionCheckTask::Run() { try { using namespace nlohmann; - LOG(INFO) << "current version" << current_version_; + SPDLOG_INFO("current version: {}", current_version_); std::string latest_version_url = "https://api.github.com/repos/saturneric/gpgfrontend/releases/latest"; @@ -73,7 +73,7 @@ void VersionCheckTask::slot_parse_latest_version_info() { try { if (latest_reply_ == nullptr || latest_reply_->error() != QNetworkReply::NoError) { - LOG(ERROR) << "latest version request error"; + SPDLOG_ERROR("latest version request error"); version_.latest_version = current_version_; } else { latest_reply_bytes_ = latest_reply_->readAll(); @@ -83,16 +83,16 @@ void VersionCheckTask::slot_parse_latest_version_info() { std::string latest_version = latest_reply_json["tag_name"]; - LOG(INFO) << "latest version from Github" << latest_version; + SPDLOG_INFO("latest version from Github: {}", latest_version); QRegularExpression re(R"(^[vV](\d+\.)?(\d+\.)?(\*|\d+))"); auto version_match = re.match(latest_version.c_str()); if (version_match.hasMatch()) { latest_version = version_match.captured(0).toStdString(); - LOG(INFO) << "latest version matched" << latest_version; + SPDLOG_INFO("latest version matched: {}", latest_version); } else { latest_version = current_version_; - LOG(WARNING) << "latest version unknown"; + SPDLOG_WARN("latest version unknown"); } bool prerelease = latest_reply_json["prerelease"], @@ -106,7 +106,7 @@ void VersionCheckTask::slot_parse_latest_version_info() { version_.release_note = release_note; } } catch (...) { - LOG(INFO) << "error occurred"; + SPDLOG_INFO("error occurred"); version_.load_info_done = false; } @@ -126,7 +126,7 @@ void VersionCheckTask::slot_parse_latest_version_info() { connect(current_reply_, &QNetworkReply::finished, this, &VersionCheckTask::slot_parse_current_version_info); } catch (...) { - LOG(ERROR) << "current version request create error"; + SPDLOG_ERROR("current version request create error"); emit SignalTaskFinished(); } } @@ -135,12 +135,12 @@ void VersionCheckTask::slot_parse_current_version_info() { try { if (current_reply_ == nullptr || current_reply_->error() != QNetworkReply::NoError) { - LOG(ERROR) << "current version request network error"; + SPDLOG_ERROR("current version request network error"); version_.current_version_found = false; } else { version_.current_version_found = true; current_reply_bytes_ = current_reply_->readAll(); - LOG(INFO) << "current version" << current_reply_bytes_.size(); + SPDLOG_INFO("current version: {}", current_reply_bytes_.size()); auto current_reply_json = nlohmann::json::parse(current_reply_bytes_.toStdString()); bool current_prerelease = current_reply_json["prerelease"], @@ -150,11 +150,11 @@ void VersionCheckTask::slot_parse_current_version_info() { version_.load_info_done = true; } } catch (...) { - LOG(INFO) << "error occurred"; + SPDLOG_INFO("error occurred"); version_.load_info_done = false; } - LOG(INFO) << "current version parse done" << version_.current_version_found; + SPDLOG_INFO("current version parse done: {}", version_.current_version_found); if (current_reply_ != nullptr) { current_reply_->deleteLater(); diff --git a/src/ui/widgets/FilePage.cpp b/src/ui/widgets/FilePage.cpp index fe188e93..98b46467 100644 --- a/src/ui/widgets/FilePage.cpp +++ b/src/ui/widgets/FilePage.cpp @@ -108,7 +108,7 @@ void FilePage::slot_file_tree_view_item_clicked(const QModelIndex& index) { #endif m_path_ = selected_path_; - LOG(INFO) << "selected path" << selected_path_.u8string(); + SPDLOG_INFO("selected path: {}", selected_path_.u8string()); selected_path_ = std::filesystem::path(selected_path_); MainWindow::CryptoMenu::OperationType operation_type = @@ -164,10 +164,10 @@ void FilePage::slot_up_level() { std::filesystem::path path_obj(str_path); m_path_ = path_obj; - LOG(INFO) << "get path" << m_path_; + SPDLOG_INFO("get path: {}", m_path_.u8string()); if (m_path_.has_parent_path() && !m_path_.parent_path().empty()) { m_path_ = m_path_.parent_path(); - LOG(INFO) << "parent path" << m_path_; + SPDLOG_INFO("parent path: {}", m_path_.u8string()); ui_->pathEdit->setText(m_path_.u8string().c_str()); this->SlotGoPath(); } @@ -204,7 +204,7 @@ void FilePage::SlotGoPath() { m_path_ = std::filesystem::path(fileInfo.filePath().toStdString()); #endif - LOG(INFO) << "set path" << m_path_.u8string(); + SPDLOG_INFO("set path: {}", m_path_.u8string()); ui_->fileTreeView->setRootIndex(dir_model_->index(fileInfo.filePath())); dir_model_->setRootPath(fileInfo.filePath()); for (int i = 1; i < dir_model_->columnCount(); ++i) { @@ -267,7 +267,7 @@ void FilePage::create_popup_menu() { auto showHiddenAct = new QAction(_("Show Hidden File"), this); showHiddenAct->setCheckable(true); connect(showHiddenAct, &QAction::triggered, this, [&](bool checked) { - LOG(INFO) << "Set Hidden" << checked; + SPDLOG_INFO("set hidden: {}", checked); if (checked) dir_model_->setFilter(dir_model_->filter() | QDir::Hidden); else @@ -279,7 +279,7 @@ void FilePage::create_popup_menu() { auto showSystemAct = new QAction(_("Show System File"), this); showSystemAct->setCheckable(true); connect(showSystemAct, &QAction::triggered, this, [&](bool checked) { - LOG(INFO) << "Set Hidden" << checked; + SPDLOG_INFO("set hidden: {}", checked); if (checked) dir_model_->setFilter(dir_model_->filter() | QDir::System); else @@ -291,7 +291,7 @@ void FilePage::create_popup_menu() { void FilePage::onCustomContextMenu(const QPoint& point) { QModelIndex index = ui_->fileTreeView->indexAt(point); - LOG(INFO) << "right click" << selected_path_.u8string(); + SPDLOG_INFO("right click: {}", selected_path_.u8string()); #ifdef WINDOWS auto index_dir_str = @@ -328,7 +328,7 @@ void FilePage::slot_open_item() { if (info.isDir()) { if (info.isReadable() && info.isExecutable()) { const auto file_path = info.filePath().toUtf8().toStdString(); - LOG(INFO) << "set path" << file_path; + SPDLOG_INFO("set path: {}", file_path); ui_->pathEdit->setText(info.filePath().toUtf8()); SlotGoPath(); } else { @@ -340,7 +340,7 @@ void FilePage::slot_open_item() { // handle normal text or binary file auto main_window = qobject_cast<MainWindow*>(first_parent_); auto qt_open_path = QString::fromStdString(selected_path_.u8string()); - LOG(INFO) << "open item" << qt_open_path.toStdString(); + SPDLOG_INFO("open item: {}", qt_open_path.toStdString()); if (main_window != nullptr) main_window->SlotOpenFile(qt_open_path); } else { QMessageBox::critical(this, _("Error"), @@ -365,12 +365,12 @@ void FilePage::slot_rename_item() { #else new_name_path /= text.toStdString(); #endif - LOG(INFO) << "new name path" << new_name_path; + SPDLOG_INFO("new name path: {}", new_name_path.u8string()); std::filesystem::rename(old_name_path, new_name_path); // refresh this->SlotGoPath(); } catch (...) { - LOG(ERROR) << "rename error" << new_name_path; + SPDLOG_ERROR("rename error: {}", new_name_path.u8string()); QMessageBox::critical(this, _("Error"), _("Unable to rename the file or folder.")); } @@ -387,7 +387,7 @@ void FilePage::slot_delete_item() { if (ret == QMessageBox::Cancel) return; - LOG(INFO) << "Delete Item" << data.toString().toStdString(); + SPDLOG_INFO("delete item: {}", data.toString().toStdString()); if (!dir_model_->remove(index)) { QMessageBox::critical(this, _("Error"), @@ -441,7 +441,7 @@ void FilePage::slot_create_empty_file() { } void FilePage::keyPressEvent(QKeyEvent* event) { - LOG(INFO) << "Key Press" << event->key(); + SPDLOG_INFO("key press: {}", event->key()); if (ui_->pathEdit->hasFocus() && (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)) { SlotGoPath(); diff --git a/src/ui/widgets/InfoBoardWidget.cpp b/src/ui/widgets/InfoBoardWidget.cpp index 74ead2ce..fceefe2a 100644 --- a/src/ui/widgets/InfoBoardWidget.cpp +++ b/src/ui/widgets/InfoBoardWidget.cpp @@ -85,7 +85,6 @@ void InfoBoardWidget::SetInfoBoard(const QString& text, auto info_font_size = general_settings_state.Check("text_editor").Check("font_size", 10); ui_->infoBoard->setFont(QFont("Times", info_font_size)); - } void InfoBoardWidget::SlotRefresh(const QString& text, InfoBoardStatus status) { @@ -114,7 +113,7 @@ void InfoBoardWidget::AssociateTabWidget(QTabWidget* tab) { void InfoBoardWidget::AddOptionalAction(const QString& name, const std::function<void()>& action) { - LOG(INFO) << "add option" << name.toStdString(); + SPDLOG_INFO("add option: {}", name.toStdString()); auto actionButton = new QPushButton(name); auto layout = new QHBoxLayout(); layout->setContentsMargins(5, 0, 5, 0); @@ -144,7 +143,7 @@ void InfoBoardWidget::SlotReset() { */ void InfoBoardWidget::delete_widgets_in_layout(QLayout* layout, int start_index) { - LOG(INFO) << "Called"; + SPDLOG_INFO("called"); QLayoutItem* item; while ((item = layout->layout()->takeAt(start_index)) != nullptr) { @@ -165,7 +164,7 @@ void InfoBoardWidget::slot_copy() { void InfoBoardWidget::slot_save() { auto file_path = QFileDialog::getSaveFileName( this, _("Save Information Board's Content"), {}, tr("Text (*.txt)")); - LOG(INFO) << "file path" << file_path.toStdString(); + SPDLOG_INFO("file path: {{}", file_path.toStdString()); if (file_path.isEmpty()) return; QFile file(file_path); diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index 9150d580..246e3d5a 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -100,7 +100,7 @@ void KeyList::AddListGroupTab( const QString& name, KeyListRow::KeyType selectType, KeyListColumn::InfoType infoType, const std::function<bool(const GpgKey&)>& filter) { - LOG(INFO) << _("Called") << name.toStdString(); + SPDLOG_INFO("called: {}", name.toStdString()); auto key_list = new QTableWidget(this); if (m_key_list_ == nullptr) { @@ -158,7 +158,7 @@ void KeyList::AddListGroupTab( } void KeyList::SlotRefresh() { - LOG(INFO) << _("called") << "address" << this; + SPDLOG_INFO("called address: {}", static_cast<void*>(this)); ui_->refreshKeyListButton->setDisabled(true); ui_->syncButton->setDisabled(true); @@ -317,10 +317,10 @@ void KeyList::dropEvent(QDropEvent* event) { bool confirm_import_keys = true; try { confirm_import_keys = settings.lookup("general.confirm_import_keys"); - LOG(INFO) << "confirm_import_keys" << confirm_import_keys; + SPDLOG_INFO("confirm_import_keys: {}", confirm_import_keys); if (confirm_import_keys) checkBox->setCheckState(Qt::Checked); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("confirm_import_keys"); + SPDLOG_ERROR("setting operation error: confirm_import_keys"); } // Buttons for ok and cancel @@ -358,8 +358,7 @@ void KeyList::dropEvent(QDropEvent* event) { QFile file; file.setFileName(tmp.toLocalFile()); if (!file.open(QIODevice::ReadOnly)) { - LOG(INFO) << _("Couldn't Open File") << ":" - << tmp.toString().toStdString(); + SPDLOG_INFO("couldn't open file: {}", tmp.toString().toStdString()); } QByteArray inBuffer = file.readAll(); this->import_keys(inBuffer); @@ -379,7 +378,7 @@ void KeyList::dragEnterEvent(QDragEnterEvent* event) { * */ [[maybe_unused]] void KeyList::MarkKeys(QStringList* keyIds) { - foreach (QString id, *keyIds) { qDebug() << "marked: " << id; } + foreach (QString id, *keyIds) { spdlog::debug("marked: ", id.toStdString()); } } void KeyList::import_keys(const QByteArray& inBuffer) { @@ -419,7 +418,7 @@ std::string KeyList::GetSelectedKey() { } void KeyList::slot_refresh_ui() { - LOG(INFO) << _("Called") << buffered_keys_list_.get(); + SPDLOG_INFO("called: {}", static_cast<void*>(buffered_keys_list_.get())); if (buffered_keys_list_ != nullptr) { std::lock_guard<std::mutex> guard(buffered_key_list_mutex_); for (auto& key_table : m_key_tables_) { @@ -451,8 +450,8 @@ void KeyList::slot_sync_with_key_server() { CommonUtils::SlotImportKeyFromKeyServer( key_ids, [=](const std::string& key_id, const std::string& status, size_t current_index, size_t all_index) { - LOG(INFO) << _("Called") << key_id << status << current_index - << all_index; + SPDLOG_INFO("called: {} {} {} {}", key_id, status, current_index, + all_index); auto key = GpgKeyGetter::GetInstance().GetKey(key_id); boost::format status_str = boost::format(_("Sync [%1%/%2%] %3% %4%")) % @@ -503,7 +502,7 @@ KeyIdArgsListPtr& KeyTable::GetChecked() { auto& ret = checked_key_ids_; for (int i = 0; i < buffered_keys_.size(); i++) { auto key_id = buffered_keys_[i].GetId(); - LOG(INFO) << "i: " << i << " key_id: " << key_id; + SPDLOG_INFO("i: {} key_id: {}", i, key_id); if (key_list_->item(i, 0)->checkState() == Qt::Checked && std::find(ret->begin(), ret->end(), key_id) == ret->end()) { ret->push_back(key_id); @@ -513,7 +512,7 @@ KeyIdArgsListPtr& KeyTable::GetChecked() { } void KeyTable::SetChecked(KeyIdArgsListPtr key_ids) { - LOG(INFO) << "called"; + SPDLOG_INFO("called"); checked_key_ids_ = std::move(key_ids); } @@ -535,14 +534,14 @@ void KeyTable::Refresh(KeyLinkListPtr m_keys) { int row_count = 0; while (it != keys->end()) { - LOG(INFO) << "filtering key id: " << it->GetId(); + SPDLOG_INFO("filtering key id: {}", it->GetId()); if (filter_ != nullptr) { if (!filter_(*it)) { it = keys->erase(it); continue; } } - LOG(INFO) << "adding key id: " << it->GetId(); + SPDLOG_INFO("adding key id: {}", it->GetId()); if (select_type_ == KeyListRow::ONLY_SECRET_KEY && !it->IsPrivateKey()) { it = keys->erase(it); continue; @@ -625,7 +624,8 @@ void KeyTable::Refresh(KeyLinkListPtr m_keys) { tmp3->setFont(strike); } - LOG(INFO) << "key id: " << it->GetId() << "added into key_list_:" << this; + SPDLOG_INFO("key id: {} added into key_list_: {}", it->GetId(), + static_cast<void*>(this)); // move to buffered keys buffered_keys_.emplace_back(std::move(*it)); diff --git a/src/ui/widgets/PlainTextEditorPage.cpp b/src/ui/widgets/PlainTextEditorPage.cpp index 10e19b8b..fc6a25bf 100644 --- a/src/ui/widgets/PlainTextEditorPage.cpp +++ b/src/ui/widgets/PlainTextEditorPage.cpp @@ -160,7 +160,7 @@ void PlainTextEditorPage::slot_format_gpg_header() { } void PlainTextEditorPage::ReadFile() { - LOG(INFO) << "called"; + SPDLOG_INFO("called"); read_done_ = false; read_bytes_ = 0; @@ -185,7 +185,7 @@ void PlainTextEditorPage::ReadFile() { &FileReadTask::SignalFileBytesReadNext, Qt::QueuedConnection); connect(read_task, &FileReadTask::SignalTaskFinished, this, - []() { LOG(INFO) << "read thread closed"; }); + []() { SPDLOG_INFO("read thread closed"); }); connect(this, &PlainTextEditorPage::close, read_task, &FileReadTask::SignalTaskFinished); connect(read_task, &FileReadTask::SignalFileBytesReadEnd, this, [=]() { @@ -212,7 +212,7 @@ std::string binary_to_string(const std::string &source) { void PlainTextEditorPage::slot_insert_text(QByteArray bytes_data) { std::string data = bytes_data.toStdString(); - LOG(INFO) << "data size" << data.size(); + SPDLOG_INFO("data size: {}", data.size()); read_bytes_ += data.size(); // If binary format is detected, the entire file is converted to binary // format for display. @@ -260,7 +260,7 @@ void PlainTextEditorPage::slot_insert_text(QByteArray bytes_data) { this->ui_->characterLabel->setText(str.str().c_str()); } QTimer::singleShot(25, this, &PlainTextEditorPage::SignalUIBytesDisplayed); - LOG(INFO) << "end"; + SPDLOG_INFO("end"); } void PlainTextEditorPage::detect_encoding(const std::string &data) { diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp index 713dbb80..c4754b3b 100644 --- a/src/ui/widgets/TextEdit.cpp +++ b/src/ui/widgets/TextEdit.cpp @@ -81,7 +81,7 @@ void TextEdit::SlotNewFileTab() const { void TextEdit::SlotOpenFile(QString& path) { QFile file(path); - LOG(INFO) << "path" << path.toStdString(); + SPDLOG_INFO("path: {}", path.toStdString()); auto result = file.open(QIODevice::ReadOnly | QIODevice::Text); if (result) { auto* page = new PlainTextEditorPage(path); @@ -516,7 +516,7 @@ QHash<int, QString> TextEdit::UnsavedDocuments() const { if (ep != nullptr && ep->ReadDone() && ep->GetTextPage()->document()->isModified()) { QString doc_name = tab_widget_->tabText(i); - LOG(INFO) << "unsaved" << doc_name.toStdString(); + SPDLOG_INFO("unsaved: {}", doc_name.toStdString()); // remove * before name of modified doc doc_name.remove(0, 2); |