diff options
author | saturneric <[email protected]> | 2024-07-30 18:42:12 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-07-30 18:42:12 +0000 |
commit | dbb4a21931cd10a3caed3c446af0fe06de9873b1 (patch) | |
tree | b3eb2e6fc3e67ea274472dfacfa3451848b43c80 /src/core | |
parent | fix: solve known issues on build (diff) | |
download | GpgFrontend-dbb4a21931cd10a3caed3c446af0fe06de9873b1.tar.gz GpgFrontend-dbb4a21931cd10a3caed3c446af0fe06de9873b1.zip |
feat: simplify logging
Diffstat (limited to 'src/core')
31 files changed, 338 insertions, 337 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 921e8944..81c3f08f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -48,7 +48,7 @@ set(_export_file "${CMAKE_CURRENT_SOURCE_DIR}/GpgFrontendCoreExport.h") generate_export_header(gpgfrontend_core EXPORT_FILE_NAME "${_export_file}") # compile definitions -target_compile_definitions(gpgfrontend_core PUBLIC GF_CORE) +target_compile_definitions(gpgfrontend_core PRIVATE GF_CORE_PRIVATE) # mimalloc (except apple macos) if(NOT APPLE) diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index 3e03536a..d0f24824 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -177,7 +177,7 @@ auto InitGpgME(const QString& gpgconf_path, const QString& gnupg_path) -> bool { // conditional check: only support gpg 2.1.x now if (!(GFCompareSoftwareVersion(gnupg_version, "2.1.0") >= 0 && find_gpgconf && find_openpgp && find_cms)) { - qCWarning(core, "gpgme env check failed, abort"); + FLOG_W("gpgme env check failed, abort"); return false; } @@ -238,8 +238,8 @@ auto DetectGpgConfPath() -> QString { #endif if (!VerifyGpgconfPath(QFileInfo(gnupg_install_fs_path))) { - qCWarning(core) << "core loaded custom gpgconf path is illegal: " - << gnupg_install_fs_path; + LOG_W() << "core loaded custom gpgconf path is illegal: " + << gnupg_install_fs_path; gnupg_install_fs_path = ""; } } @@ -279,8 +279,8 @@ void InitGpgFrontendCore(CoreInitArgs args) { auto gpgconf_install_fs_path = DetectGpgConfPath(); auto gnupg_install_fs_path = DetectGnuPGPath(gpgconf_install_fs_path); - qCInfo(core) << "detected gpgconf path: " << gpgconf_install_fs_path; - qCInfo(core) << "detected gnupg path: " << gnupg_install_fs_path; + LOG_I() << "detected gpgconf path: " << gpgconf_install_fs_path; + LOG_I() << "detected gnupg path: " << gnupg_install_fs_path; // initialize library gpgme if (!InitGpgME(gpgconf_install_fs_path, gnupg_install_fs_path)) { @@ -329,8 +329,8 @@ void InitGpgFrontendCore(CoreInitArgs args) { key_database_fs_path = QFileInfo(custom_gnupg_install_path).absoluteFilePath(); } else { - qCWarning(core) << "custom gpg key database path is not suitable: " - << key_database_fs_path; + LOG_W() << "custom gpg key database path is not suitable: " + << key_database_fs_path; } } else { @@ -369,7 +369,7 @@ void InitGpgFrontendCore(CoreInitArgs args) { // exit if failed if (!ctx.Good()) { - qCWarning(core, "default gnupg context init error, abort"); + FLOG_W("default gnupg context init error, abort"); CoreSignalStation::GetInstance()->SignalBadGnupgEnv( QCoreApplication::tr("GpgME Context initiation failed")); return -1; diff --git a/src/core/GpgFrontendCore.h b/src/core/GpgFrontendCore.h index fbbab22e..1d5ae29f 100644 --- a/src/core/GpgFrontendCore.h +++ b/src/core/GpgFrontendCore.h @@ -28,13 +28,28 @@ #pragma once -// Qt +// project base header +#include "GpgFrontend.h" + +// qt #include <QtCore> -// declare area of core -#ifdef GF_CORE +// private declare area of core +#ifdef GF_CORE_PRIVATE // declare logging category Q_DECLARE_LOGGING_CATEGORY(core) +#define LOG_D() qCDebug(core) +#define LOG_I() qCInfo(core) +#define LOG_W() qCWarning(core) +#define LOG_E() qCCritical(core) +#define LOG_F() qCFatal(core) + +#define FLOG_D(...) qCDebug(core, __VA_ARGS__) +#define FLOG_I(...) qCInfo(core, __VA_ARGS__) +#define FLOG_W(...) qCWarning(core, __VA_ARGS__) +#define FLOG_E(...) qCCritical(core, __VA_ARGS__) +#define FLOG_F(...) qCFatal(core, __VA_ARGS__) + #endif
\ No newline at end of file diff --git a/src/core/function/ArchiveFileOperator.cpp b/src/core/function/ArchiveFileOperator.cpp index 2fc801ab..71c36d46 100644 --- a/src/core/function/ArchiveFileOperator.cpp +++ b/src/core/function/ArchiveFileOperator.cpp @@ -46,14 +46,14 @@ auto CopyData(struct archive *ar, struct archive *aw) -> int { r = archive_read_data_block(ar, &buff, &size, &offset); if (r == ARCHIVE_EOF) return (ARCHIVE_OK); if (r != ARCHIVE_OK) { - qCWarning(core) << "archive_read_data_block() failed: " - << archive_error_string(ar); + LOG_W() << "archive_read_data_block() failed: " + << archive_error_string(ar); return (r); } r = archive_write_data_block(aw, buff, size, offset); if (r != ARCHIVE_OK) { - qCWarning(core) << "archive_write_data_block() failed: " - << archive_error_string(aw); + LOG_W() << "archive_write_data_block() failed: " + << archive_error_string(aw); return (r); } } @@ -113,8 +113,8 @@ void ArchiveFileOperator::NewArchive2DataExchanger( #endif if (r != ARCHIVE_OK) { - qCWarning(core, "archive_read_disk_open() failed: %s, abort...", - archive_error_string(disk)); + FLOG_W("archive_read_disk_open() failed: %s, abort...", + archive_error_string(disk)); archive_read_free(disk); archive_write_free(archive); return -1; @@ -227,8 +227,8 @@ void ArchiveFileOperator::ExtractArchiveFromDataExchanger( nullptr); if (r != ARCHIVE_OK) { - qCWarning(core, "archive_read_open(), ret: %d, reason: %s", r, - archive_error_string(archive)); + FLOG_W("archive_read_open(), ret: %d, reason: %s", r, + archive_error_string(archive)); return r; } @@ -245,8 +245,8 @@ void ArchiveFileOperator::ExtractArchiveFromDataExchanger( r = archive_read_next_header(archive, &entry); if (r == ARCHIVE_EOF) break; if (r != ARCHIVE_OK) { - qCWarning(core, "archive_read_next_header(), ret: %d, reason: %s", - r, archive_error_string(archive)); + FLOG_W("archive_read_next_header(), ret: %d, reason: %s", r, + archive_error_string(archive)); break; } @@ -264,8 +264,8 @@ void ArchiveFileOperator::ExtractArchiveFromDataExchanger( r = archive_write_header(ext, entry); if (r != ARCHIVE_OK) { - qCWarning(core, "archive_write_header(), ret: %d, reason: %s", r, - archive_error_string(archive)); + FLOG_W("archive_write_header(), ret: %d, reason: %s", r, + archive_error_string(archive)); } else { r = CopyData(archive, ext); } @@ -273,13 +273,13 @@ void ArchiveFileOperator::ExtractArchiveFromDataExchanger( r = archive_read_free(archive); if (r != ARCHIVE_OK) { - qCWarning(core, "archive_read_free(), ret: %d, reason: %s", r, - archive_error_string(archive)); + FLOG_W("archive_read_free(), ret: %d, reason: %s", r, + archive_error_string(archive)); } r = archive_write_free(ext); if (r != ARCHIVE_OK) { - qCWarning(core, "archive_read_free(), ret: %d, reason: %s", r, - archive_error_string(archive)); + FLOG_W("archive_read_free(), ret: %d, reason: %s", r, + archive_error_string(archive)); } return 0; @@ -299,8 +299,8 @@ void ArchiveFileOperator::ListArchive(const QString &archive_path) { 10240); // Note 1 if (r != ARCHIVE_OK) return; while (archive_read_next_header(a, &entry) == ARCHIVE_OK) { - qCDebug(core, core, "File: %s", archive_entry_pathname(entry)); - qCDebug(core, core, "File Path: %s", archive_entry_pathname(entry)); + FLOG_D("File: %s", archive_entry_pathname(entry)); + FLOG_D("File Path: %s", archive_entry_pathname(entry)); archive_read_data_skip(a); // Note 2 } r = archive_read_free(a); // Note 3 diff --git a/src/core/function/CacheManager.cpp b/src/core/function/CacheManager.cpp index bbb52cc7..05138025 100644 --- a/src/core/function/CacheManager.cpp +++ b/src/core/function/CacheManager.cpp @@ -164,7 +164,7 @@ class CacheManager::Impl : public QObject { * */ void slot_flush_cache_storage() { - qCDebug(core, "write cache to file system..."); + FLOG_D("write cache to file system..."); for (const auto& cache : durable_cache_storage_.mirror()) { auto key = get_data_object_key(cache.first); @@ -215,7 +215,7 @@ class CacheManager::Impl : public QObject { * */ void load_all_cache_storage() { - qCDebug(core, "start to load all cache from file system"); + FLOG_D("start to load all cache from file system"); auto stored_data = GpgFrontend::DataObjectOperator::GetInstance().GetDataObject(drk_key_); diff --git a/src/core/function/DataObjectOperator.cpp b/src/core/function/DataObjectOperator.cpp index 634228c9..b762b1c8 100644 --- a/src/core/function/DataObjectOperator.cpp +++ b/src/core/function/DataObjectOperator.cpp @@ -49,8 +49,7 @@ DataObjectOperator::DataObjectOperator(int channel) QByteArray key; if (!ReadFile(app_secure_key_path_, key)) { - qCWarning(core) << "failed to read app secure key file: " - << app_secure_key_path_; + LOG_W() << "failed to read app secure key file: " << app_secure_key_path_; // unsafe mode key = {}; } @@ -91,7 +90,7 @@ auto DataObjectOperator::SaveDataObj(const QString& key, } if (!WriteFile(target_obj_path, encoded_data)) { - qCWarning(core) << "failed to write data object to disk: " << key; + LOG_W() << "failed to write data object to disk: " << key; } return key.isEmpty() ? hash_obj_key : QString(); } @@ -105,13 +104,13 @@ auto DataObjectOperator::GetDataObject(const QString& key) const auto obj_path = app_data_objs_path_ + "/" + hash_obj_key; if (!QFileInfo(obj_path).exists()) { - qCWarning(core) << "data object not found from disk, key: " << key; + LOG_W() << "data object not found from disk, key: " << key; return {}; } QByteArray encoded_data; if (!ReadFile(obj_path, encoded_data)) { - qCWarning(core) << "failed to read data object from disk, key: " << key; + LOG_W() << "failed to read data object from disk, key: " << key; return {}; } @@ -123,8 +122,7 @@ auto DataObjectOperator::GetDataObject(const QString& key) return QJsonDocument::fromJson(decoded_data); } catch (...) { - qCWarning(core) << "failed to get data object:" << key - << " caught exception."; + LOG_W() << "failed to get data object:" << key << " caught exception."; return {}; } } diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp index 68fc79d7..42aced01 100644 --- a/src/core/function/GlobalSettingStation.cpp +++ b/src/core/function/GlobalSettingStation.cpp @@ -40,8 +40,8 @@ class GlobalSettingStation::Impl { * */ explicit Impl() noexcept { - qCInfo(core) << "app path: " << GetAppDir(); - qCInfo(core) << "app working path: " << working_path_; + LOG_I() << "app path: " << GetAppDir(); + LOG_I() << "app working path: " << working_path_; auto portable_file_path = working_path_ + "/PORTABLE.txt"; if (QFileInfo(portable_file_path).exists()) { @@ -54,11 +54,11 @@ class GlobalSettingStation::Impl { portable_mode_ = true; } - qCInfo(core) << "app data path: " << app_data_path_; - qCInfo(core) << "app log path: " << app_log_path_; + LOG_I() << "app data path: " << app_data_path_; + LOG_I() << "app log path: " << app_log_path_; #if defined(_WIN32) || defined(WIN32) - qCInfo(core) << "app config path: " << app_config_path_; + LOG_I() << "app config path: " << app_config_path_; if (!QDir(app_config_path_).exists()) QDir(app_config_path_).mkpath("."); #endif diff --git a/src/core/function/KeyPackageOperator.cpp b/src/core/function/KeyPackageOperator.cpp index ccba642c..c5c573ce 100644 --- a/src/core/function/KeyPackageOperator.cpp +++ b/src/core/function/KeyPackageOperator.cpp @@ -45,7 +45,7 @@ namespace GpgFrontend { auto KeyPackageOperator::GeneratePassphrase(const QString& phrase_path, QString& phrase) -> bool { phrase = PassphraseGenerator::GetInstance().Generate(256); - qCDebug(core, "generated passphrase: %lld bytes", phrase.size()); + FLOG_D("generated passphrase: %lld bytes", phrase.size()); return WriteFile(phrase_path, phrase.toUtf8()); } @@ -57,8 +57,8 @@ void KeyPackageOperator::GenerateKeyPackage(const QString& key_package_path, GpgKeyImportExporter::GetInstance().ExportAllKeys( keys, secret, true, [=](GpgError err, const DataObjectPtr& data_obj) { if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { - qCWarning(core) << "export keys error, reason: " - << DescribeGpgErrCode(err).second; + LOG_W() << "export keys error, reason: " + << DescribeGpgErrCode(err).second; cb(-1, data_obj); return; } @@ -93,14 +93,14 @@ void KeyPackageOperator::ImportKeyPackage(const QString& key_package_path, ReadFile(key_package_path, encrypted_data); if (encrypted_data.isEmpty()) { - qCWarning(core) << "failed to read key package: " << key_package_path; + LOG_W() << "failed to read key package: " << key_package_path; return -1; }; QByteArray passphrase; ReadFile(phrase_path, passphrase); if (passphrase.size() != 256) { - qCWarning(core) << "passphrase size mismatch: " << phrase_path; + LOG_W() << "passphrase size mismatch: " << phrase_path; return -1; } diff --git a/src/core/function/basic/SingletonStorage.cpp b/src/core/function/basic/SingletonStorage.cpp index 4883c3a1..edc52b4a 100644 --- a/src/core/function/basic/SingletonStorage.cpp +++ b/src/core/function/basic/SingletonStorage.cpp @@ -53,7 +53,7 @@ class SingletonStorage::Impl { std::shared_lock<std::shared_mutex> lock(instances_mutex_); ins_it = instances_map_.find(channel); if (ins_it == instances_map_.end()) { - qCDebug(core, "cannot find channel object, channel: %d", channel); + FLOG_D("cannot find channel object, channel: %d", channel); return nullptr; } return ins_it->second.get(); @@ -71,14 +71,14 @@ class SingletonStorage::Impl { auto SetObjectInChannel(int channel, ChannelObjectPtr p_obj) -> GpgFrontend::ChannelObject* { - qCDebug(core, "set channel object, type: %s in channel: %d, address: %p", - typeid(p_obj.get()).name(), channel, - static_cast<void*>(p_obj.get())); + FLOG_D("set channel object, type: %s in channel: %d, address: %p", + typeid(p_obj.get()).name(), channel, + static_cast<void*>(p_obj.get())); assert(p_obj != nullptr); if (p_obj == nullptr) { - qCWarning(core, "cannot set a nullptr as a channel object of channel: %d", - channel); + FLOG_W("cannot set a nullptr as a channel object of channel: %d", + channel); return nullptr; } @@ -94,8 +94,8 @@ class SingletonStorage::Impl { instances_map_[channel] = std::move(p_obj); } - qCDebug(core, "set channel: %d success, current channel object address: %p", - channel, static_cast<void*>(raw_obj)); + FLOG_D("set channel: %d success, current channel object address: %p", + channel, static_cast<void*>(raw_obj)); return raw_obj; } diff --git a/src/core/function/gpg/GpgAdvancedOperator.cpp b/src/core/function/gpg/GpgAdvancedOperator.cpp index 3d5a7b59..20d9aa4b 100644 --- a/src/core/function/gpg/GpgAdvancedOperator.cpp +++ b/src/core/function/gpg/GpgAdvancedOperator.cpp @@ -41,7 +41,7 @@ void GpgFrontend::GpgAdvancedOperator::ClearGpgPasswordCache( "core", "gpgme.ctx.gpgconf_path", QString{}); if (gpgconf_path.isEmpty()) { - qCWarning(core, "cannot get valid gpgconf path from rt, abort."); + FLOG_W("cannot get valid gpgconf path from rt, abort."); cb(-1, TransferParams()); return; } @@ -60,7 +60,7 @@ void GpgFrontend::GpgAdvancedOperator::ReloadGpgComponents( "core", "gpgme.ctx.gpgconf_path", QString{}); if (gpgconf_path.isEmpty()) { - qCWarning(core, "cannot get valid gpgconf path from rt, abort."); + FLOG_W("cannot get valid gpgconf path from rt, abort."); cb(-1, TransferParams()); return; } @@ -68,7 +68,7 @@ void GpgFrontend::GpgAdvancedOperator::ReloadGpgComponents( GpgFrontend::GpgCommandExecutor::ExecuteSync( {gpgconf_path, QStringList{"--reload"}, [=](int exit_code, const QString &, const QString &) { - qCDebug(core, "gpgconf reload exit code: %d", exit_code); + FLOG_D("gpgconf reload exit code: %d", exit_code); cb(exit_code == 0 ? 0 : -1, TransferParams()); }}); } @@ -78,7 +78,7 @@ void GpgFrontend::GpgAdvancedOperator::KillAllGpgComponents() { "core", "gpgme.ctx.gpgconf_path", QString{}); if (gpgconf_path.isEmpty()) { - qCWarning(core, "cannot get valid gpgconf path from rt, abort."); + FLOG_W("cannot get valid gpgconf path from rt, abort."); return; } @@ -88,12 +88,12 @@ void GpgFrontend::GpgAdvancedOperator::KillAllGpgComponents() { bool success = true; if (exit_code != 0) { success = false; - qCWarning(core) << "gpgconf execute error, process stderr: " << p_err - << ", process stdout: " << p_out; + LOG_W() << "gpgconf execute error, process stderr: " << p_err + << ", process stdout: " << p_out; return; } - qCDebug(core, "gpgconf --kill --all execute result: %d", success); + FLOG_D("gpgconf --kill --all execute result: %d", success); }}); } @@ -102,24 +102,23 @@ void GpgFrontend::GpgAdvancedOperator::RestartGpgComponents() { "core", "gpgme.ctx.gpgconf_path", QString{}); if (gpgconf_path.isEmpty()) { - qCWarning(core, "cannot get valid gpgconf path from rt, abort."); + FLOG_W("cannot get valid gpgconf path from rt, abort."); return; } GpgFrontend::GpgCommandExecutor::ExecuteSync( {gpgconf_path, QStringList{"--verbose", "--kill", "all"}, [=](int exit_code, const QString &p_out, const QString &p_err) { - qCDebug(core, "gpgconf --kill all command got exit code: %d", - exit_code); + FLOG_D("gpgconf --kill all command got exit code: %d", exit_code); bool success = true; if (exit_code != 0) { success = false; - qCWarning(core) << "gpgconf execute error, process stderr: " << p_err - << ", process stdout: " << p_out; + LOG_W() << "gpgconf execute error, process stderr: " << p_err + << ", process stdout: " << p_out; return; } - qCDebug(core, "gpgconf --kill --all execute result: %d", success); + FLOG_D("gpgconf --kill --all execute result: %d", success); if (!success) { qCWarning(core, "restart all component after core initilized failed"); @@ -143,7 +142,7 @@ void GpgFrontend::GpgAdvancedOperator::ResetConfigures(OperationCallback cb) { "core", "gpgme.ctx.gpgconf_path", QString{}); if (gpgconf_path.isEmpty()) { - qCWarning(core, "cannot get valid gpgconf path from rt, abort."); + FLOG_W("cannot get valid gpgconf path from rt, abort."); cb(-1, TransferParams()); return; } @@ -151,7 +150,7 @@ void GpgFrontend::GpgAdvancedOperator::ResetConfigures(OperationCallback cb) { GpgFrontend::GpgCommandExecutor::ExecuteSync( {gpgconf_path, QStringList{"--apply-defaults"}, [=](int exit_code, const QString &, const QString &) { - qCDebug(core, "gpgconf apply-defaults exit code: %d", exit_code); + FLOG_D("gpgconf apply-defaults exit code: %d", exit_code); cb(exit_code == 0 ? 0 : -1, TransferParams()); }}); } @@ -169,7 +168,7 @@ void GpgFrontend::GpgAdvancedOperator::StartGpgAgent(OperationCallback cb) { kGnuPGInfoGatheringModuleID, "gnupg.home_path", QString{}); if (gpg_agent_path.isEmpty()) { - qCWarning(core, "cannot get valid gpg agent path from rt, abort."); + FLOG_W("cannot get valid gpg agent path from rt, abort."); cb(-1, TransferParams()); return; } @@ -177,7 +176,7 @@ void GpgFrontend::GpgAdvancedOperator::StartGpgAgent(OperationCallback cb) { GpgFrontend::GpgCommandExecutor::ExecuteSync( {gpg_agent_path, QStringList{"--homedir", home_path, "--daemon"}, [=](int exit_code, const QString &, const QString &) { - qCDebug(core, "gpgconf daemon exit code: %d", exit_code); + FLOG_D("gpgconf daemon exit code: %d", exit_code); cb(exit_code >= 0 ? 0 : -1, TransferParams()); }}); } @@ -195,7 +194,7 @@ void GpgFrontend::GpgAdvancedOperator::StartDirmngr(OperationCallback cb) { kGnuPGInfoGatheringModuleID, "gnupg.home_path", QString{}); if (dirmngr_path.isEmpty()) { - qCWarning(core, "cannot get valid dirmngr path from rt, abort."); + FLOG_W("cannot get valid dirmngr path from rt, abort."); cb(-1, TransferParams()); return; } @@ -203,7 +202,7 @@ void GpgFrontend::GpgAdvancedOperator::StartDirmngr(OperationCallback cb) { GpgFrontend::GpgCommandExecutor::ExecuteSync( {dirmngr_path, QStringList{"--homedir", home_path, "--daemon"}, [=](int exit_code, const QString &, const QString &) { - qCDebug(core, "gpgconf daemon exit code: %d", exit_code); + FLOG_D("gpgconf daemon exit code: %d", exit_code); cb(exit_code >= 0 ? 0 : -1, TransferParams()); }}); } @@ -221,7 +220,7 @@ void GpgFrontend::GpgAdvancedOperator::StartKeyBoxd(OperationCallback cb) { kGnuPGInfoGatheringModuleID, "gnupg.home_path", QString{}); if (keyboxd_path.isEmpty()) { - qCWarning(core, "cannot get valid keyboxd path from rt, abort."); + FLOG_W("cannot get valid keyboxd path from rt, abort."); cb(-1, TransferParams()); return; } @@ -229,7 +228,7 @@ void GpgFrontend::GpgAdvancedOperator::StartKeyBoxd(OperationCallback cb) { GpgFrontend::GpgCommandExecutor::ExecuteSync( {keyboxd_path, QStringList{"--homedir", home_path, "--daemon"}, [=](int exit_code, const QString &, const QString &) { - qCDebug(core, "gpgconf daemon exit code: %d", exit_code); + FLOG_D("gpgconf daemon exit code: %d", exit_code); cb(exit_code >= 0 ? 0 : -1, TransferParams()); }}); } diff --git a/src/core/function/gpg/GpgBasicOperator.cpp b/src/core/function/gpg/GpgBasicOperator.cpp index eb4ac337..6443f242 100644 --- a/src/core/function/gpg/GpgBasicOperator.cpp +++ b/src/core/function/gpg/GpgBasicOperator.cpp @@ -390,14 +390,15 @@ void GpgBasicOperator::SetSigners(const KeyArgsList& signers, bool ascii) { gpgme_signers_clear(ctx); for (const GpgKey& key : signers) { - qCDebug(core) << "signer's key fpr: " << key.GetFingerprint(); + LOG_D() << "signer's key fpr: " << key.GetFingerprint(); if (key.IsHasActualSigningCapability()) { auto error = gpgme_signers_add(ctx, gpgme_key_t(key)); CheckGpgError(error); } } - if (signers.size() != gpgme_signers_count(ctx_.DefaultContext())) - qCDebug(core, "not all signers added"); + if (signers.size() != gpgme_signers_count(ctx_.DefaultContext())) { + FLOG_D("not all signers added"); + } } auto GpgBasicOperator::GetSigners(bool ascii) -> std::unique_ptr<KeyArgsList> { diff --git a/src/core/function/gpg/GpgCommandExecutor.cpp b/src/core/function/gpg/GpgCommandExecutor.cpp index 6b65afc5..374d59d8 100644 --- a/src/core/function/gpg/GpgCommandExecutor.cpp +++ b/src/core/function/gpg/GpgCommandExecutor.cpp @@ -50,7 +50,7 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context) data_object->GetObjectSize()); if (!data_object->Check<int, QString, GpgCommandExecutorCallback>()) { - qCWarning(core, "data object checking failed"); + FLOG_W("data object checking failed"); return; } @@ -64,12 +64,12 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context) Thread::Task::TaskRunnable runner = [](const DataObjectPtr &data_object) -> int { - qCDebug(core, "process runner called, data object size: %lu", - data_object->GetObjectSize()); + FLOG_D("process runner called, data object size: %lu", + data_object->GetObjectSize()); if (!data_object->Check<QString, QStringList, GpgCommandExecutorInteractor, GpgCommandExecutorCallback>()) { - qCWarning(core, "data object checking failed"); + FLOG_W("data object checking failed"); return -1; } @@ -100,23 +100,23 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context) QObject::connect( cmd_process, &QProcess::started, [cmd, joined_argument]() -> void { - qCDebug(core) << "\n== Process Execute Started ==\nCommand: " << cmd - << "\nArguments: " << joined_argument - << " \n========================"; + LOG_D() << "\n== Process Execute Started ==\nCommand: " << cmd + << "\nArguments: " << joined_argument + << " \n========================"; }); QObject::connect( cmd_process, &QProcess::readyReadStandardOutput, [interact_func, cmd_process]() { interact_func(cmd_process); }); QObject::connect(cmd_process, &QProcess::errorOccurred, [=](QProcess::ProcessError error) { - qCWarning(core) + LOG_W() << "caught error while executing command: " << cmd << joined_argument << ", error:" << error; }); - qCDebug(core) << "\n== Process Execute Ready ==\nCommand: " << cmd - << "\nArguments: " << joined_argument - << "\n========================"; + LOG_D() << "\n== Process Execute Ready ==\nCommand: " << cmd + << "\nArguments: " << joined_argument + << "\n========================"; cmd_process->start(); cmd_process->waitForFinished(); @@ -124,13 +124,13 @@ auto BuildTaskFromExecCtx(const GpgCommandExecutor::ExecuteContext &context) QString process_stdout = cmd_process->readAllStandardOutput(); int exit_code = cmd_process->exitCode(); - qCDebug(core) << "\n==== Process Execution Summary ====\n" - << "Command: " << cmd << "\n" - << "Arguments: " << joined_argument << "\n" - << "Exit Code: " << exit_code << "\n" - << "---- Standard Output ----\n" - << process_stdout << "\n" - << "==============================="; + LOG_D() << "\n==== Process Execution Summary ====\n" + << "Command: " << cmd << "\n" + << "Arguments: " << joined_argument << "\n" + << "Exit Code: " << exit_code << "\n" + << "---- Standard Output ----\n" + << process_stdout << "\n" + << "==============================="; cmd_process->close(); cmd_process->deleteLater(); @@ -166,7 +166,7 @@ void GpgCommandExecutor::ExecuteSync(ExecuteContext context) { // to arvoid dead lock issue we need to check if current thread is the same as // target thread. if it is, we can't call exec() because it will block the // current thread. - qCDebug(core, "blocking until gpg command finish..."); + FLOG_D("blocking until gpg command finish..."); // block until task finished // this is to keep reference vaild until task finished looper.exec(); @@ -194,15 +194,15 @@ void GpgCommandExecutor::ExecuteConcurrentlySync(ExecuteContexts contexts) { for (auto &context : contexts) { const auto &cmd = context.cmd; - qCDebug(core) << "gpg concurrently called cmd: " << cmd; + LOG_D() << "gpg concurrently called cmd: " << cmd; Thread::Task *task = BuildTaskFromExecCtx(context); QObject::connect(task, &Thread::Task::SignalTaskEnd, [&]() { --remaining_tasks; - qCDebug(core, "remaining tasks: %lld", remaining_tasks); + FLOG_D("remaining tasks: %lld", remaining_tasks); if (remaining_tasks <= 0) { - qCDebug(core, "no remaining task, quit"); + FLOG_D("no remaining task, quit"); looper.quit(); } }); @@ -218,7 +218,7 @@ void GpgCommandExecutor::ExecuteConcurrentlySync(ExecuteContexts contexts) { target_task_runner->PostTask(task); } - qCDebug(core, "blocking until concurrent gpg commands finish..."); + FLOG_D("blocking until concurrent gpg commands finish..."); // block until task finished // this is to keep reference vaild until task finished looper.exec(); diff --git a/src/core/function/gpg/GpgContext.cpp b/src/core/function/gpg/GpgContext.cpp index 3058e33f..94a4f522 100644 --- a/src/core/function/gpg/GpgContext.cpp +++ b/src/core/function/gpg/GpgContext.cpp @@ -124,12 +124,12 @@ class GpgContext::Impl { passphrase_info != nullptr ? passphrase_info : "", prev_was_bad != 0, ask_for_new)); - qCDebug(core) << "custom passphrase cb called, uid: " - << (uid_hint == nullptr ? "<empty>" : QString{uid_hint}) - << ", info: " - << (passphrase_info == nullptr ? "<empty>" - : QString{passphrase_info}) - << ", last_was_bad: " << prev_was_bad; + LOG_D() << "custom passphrase cb called, uid: " + << (uid_hint == nullptr ? "<empty>" : QString{uid_hint}) + << ", info: " + << (passphrase_info == nullptr ? "<empty>" + : QString{passphrase_info}) + << ", last_was_bad: " << prev_was_bad; QEventLoop looper; QString passphrase = ""; @@ -171,7 +171,7 @@ class GpgContext::Impl { static auto TestStatusCb(void *hook, const char *keyword, const char *args) -> gpgme_error_t { - qCDebug(core, "keyword %s", keyword); + FLOG_D("keyword %s", keyword); return GPG_ERR_NO_ERROR; } @@ -189,7 +189,7 @@ class GpgContext::Impl { const auto gpgme_version = Module::RetrieveRTValueTypedOrDefault<>( "core", "gpgme.version", QString{"0.0.0"}); - qCDebug(core) << "got gpgme version version from rt: " << gpgme_version; + LOG_D() << "got gpgme version version from rt: " << gpgme_version; if (gpgme_get_keylist_mode(ctx) == 0) { qCWarning( @@ -212,8 +212,8 @@ class GpgContext::Impl { const auto database_path = Module::RetrieveRTValueTypedOrDefault<>( "core", "gpgme.ctx.database_path", QString{}); - qCDebug(core) << "ctx set engine info, db path: " << database_path - << ", app path: " << app_path; + LOG_D() << "ctx set engine info, db path: " << database_path + << ", app path: " << app_path; auto app_path_buffer = app_path.toUtf8(); auto database_path_buffer = database_path.toUtf8(); @@ -234,22 +234,22 @@ class GpgContext::Impl { assert(ctx != nullptr); if (args.custom_gpgconf && !args.custom_gpgconf_path.isEmpty()) { - qCDebug(core) << "set custom gpgconf path: " << args.custom_gpgconf_path; + LOG_D() << "set custom gpgconf path: " << args.custom_gpgconf_path; auto err = gpgme_ctx_set_engine_info(ctx, GPGME_PROTOCOL_GPGCONF, args.custom_gpgconf_path.toUtf8(), nullptr); if (CheckGpgError(err) != GPG_ERR_NO_ERROR) { - qCWarning(core) << "set gpg context engine info error: " - << DescribeGpgErrCode(err).second; + LOG_W() << "set gpg context engine info error: " + << DescribeGpgErrCode(err).second; return false; } } // set context offline mode - qCDebug(core, "gpg context: offline mode: %d", args_.offline_mode); - qCDebug(core, "gpg context: auto import missing key: %d", - args_.auto_import_missing_key); + FLOG_D("gpg context: offline mode: %d", args_.offline_mode); + FLOG_D("gpg context: auto import missing key: %d", + args_.auto_import_missing_key); gpgme_set_offline(ctx, args_.offline_mode ? 1 : 0); // set option auto import missing key @@ -261,20 +261,20 @@ class GpgContext::Impl { } if (!set_ctx_key_list_mode(ctx)) { - qCDebug(core, "set ctx key list mode failed"); + FLOG_D("set ctx key list mode failed"); return false; } // for unit test if (args_.test_mode) { if (!SetPassphraseCb(ctx, TestPassphraseCb)) { - qCWarning(core, "set passphrase cb failed, test"); + FLOG_W("set passphrase cb failed, test"); return false; }; } else if (!args_.use_pinentry && Module::IsModuleActivate(kPinentryModuleID)) { if (!SetPassphraseCb(ctx, CustomPassphraseCb)) { - qCDebug(core, "set passphrase cb failed, custom"); + FLOG_D("set passphrase cb failed, custom"); return false; } } @@ -285,7 +285,7 @@ class GpgContext::Impl { } if (!set_ctx_openpgp_engine_info(ctx)) { - qCWarning(core, "set gpgme context openpgp engine info failed"); + FLOG_W("set gpgme context openpgp engine info failed"); return false; } @@ -295,15 +295,15 @@ class GpgContext::Impl { auto binary_ctx_initialize(const GpgContextInitArgs &args) -> bool { gpgme_ctx_t p_ctx; if (auto err = CheckGpgError(gpgme_new(&p_ctx)); err != GPG_ERR_NO_ERROR) { - qCWarning(core) << "get new gpg context error: " - << DescribeGpgErrCode(err).second; + LOG_W() << "get new gpg context error: " + << DescribeGpgErrCode(err).second; return false; } assert(p_ctx != nullptr); binary_ctx_ref_ = p_ctx; if (!common_ctx_initialize(binary_ctx_ref_, args)) { - qCWarning(core, "get new ctx failed, binary"); + FLOG_W("get new ctx failed, binary"); return false; } @@ -314,7 +314,7 @@ class GpgContext::Impl { auto default_ctx_initialize(const GpgContextInitArgs &args) -> bool { gpgme_ctx_t p_ctx; if (CheckGpgError(gpgme_new(&p_ctx)) != GPG_ERR_NO_ERROR) { - qCWarning(core, "get new ctx failed, default"); + FLOG_W("get new ctx failed, default"); return false; } assert(p_ctx != nullptr); diff --git a/src/core/function/gpg/GpgFileOpera.cpp b/src/core/function/gpg/GpgFileOpera.cpp index ae9dce82..d2cdff9b 100644 --- a/src/core/function/gpg/GpgFileOpera.cpp +++ b/src/core/function/gpg/GpgFileOpera.cpp @@ -110,7 +110,7 @@ void GpgFileOpera::EncryptDirectory(const KeyArgsList& keys, GpgData data_in(ex); GpgData data_out(out_path, false); - qCDebug(core, "encrypt directory start"); + FLOG_D("encrypt directory start"); auto* ctx = ascii ? ctx_.DefaultContext() : ctx_.BinaryContext(); auto err = CheckGpgError(gpgme_op_encrypt(ctx, recipients.data(), @@ -118,14 +118,14 @@ void GpgFileOpera::EncryptDirectory(const KeyArgsList& keys, data_in, data_out)); data_object->Swap({GpgEncryptResult(gpgme_op_encrypt_result(ctx))}); - qCDebug(core, "encrypt directory finished, err: %d", err); + FLOG_D("encrypt directory finished, err: %d", err); return err; }, cb, "gpgme_op_encrypt", "2.1.0"); ArchiveFileOperator::NewArchive2DataExchanger( in_path, ex, [=](GFError err, const DataObjectPtr&) { - qCDebug(core, "new archive 2 data exchanger operation, err: %d", err); + FLOG_D("new archive 2 data exchanger operation, err: %d", err); if (decltype(ex) p_ex = w_ex.lock(); err < 0 && p_ex != nullptr) { ex->CloseWrite(); } @@ -174,7 +174,7 @@ void GpgFileOpera::DecryptArchive(const QString& in_path, ArchiveFileOperator::ExtractArchiveFromDataExchanger( ex, out_path, [](GFError err, const DataObjectPtr&) { - qCDebug(core, "extract archive from data exchanger operation, err: %d", + FLOG_D("extract archive from data exchanger operation, err: %d", err); }); @@ -396,7 +396,7 @@ void GpgFileOpera::EncryptSignDirectory(const KeyArgsList& keys, ArchiveFileOperator::NewArchive2DataExchanger( in_path, ex, [=](GFError err, const DataObjectPtr&) { - qCDebug(core, "new archive 2 fd operation, err: %d", err); + FLOG_D("new archive 2 fd operation, err: %d", err); if (decltype(ex) p_ex = w_ex.lock(); err < 0 && p_ex != nullptr) { ex->CloseWrite(); } @@ -456,7 +456,7 @@ void GpgFileOpera::DecryptVerifyArchive(const QString& in_path, ArchiveFileOperator::ExtractArchiveFromDataExchanger( ex, out_path, [](GFError err, const DataObjectPtr&) { - qCDebug(core, "extract archive from ex operation, err: %d", err); + FLOG_D("extract archive from ex operation, err: %d", err); }); RunGpgOperaAsync( @@ -542,7 +542,7 @@ void GpgFileOpera::EncryptDerectorySymmetric(const QString& in_path, bool ascii, ArchiveFileOperator::NewArchive2DataExchanger( in_path, ex, [=](GFError err, const DataObjectPtr&) { - qCDebug(core, "new archive 2 fd operation, err: %d", err); + FLOG_D("new archive 2 fd operation, err: %d", err); }); } @@ -553,7 +553,7 @@ auto GpgFileOpera::EncryptDerectorySymmetricSync( ArchiveFileOperator::NewArchive2DataExchanger( in_path, ex, [=](GFError err, const DataObjectPtr&) { - qCDebug(core, "new archive 2 fd operation, err: %d", err); + FLOG_D("new archive 2 fd operation, err: %d", err); }); return RunGpgOperaSync( diff --git a/src/core/function/gpg/GpgKeyGetter.cpp b/src/core/function/gpg/GpgKeyGetter.cpp index 60d3c418..af77b067 100644 --- a/src/core/function/gpg/GpgKeyGetter.cpp +++ b/src/core/function/gpg/GpgKeyGetter.cpp @@ -54,8 +54,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { gpgme_key_t p_key = nullptr; gpgme_get_key(ctx_.DefaultContext(), fpr.toUtf8(), &p_key, 1); if (p_key == nullptr) { - qCWarning(core) << "GpgKeyGetter GetKey Private _p_key Null, fpr: " - << fpr; + LOG_W() << "GpgKeyGetter GetKey Private _p_key Null, fpr: " << fpr; return GetPubkey(fpr, true); } return GpgKey(std::move(p_key)); @@ -71,7 +70,7 @@ class GpgKeyGetter::Impl : public SingletonFunctionObject<GpgKeyGetter::Impl> { gpgme_key_t p_key = nullptr; gpgme_get_key(ctx_.DefaultContext(), fpr.toUtf8(), &p_key, 0); if (p_key == nullptr) - qCWarning(core) << "GpgKeyGetter GetKey _p_key Null, fpr: " << fpr; + LOG_W() << "GpgKeyGetter GetKey _p_key Null, fpr: " << fpr; return GpgKey(std::move(p_key)); } diff --git a/src/core/function/gpg/GpgKeyManager.cpp b/src/core/function/gpg/GpgKeyManager.cpp index 66e28c4e..fda3173a 100644 --- a/src/core/function/gpg/GpgKeyManager.cpp +++ b/src/core/function/gpg/GpgKeyManager.cpp @@ -94,83 +94,82 @@ auto GpgFrontend::GpgKeyManager::SetExpire( auto GpgFrontend::GpgKeyManager::SetOwnerTrustLevel(const GpgKey& key, int trust_level) -> bool { if (trust_level < 0 || trust_level > 5) { - qCWarning(core, "illegal owner trust level: %d", trust_level); + FLOG_W("illegal owner trust level: %d", trust_level); } - AutomatonNextStateHandler next_state_handler = - [](AutomatonState state, QString status, QString args) { - qCDebug(core) << "next_state_handler state: " - << static_cast<unsigned int>(state) - << ", gpg_status: " << status << ", args: " << args; + AutomatonNextStateHandler next_state_handler = [](AutomatonState state, + QString status, + QString args) { + LOG_D() << "next_state_handler state: " << static_cast<unsigned int>(state) + << ", gpg_status: " << status << ", args: " << args; - auto tokens = args.split(' '); + auto tokens = args.split(' '); - switch (state) { - case AS_START: - if (status == "GET_LINE" && args == "keyedit.prompt") { - return AS_COMMAND; - } - return AS_ERROR; - case AS_COMMAND: - if (status == "GET_LINE" && args == "edit_ownertrust.value") { - return AS_VALUE; - } - return AS_ERROR; - case AS_VALUE: - if (status == "GET_LINE" && args == "keyedit.prompt") { - return AS_QUIT; - } else if (status == "GET_BOOL" && - args == "edit_ownertrust.set_ultimate.okay") { - return AS_REALLY_ULTIMATE; - } - return AS_ERROR; - case AS_REALLY_ULTIMATE: - if (status == "GET_LINE" && args == "keyedit.prompt") { - return AS_QUIT; - } - return AS_ERROR; - case AS_QUIT: - if (status == "GET_LINE" && args == "keyedit.save.okay") { - return AS_SAVE; - } - return AS_ERROR; - case AS_ERROR: - if (status == "GET_LINE" && args == "keyedit.prompt") { - return AS_QUIT; - } - return AS_ERROR; - default: - return AS_ERROR; - }; - }; - - AutomatonActionHandler action_handler = [trust_level]( - AutomatonHandelStruct& handler, - AutomatonState state) { - qCDebug(core, "action_handler state: %d", static_cast<unsigned int>(state)); switch (state) { + case AS_START: + if (status == "GET_LINE" && args == "keyedit.prompt") { + return AS_COMMAND; + } + return AS_ERROR; case AS_COMMAND: - return QString("trust"); + if (status == "GET_LINE" && args == "edit_ownertrust.value") { + return AS_VALUE; + } + return AS_ERROR; case AS_VALUE: - handler.SetSuccess(true); - return QString::number(trust_level); + if (status == "GET_LINE" && args == "keyedit.prompt") { + return AS_QUIT; + } else if (status == "GET_BOOL" && + args == "edit_ownertrust.set_ultimate.okay") { + return AS_REALLY_ULTIMATE; + } + return AS_ERROR; case AS_REALLY_ULTIMATE: - handler.SetSuccess(true); - return QString("Y"); + if (status == "GET_LINE" && args == "keyedit.prompt") { + return AS_QUIT; + } + return AS_ERROR; case AS_QUIT: - return QString("quit"); - case AS_SAVE: - handler.SetSuccess(true); - return QString("Y"); - case AS_START: + if (status == "GET_LINE" && args == "keyedit.save.okay") { + return AS_SAVE; + } + return AS_ERROR; case AS_ERROR: - return QString(""); + if (status == "GET_LINE" && args == "keyedit.prompt") { + return AS_QUIT; + } + return AS_ERROR; default: - return QString(""); - } - return QString(""); + return AS_ERROR; + }; }; + AutomatonActionHandler action_handler = + [trust_level](AutomatonHandelStruct& handler, AutomatonState state) { + FLOG_D("action_handler state: %d", static_cast<unsigned int>(state)); + switch (state) { + case AS_COMMAND: + return QString("trust"); + case AS_VALUE: + handler.SetSuccess(true); + return QString::number(trust_level); + case AS_REALLY_ULTIMATE: + handler.SetSuccess(true); + return QString("Y"); + case AS_QUIT: + return QString("quit"); + case AS_SAVE: + handler.SetSuccess(true); + return QString("Y"); + case AS_START: + case AS_ERROR: + return QString(""); + default: + return QString(""); + } + return QString(""); + }; + auto key_fpr = key.GetFingerprint(); AutomatonHandelStruct handel_struct(key_fpr); handel_struct.SetHandler(next_state_handler, action_handler); @@ -196,8 +195,8 @@ auto GpgFrontend::GpgKeyManager::interactor_cb_fnc(void* handle, auto tokens = QString(args).split(' '); if (tokens.empty() || tokens[0] != handle_struct->KeyFpr()) { - qCWarning(core) << "handle struct key fpr " << handle_struct->KeyFpr() - << "mismatch token: " << tokens[0] << ", exit..."; + LOG_W() << "handle struct key fpr " << handle_struct->KeyFpr() + << "mismatch token: " << tokens[0] << ", exit..."; return -1; } @@ -206,13 +205,13 @@ auto GpgFrontend::GpgKeyManager::interactor_cb_fnc(void* handle, } if (status_s == "GOT_IT" || status_s.isEmpty()) { - qCDebug(core, "status GOT_IT, continue..."); + FLOG_D("status GOT_IT, continue..."); return 0; } AutomatonState next_state = handle_struct->NextState(status_s, args_s); if (next_state == AS_ERROR) { - qCDebug(core, "handle struct next state caught error, skipping..."); + FLOG_D("handle struct next state caught error, skipping..."); return GPG_ERR_FALSE; } diff --git a/src/core/function/gpg/GpgKeyOpera.cpp b/src/core/function/gpg/GpgKeyOpera.cpp index aa9bafaf..54c90182 100644 --- a/src/core/function/gpg/GpgKeyOpera.cpp +++ b/src/core/function/gpg/GpgKeyOpera.cpp @@ -61,7 +61,7 @@ void GpgKeyOpera::DeleteKeys(KeyIdArgsListPtr key_ids) { GPGME_DELETE_ALLOW_SECRET | GPGME_DELETE_FORCE)); assert(gpg_err_code(err) == GPG_ERR_NO_ERROR); } else { - qCWarning(core) << "GpgKeyOpera DeleteKeys get key failed: " << tmp; + LOG_W() << "GpgKeyOpera DeleteKeys get key failed: " << tmp; } } } @@ -113,8 +113,8 @@ void GpgKeyOpera::GenerateRevokeCert(const GpgKey& key, output_path, "--gen-revoke", key.GetFingerprint()}, [=](int exit_code, const QString& p_out, const QString& p_err) { if (exit_code != 0) { - qCWarning(core) << "gnupg gen revoke execute error, process stderr: " - << p_err << ", process stdout: " << p_out; + LOG_W() << "gnupg gen revoke execute error, process stderr: " + << p_err << ", process stdout: " << p_out; } else { qCDebug(core, "gnupg gen revoke exit_code: %d, process stdout size: %lld", @@ -159,8 +159,7 @@ void GpgKeyOpera::GenerateKey(const std::shared_ptr<GenKeyInfo>& params, auto userid = params->GetUserid(); auto algo = params->GetAlgo() + params->GetKeySizeStr(); - qCDebug(core) << "params: " << params->GetAlgo() - << params->GetKeySizeStr(); + LOG_D() << "params: " << params->GetAlgo() << params->GetKeySizeStr(); unsigned long expires = QDateTime::currentDateTime().secsTo(params->GetExpireTime()); @@ -175,8 +174,8 @@ void GpgKeyOpera::GenerateKey(const std::shared_ptr<GenKeyInfo>& params, if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - qCDebug(core) << "key generation args: " << userid << algo << expires - << flags; + LOG_D() << "key generation args: " << userid << algo << expires + << flags; err = gpgme_op_createkey(ctx.DefaultContext(), userid.toUtf8(), algo.toUtf8(), 0, expires, nullptr, flags); @@ -200,8 +199,7 @@ auto GpgKeyOpera::GenerateKeySync(const std::shared_ptr<GenKeyInfo>& params) auto userid = params->GetUserid(); auto algo = params->GetAlgo() + params->GetKeySizeStr(); - qCDebug(core) << "params: " << params->GetAlgo() - << params->GetKeySizeStr(); + LOG_D() << "params: " << params->GetAlgo() << params->GetKeySizeStr(); unsigned long expires = QDateTime::currentDateTime().secsTo(params->GetExpireTime()); @@ -216,8 +214,8 @@ auto GpgKeyOpera::GenerateKeySync(const std::shared_ptr<GenKeyInfo>& params) if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - qCDebug(core) << "key generation args: " << userid << algo << expires - << flags; + LOG_D() << "key generation args: " << userid << algo << expires + << flags; err = gpgme_op_createkey(ctx.DefaultContext(), userid.toUtf8(), algo.toUtf8(), 0, expires, nullptr, flags); @@ -241,8 +239,8 @@ void GpgKeyOpera::GenerateSubkey(const GpgKey& key, [key, &ctx = ctx_, params](const DataObjectPtr& data_object) -> GpgError { if (!params->IsSubKey()) return GPG_ERR_CANCELED; - qCDebug(core) << "generate subkey algo: " << params->GetAlgo() - << "key size: " << params->GetKeySizeStr(); + LOG_D() << "generate subkey algo: " << params->GetAlgo() + << "key size: " << params->GetKeySizeStr(); auto algo = params->GetAlgo() + params->GetKeySizeStr(); unsigned long expires = @@ -256,8 +254,8 @@ void GpgKeyOpera::GenerateSubkey(const GpgKey& key, if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - qCDebug(core) << "subkey generation args: " << key.GetId() << algo - << expires << flags; + LOG_D() << "subkey generation args: " << key.GetId() << algo << expires + << flags; auto err = gpgme_op_createsubkey(ctx.DefaultContext(), static_cast<gpgme_key_t>(key), @@ -281,8 +279,8 @@ auto GpgKeyOpera::GenerateSubkeySync(const GpgKey& key, [key, &ctx = ctx_, params](const DataObjectPtr& data_object) -> GpgError { if (!params->IsSubKey()) return GPG_ERR_CANCELED; - qCDebug(core) << "generate subkey algo: " << params->GetAlgo() - << " key size: " << params->GetKeySizeStr(); + LOG_D() << "generate subkey algo: " << params->GetAlgo() + << " key size: " << params->GetKeySizeStr(); auto algo = params->GetAlgo() + params->GetKeySizeStr(); unsigned long expires = @@ -296,7 +294,7 @@ auto GpgKeyOpera::GenerateSubkeySync(const GpgKey& key, if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - qCDebug(core) << " args: " << key.GetId() << algo << expires << flags; + LOG_D() << " args: " << key.GetId() << algo << expires << flags; auto err = gpgme_op_createsubkey(ctx.DefaultContext(), static_cast<gpgme_key_t>(key), @@ -336,8 +334,8 @@ void GpgKeyOpera::GenerateKeyWithSubkey( if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - qCDebug(core) << "key generation args: " << userid << algo << expires - << flags; + LOG_D() << "key generation args: " << userid << algo << expires + << flags; err = gpgme_op_createkey(ctx.DefaultContext(), userid, algo, 0, expires, nullptr, flags); @@ -358,8 +356,8 @@ void GpgKeyOpera::GenerateKeyWithSubkey( auto key = GpgKeyGetter::GetInstance().GetKey(genkey_result.GetFingerprint()); if (!key.IsGood()) { - qCWarning(core) << "cannot get key which has been generate, fpr: " - << genkey_result.GetFingerprint(); + LOG_W() << "cannot get key which has been generate, fpr: " + << genkey_result.GetFingerprint(); return err; } @@ -375,8 +373,8 @@ void GpgKeyOpera::GenerateKeyWithSubkey( if (subkey_params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; if (subkey_params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - qCDebug(core) << "subkey generation args: " << key.GetId() << algo - << expires << flags; + LOG_D() << "subkey generation args: " << key.GetId() << algo << expires + << flags; err = gpgme_op_createsubkey(ctx.DefaultContext(), static_cast<gpgme_key_t>(key), algo, 0, @@ -417,8 +415,8 @@ auto GpgKeyOpera::GenerateKeyWithSubkeySync( if (params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; if (params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - qCDebug(core) << "key generation args: " << userid << algo << expires - << flags; + LOG_D() << "key generation args: " << userid << algo << expires + << flags; err = gpgme_op_createkey(ctx.DefaultContext(), userid, algo, 0, expires, nullptr, flags); @@ -439,14 +437,14 @@ auto GpgKeyOpera::GenerateKeyWithSubkeySync( auto key = GpgKeyGetter::GetInstance().GetKey(genkey_result.GetFingerprint()); if (!key.IsGood()) { - qCWarning(core) << "cannot get key which has been generate, fpr: " - << genkey_result.GetFingerprint(); + LOG_W() << "cannot get key which has been generate, fpr: " + << genkey_result.GetFingerprint(); return err; } - qCDebug(core) << "try to generate subkey of key: " << key.GetId() - << ", algo :" << subkey_params->GetAlgo() - << ", key size: " << subkey_params->GetKeySizeStr(); + LOG_D() << "try to generate subkey of key: " << key.GetId() + << ", algo :" << subkey_params->GetAlgo() + << ", key size: " << subkey_params->GetKeySizeStr(); algo = (subkey_params->GetAlgo() + subkey_params->GetKeySizeStr()) .toUtf8(); @@ -460,8 +458,8 @@ auto GpgKeyOpera::GenerateKeyWithSubkeySync( if (subkey_params->IsNonExpired()) flags |= GPGME_CREATE_NOEXPIRE; if (subkey_params->IsNoPassPhrase()) flags |= GPGME_CREATE_NOPASSWD; - qCDebug(core) << "subkey generation args: " << key.GetId() << algo - << expires << flags; + LOG_D() << "subkey generation args: " << key.GetId() << algo << expires + << flags; err = gpgme_op_createsubkey(ctx.DefaultContext(), static_cast<gpgme_key_t>(key), algo, 0, @@ -494,10 +492,10 @@ auto GpgKeyOpera::ModifyTOFUPolicy( const GpgKey& key, gpgme_tofu_policy_t tofu_policy) -> GpgError { const auto gnupg_version = Module::RetrieveRTValueTypedOrDefault<>( "core", "gpgme.ctx.gnupg_version", QString{"2.0.0"}); - qCDebug(core) << "got gnupg version from rt: " << gnupg_version; + LOG_D() << "got gnupg version from rt: " << gnupg_version; if (GFCompareSoftwareVersion(gnupg_version, "2.1.10") < 0) { - qCWarning(core, "operator not support"); + FLOG_W("operator not support"); return GPG_ERR_NOT_SUPPORTED; } diff --git a/src/core/function/gpg/GpgUIDOperator.cpp b/src/core/function/gpg/GpgUIDOperator.cpp index cb9594f0..90034413 100644 --- a/src/core/function/gpg/GpgUIDOperator.cpp +++ b/src/core/function/gpg/GpgUIDOperator.cpp @@ -58,7 +58,7 @@ auto GpgUIDOperator::SetPrimaryUID(const GpgKey& key, auto GpgUIDOperator::AddUID(const GpgKey& key, const QString& name, const QString& comment, const QString& email) -> bool { - qCDebug(core) << "new uuid:" << name << comment << email; + LOG_D() << "new uuid:" << name << comment << email; return AddUID(key, QString("%1(%2)<%3>").arg(name).arg(comment).arg(email)); } diff --git a/src/core/model/GpgGenKeyInfo.cpp b/src/core/model/GpgGenKeyInfo.cpp index 0553846f..0d0ab239 100644 --- a/src/core/model/GpgGenKeyInfo.cpp +++ b/src/core/model/GpgGenKeyInfo.cpp @@ -124,7 +124,7 @@ void GenKeyInfo::SetAlgo(const QString &t_algo_args) { suggest_size_addition_step_ = -1; SetKeyLength(-1); } else { - qCWarning(core) << "unsupported genkey algo arguments: " << algo_args; + LOG_W() << "unsupported genkey algo arguments: " << algo_args; return; } diff --git a/src/core/model/SettingsObject.cpp b/src/core/model/SettingsObject.cpp index 349c74c3..8e935e08 100644 --- a/src/core/model/SettingsObject.cpp +++ b/src/core/model/SettingsObject.cpp @@ -45,7 +45,7 @@ SettingsObject::SettingsObject(QString settings_name) } } catch (std::exception& e) { - qCWarning(core) << "load setting object error: {}" << e.what(); + LOG_W() << "load setting object error: {}" << e.what(); } } diff --git a/src/core/module/Event.cpp b/src/core/module/Event.cpp index b6d31369..873e728d 100644 --- a/src/core/module/Event.cpp +++ b/src/core/module/Event.cpp @@ -86,9 +86,8 @@ class Event::Impl { listener_id, data_object]() { callback(event_identifier, listener_id, data_object); })) { - qCWarning(core) << "failed to invoke callback for event: " - << event_identifier_ - << " with listener:" << listener_id; + LOG_W() << "failed to invoke callback for event: " << event_identifier_ + << " with listener:" << listener_id; } } } diff --git a/src/core/module/GlobalModuleContext.cpp b/src/core/module/GlobalModuleContext.cpp index 94165f88..08090d33 100644 --- a/src/core/module/GlobalModuleContext.cpp +++ b/src/core/module/GlobalModuleContext.cpp @@ -54,8 +54,7 @@ class GlobalModuleContext::Impl { // Search for the module in the register table. auto module_info_opt = search_module_register_table(module_id); if (!module_info_opt.has_value()) { - qCWarning(core) << "cannot find module id " << module_id - << " at register table"; + LOG_W() << "cannot find module id " << module_id << " at register table"; return nullptr; } @@ -67,10 +66,9 @@ class GlobalModuleContext::Impl { auto module_info_opt = search_module_register_table(module->GetModuleIdentifier()); if (!module_info_opt.has_value()) { - qCWarning(core) << "cannot find module id " - << module->GetModuleIdentifier() - << " at register table, fallback to " - "default channel"; + LOG_W() << "cannot find module id " << module->GetModuleIdentifier() + << " at register table, fallback to " + "default channel"; return GetDefaultChannel(module); } @@ -103,13 +101,13 @@ class GlobalModuleContext::Impl { if (module == nullptr || module_register_table_.find(module->GetModuleIdentifier()) != module_register_table_.end()) { - qCWarning(core, "module is null or have already registered this module"); + FLOG_W("module is null or have already registered this module"); return false; } if (module->Register() != 0) { - qCWarning(core) << "register module " << module->GetModuleIdentifier() - << " failed"; + LOG_W() << "register module " << module->GetModuleIdentifier() + << " failed"; return false; } @@ -136,8 +134,7 @@ class GlobalModuleContext::Impl { // Search for the module in the register table. auto module_info_opt = search_module_register_table(module_id); if (!module_info_opt.has_value()) { - qCWarning(core) << "cannot find module id " << module_id - << " at register table"; + LOG_W() << "cannot find module id " << module_id << " at register table"; return false; } @@ -146,8 +143,8 @@ class GlobalModuleContext::Impl { // try to get module from module info auto module = module_info->module; if (module == nullptr) { - qCWarning(core) << "module id:" << module_id - << " at register table is related to a null module"; + LOG_W() << "module id:" << module_id + << " at register table is related to a null module"; return false; } @@ -164,8 +161,7 @@ class GlobalModuleContext::Impl { // module -> event auto module_info_opt = search_module_register_table(module_id); if (!module_info_opt.has_value()) { - qCWarning(core) << "cannot find module id" << module_id - << "at register table"; + LOG_W() << "cannot find module id" << module_id << "at register table"; return false; } @@ -191,8 +187,7 @@ class GlobalModuleContext::Impl { // search for the module in the register table. auto module_info_opt = search_module_register_table(module_id); if (!module_info_opt.has_value()) { - qCWarning(core) << "cannot find module id " << module_id - << " at register table"; + LOG_W() << "cannot find module id " << module_id << " at register table"; return false; } @@ -220,8 +215,8 @@ class GlobalModuleContext::Impl { auto met_it = module_events_table_.find(event_id); if (met_it == module_events_table_.end()) { // Log a warning if the event is not registered and nobody is listening - qCInfo(core) << "event: " << event_id - << " is not listening by anyone and not registered as well."; + LOG_I() << "event: " << event_id + << " is not listening by anyone and not registered as well."; return false; } @@ -231,7 +226,7 @@ class GlobalModuleContext::Impl { // Check if the set of listeners is empty if (listeners_set.empty()) { // Log a warning if nobody is listening to this event - qCInfo(core) << "event: " << event_id << " is not listening by anyone"; + LOG_I() << "event: " << event_id << " is not listening by anyone"; return false; } @@ -245,8 +240,8 @@ class GlobalModuleContext::Impl { // Log an error if the module is not found in the registration table if (!module_info_opt.has_value()) { - qCWarning(core) << "cannot find module id: " << listener_module_id - << " at register table"; + LOG_W() << "cannot find module id: " << listener_module_id + << " at register table"; continue; } @@ -264,9 +259,9 @@ class GlobalModuleContext::Impl { [listener_module_id, event_id](int code, DataObjectPtr) { if (code < 0) { // Log an error if the module execution fails - qCWarning(core) << "module " << listener_module_id - << "execution failed of event " << event_id - << ": exec return code: " << code; + LOG_W() << "module " << listener_module_id + << "execution failed of event " << event_id + << ": exec return code: " << code; } }; diff --git a/src/core/module/Module.cpp b/src/core/module/Module.cpp index 2358d108..becda4b6 100644 --- a/src/core/module/Module.cpp +++ b/src/core/module/Module.cpp @@ -59,9 +59,9 @@ class Module::Impl { *required_symbol.pointer = reinterpret_cast<void*>(module_library.resolve(required_symbol.name)); if (*required_symbol.pointer == nullptr) { - qCWarning(core) << "illegal module: " << module_library.fileName() - << ", reason cannot load symbol: " - << required_symbol.name << ", abort..."; + LOG_W() << "illegal module: " << module_library.fileName() + << ", reason cannot load symbol: " << required_symbol.name + << ", abort..."; return; } } @@ -72,38 +72,36 @@ class Module::Impl { qt_env_ver_ = GFUnStrDup(get_qt_ver_api_()); if (!module_identifier_regex_exp_.match(identifier_).hasMatch()) { - qCWarning(core) << "illegal module: " << identifier_ - << ", reason invalid module id, abort..."; + LOG_W() << "illegal module: " << identifier_ + << ", reason invalid module id, abort..."; return; } if (!module_version_regex_exp_.match(version_).hasMatch()) { - qCWarning(core) << "illegal module: " << identifier_ - << ", reason invalid version: " << version_ - << ", abort..."; + LOG_W() << "illegal module: " << identifier_ + << ", reason invalid version: " << version_ << ", abort..."; return; } if (!module_version_regex_exp_.match(gf_sdk_ver_).hasMatch()) { - qCWarning(core) << "illegal module: " << identifier_ - << ", reason invalid sdk version: " << gf_sdk_ver_ - << ", abort..."; + LOG_W() << "illegal module: " << identifier_ + << ", reason invalid sdk version: " << gf_sdk_ver_ + << ", abort..."; return; } if (GFCompareSoftwareVersion(gf_sdk_ver_, GetProjectVersion()) > 0) { - qCWarning(core) << "uncompatible module: " << identifier_ - << ", reason sdk version: " << gf_sdk_ver_ - << "current sdk version: " << GetProjectVersion() - << ", abort..."; + LOG_W() << "uncompatible module: " << identifier_ + << ", reason sdk version: " << gf_sdk_ver_ + << "current sdk version: " << GetProjectVersion() << ", abort..."; return; } auto qt_env_ver_regex_match = module_version_regex_exp_.match(qt_env_ver_); if (!qt_env_ver_regex_match.hasMatch()) { - qCWarning(core) << "illegal module: " << identifier_ - << ", reason invalid qt env version: " << qt_env_ver_ - << ", abort..."; + LOG_W() << "illegal module: " << identifier_ + << ", reason invalid qt env version: " << qt_env_ver_ + << ", abort..."; return; } @@ -112,10 +110,10 @@ class Module::Impl { if (qt_env_ver_major != QString::number(QT_VERSION_MAJOR) + "." || qt_env_ver_minor != QString::number(QT_VERSION_MINOR) + ".") { - qCWarning(core) << "uncompatible module: " << identifier_ - << ", reason sdk version: " << qt_env_ver_ - << "current sdk version: " - << QString::fromUtf8(QT_VERSION_STR) << ", abort..."; + LOG_W() << "uncompatible module: " << identifier_ + << ", reason sdk version: " << qt_env_ver_ + << "current sdk version: " << QString::fromUtf8(QT_VERSION_STR) + << ", abort..."; return; } diff --git a/src/core/module/ModuleInit.cpp b/src/core/module/ModuleInit.cpp index 4fedc6c7..3c71a45b 100644 --- a/src/core/module/ModuleInit.cpp +++ b/src/core/module/ModuleInit.cpp @@ -69,8 +69,8 @@ auto LoadIntegratedMods() -> bool { #endif if (!QDir(mods_path).exists()) { - qCWarning(core) << "integrated module directory at path: " << mods_path - << " not found, abort..."; + LOG_W() << "integrated module directory at path: " << mods_path + << " not found, abort..."; return false; } @@ -84,8 +84,8 @@ auto LoadExternalMods() -> bool { GpgFrontend::GlobalSettingStation::GetInstance().GetModulesDir(); if (!QDir(mods_path).exists()) { - qCWarning(core) << "external module directory at path " << mods_path - << " not found, abort..."; + LOG_W() << "external module directory at path " << mods_path + << " not found, abort..."; return false; } diff --git a/src/core/module/ModuleManager.cpp b/src/core/module/ModuleManager.cpp index f2318543..5f8895be 100644 --- a/src/core/module/ModuleManager.cpp +++ b/src/core/module/ModuleManager.cpp @@ -69,17 +69,17 @@ class ModuleManager::Impl { [=](GpgFrontend::DataObjectPtr) -> int { QLibrary module_library(module_library_path); if (!module_library.load()) { - qCWarning(core) << "module manager failed to load module: " - << module_library.fileName() - << ", reason: " << module_library.errorString(); + LOG_W() << "module manager failed to load module: " + << module_library.fileName() + << ", reason: " << module_library.errorString(); return -1; } auto module = SecureCreateSharedObject<Module>(module_library); if (!module->IsGood()) { - qCWarning(core) << "module manager failed to load module, " - "reason: illegal module: " - << module_library.fileName(); + LOG_W() << "module manager failed to load module, " + "reason: illegal module: " + << module_library.fileName(); return -1; } diff --git a/src/core/thread/FileReadTask.cpp b/src/core/thread/FileReadTask.cpp index b4c6874f..d74f5a68 100644 --- a/src/core/thread/FileReadTask.cpp +++ b/src/core/thread/FileReadTask.cpp @@ -45,7 +45,7 @@ auto FileReadTask::Run() -> int { target_file_.open(QIODevice::ReadOnly); if (!(target_file_.isOpen() && target_file_.isReadable())) { - qCWarning(core, "file not open or not readable"); + FLOG_W("file not open or not readable"); if (target_file_.isOpen()) target_file_.close(); return -1; } diff --git a/src/core/thread/Task.cpp b/src/core/thread/Task.cpp index f5c34dbd..7a0e76e8 100644 --- a/src/core/thread/Task.cpp +++ b/src/core/thread/Task.cpp @@ -144,8 +144,8 @@ class Task::Impl { callback_(rtn_, data_object_); } } catch (...) { - qCWarning(core) << "task: {}, " << GetFullID() - << "callback caught exception, rtn: " << rtn; + LOG_W() << "task: {}, " << GetFullID() + << "callback caught exception, rtn: " << rtn; } emit parent_->SignalTaskEnd(); }); @@ -217,7 +217,7 @@ void Task::slot_exception_safe_run() noexcept { rtn = this->Run(); } catch (...) { - qCWarning(core) << "exception was caught at task: {}" << GetFullID(); + LOG_W() << "exception was caught at task: {}" << GetFullID(); } // raise signal to anounce after runnable returned diff --git a/src/core/thread/TaskRunner.cpp b/src/core/thread/TaskRunner.cpp index abf7b8dc..c7d92382 100644 --- a/src/core/thread/TaskRunner.cpp +++ b/src/core/thread/TaskRunner.cpp @@ -38,7 +38,7 @@ class TaskRunner::Impl : public QThread { void PostTask(Task* task) { if (task == nullptr) { - qCWarning(core, "task posted is null"); + FLOG_W("task posted is null"); return; } @@ -73,7 +73,7 @@ class TaskRunner::Impl : public QThread { void PostConcurrentTask(Task* task) { if (task == nullptr) { - qCWarning(core, "task posted is null"); + FLOG_W("task posted is null"); return; } diff --git a/src/core/utils/AsyncUtils.cpp b/src/core/utils/AsyncUtils.cpp index a6fca88f..a4bc66fa 100644 --- a/src/core/utils/AsyncUtils.cpp +++ b/src/core/utils/AsyncUtils.cpp @@ -44,8 +44,8 @@ auto RunGpgOperaAsync(const GpgOperaRunnable& runnable, "core", "gpgme.ctx.gnupg_version", minial_version); if (GFCompareSoftwareVersion(gnupg_version, minial_version) < 0) { - qCWarning(core) << "operation" << operation - << " not support for gnupg version: " << gnupg_version; + LOG_W() << "operation" << operation + << " not support for gnupg version: " << gnupg_version; callback(GPG_ERR_NOT_SUPPORTED, TransferParams()); return Thread::Task::TaskHandler(nullptr); } @@ -82,8 +82,8 @@ auto RunGpgOperaSync(const GpgOperaRunnable& runnable, const QString& operation, "core", "gpgme.ctx.gnupg_version", minial_version); if (GFCompareSoftwareVersion(gnupg_version, minial_version) < 0) { - qCWarning(core) << "operation" << operation - << " not support for gnupg version: " << gnupg_version; + LOG_W() << "operation" << operation + << " not support for gnupg version: " << gnupg_version; return {GPG_ERR_NOT_SUPPORTED, TransferParams()}; } diff --git a/src/core/utils/GpgUtils.cpp b/src/core/utils/GpgUtils.cpp index 28892063..3d584b8f 100644 --- a/src/core/utils/GpgUtils.cpp +++ b/src/core/utils/GpgUtils.cpp @@ -50,9 +50,9 @@ auto GetGpgmeErrorString(gpgme_error_t err) -> QString { auto CheckGpgError(GpgError err) -> GpgError { auto err_code = gpg_err_code(err); if (err_code != GPG_ERR_NO_ERROR) { - qCWarning(core) << "gpg operation failed [error code: " << err_code - << "], source: " << gpgme_strsource(err) - << " description: " << GetGpgmeErrorString(err); + LOG_W() << "gpg operation failed [error code: " << err_code + << "], source: " << gpgme_strsource(err) + << " description: " << GetGpgmeErrorString(err); } return err_code; } @@ -61,15 +61,15 @@ auto CheckGpgError2ErrCode(GpgError err, GpgError predict) -> GpgErrorCode { auto err_code = gpg_err_code(err); if (err_code != gpg_err_code(predict)) { if (err_code == GPG_ERR_NO_ERROR) { - qCInfo(core) << "[Warning " << gpg_err_code(err) - << "] Source: " << gpgme_strsource(err) - << " description: " << GetGpgmeErrorString(err) - << " predict: " << GetGpgmeErrorString(predict); + LOG_I() << "[Warning " << gpg_err_code(err) + << "] Source: " << gpgme_strsource(err) + << " description: " << GetGpgmeErrorString(err) + << " predict: " << GetGpgmeErrorString(predict); } else { - qCWarning(core) << "[Error " << gpg_err_code(err) - << "] Source: " << gpgme_strsource(err) - << " description: " << GetGpgmeErrorString(err) - << " predict: " << GetGpgmeErrorString(predict); + LOG_W() << "[Error " << gpg_err_code(err) + << "] Source: " << gpgme_strsource(err) + << " description: " << GetGpgmeErrorString(err) + << " predict: " << GetGpgmeErrorString(predict); } } return err_code; @@ -81,9 +81,9 @@ auto DescribeGpgErrCode(GpgError err) -> GpgErrorDesc { auto CheckGpgError(GpgError err, const QString& /*comment*/) -> GpgError { if (gpg_err_code(err) != GPG_ERR_NO_ERROR) { - qCWarning(core) << "[Error " << gpg_err_code(err) - << "] Source: " << gpgme_strsource(err) - << " description: " << GetGpgmeErrorString(err); + LOG_W() << "[Error " << gpg_err_code(err) + << "] Source: " << gpgme_strsource(err) + << " description: " << GetGpgmeErrorString(err); } return err; } diff --git a/src/core/utils/IOUtils.cpp b/src/core/utils/IOUtils.cpp index 11f2b3e8..39f00d19 100644 --- a/src/core/utils/IOUtils.cpp +++ b/src/core/utils/IOUtils.cpp @@ -49,7 +49,7 @@ auto GetFileChecksum(const QString& file_name, auto ReadFile(const QString& file_name, QByteArray& data) -> bool { QFile file(file_name); if (!file.open(QIODevice::ReadOnly)) { - qCWarning(core) << "failed to open file: " << file_name; + LOG_W() << "failed to open file: " << file_name; return false; } data = file.readAll(); @@ -60,7 +60,7 @@ auto ReadFile(const QString& file_name, QByteArray& data) -> bool { auto WriteFile(const QString& file_name, const QByteArray& data) -> bool { QFile file(file_name); if (!file.open(QIODevice::WriteOnly)) { - qCWarning(core) << "failed to open file for writing: " << file_name; + LOG_W() << "failed to open file for writing: " << file_name; return false; } file.write(data); @@ -181,16 +181,16 @@ auto CalculateBinaryChacksum(const QString& path) -> QString { // check file info and access rights QFileInfo info(path); if (!info.exists() || !info.isFile() || !info.isReadable()) { - qCWarning(core) << "get info for file: " << info.filePath() - << " error, exists: " << info.exists(); + LOG_W() << "get info for file: " << info.filePath() + << " error, exists: " << info.exists(); return {}; } // open and read file QFile f(info.filePath()); if (!f.open(QIODevice::ReadOnly)) { - qCWarning(core) << "open " << path - << "to calculate checksum error: " << f.errorString(); + LOG_W() << "open " << path + << "to calculate checksum error: " << f.errorString(); return {}; } @@ -201,8 +201,8 @@ auto CalculateBinaryChacksum(const QString& path) -> QString { while (!f.atEnd()) { QByteArray const buffer = f.read(buffer_size); if (buffer.isEmpty()) { - qCWarning(core) << "error reading file: " << path - << " during checksum calculation"; + LOG_W() << "error reading file: " << path + << " during checksum calculation"; return {}; } hash_sha.addData(buffer); |