diff options
author | saturneric <[email protected]> | 2024-01-05 12:55:15 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-01-05 12:55:15 +0000 |
commit | 644aa4397b03dbef73f8bfedc13925b51cad836b (patch) | |
tree | 7788d1cd2f0687dd8e576b111d9990c580092e7a /src/core/module | |
parent | fix: slove some known issues (diff) | |
download | GpgFrontend-644aa4397b03dbef73f8bfedc13925b51cad836b.tar.gz GpgFrontend-644aa4397b03dbef73f8bfedc13925b51cad836b.zip |
feat: integrate logging api to core
Diffstat (limited to 'src/core/module')
-rw-r--r-- | src/core/module/Event.cpp | 15 | ||||
-rw-r--r-- | src/core/module/GlobalModuleContext.cpp | 59 |
2 files changed, 40 insertions, 34 deletions
diff --git a/src/core/module/Event.cpp b/src/core/module/Event.cpp index 6bd6eae5..b2a4417a 100644 --- a/src/core/module/Event.cpp +++ b/src/core/module/Event.cpp @@ -42,7 +42,7 @@ class Event::Impl { for (const auto& param : params) { AddParameter(param); } - SPDLOG_DEBUG("create event {}", event_identifier_); + GF_CORE_LOG_DEBUG("create event {}", event_identifier_); } auto operator[](const std::string& key) const @@ -80,19 +80,20 @@ class Event::Impl { void ExecuteCallback(ListenerIdentifier listener_id, const DataObjectPtr& data_object) { - SPDLOG_DEBUG("try to execute callback for event {} with listener {}", - event_identifier_, listener_id); + GF_CORE_LOG_DEBUG("try to execute callback for event {} with listener {}", + event_identifier_, listener_id); if (callback_) { - SPDLOG_DEBUG("executing callback for event {} with listener {}", - event_identifier_, listener_id); + GF_CORE_LOG_DEBUG("executing callback for event {} with listener {}", + event_identifier_, listener_id); if (!QMetaObject::invokeMethod( callback_thread_, [callback = callback_, event_identifier = event_identifier_, listener_id, data_object]() { callback(event_identifier, listener_id, data_object); })) { - SPDLOG_ERROR("failed to invoke callback for event {} with listener {}", - event_identifier_, listener_id); + GF_CORE_LOG_ERROR( + "failed to invoke callback for event {} with listener {}", + event_identifier_, listener_id); } } } diff --git a/src/core/module/GlobalModuleContext.cpp b/src/core/module/GlobalModuleContext.cpp index e2f58c92..6222a97d 100644 --- a/src/core/module/GlobalModuleContext.cpp +++ b/src/core/module/GlobalModuleContext.cpp @@ -62,7 +62,7 @@ class GlobalModuleContext::Impl { auto module_info_opt = search_module_register_table(module->GetModuleIdentifier()); if (!module_info_opt.has_value()) { - SPDLOG_ERROR( + GF_CORE_LOG_ERROR( "cannot find module id {} at register table, fallbacking to " "default " "channel", @@ -94,18 +94,20 @@ class GlobalModuleContext::Impl { } auto RegisterModule(const ModulePtr& module) -> bool { - SPDLOG_DEBUG("attempting to register module: {}", - module->GetModuleIdentifier()); + GF_CORE_LOG_DEBUG("attempting to register module: {}", + module->GetModuleIdentifier()); // Check if the module is null or already registered. if (module == nullptr || module_register_table_.find(module->GetModuleIdentifier()) != module_register_table_.end()) { - SPDLOG_ERROR("module is null or have already registered this module"); + GF_CORE_LOG_ERROR( + "module is null or have already registered this module"); return false; } if (!module->Register()) { - SPDLOG_ERROR("register module {} failed", module->GetModuleIdentifier()); + GF_CORE_LOG_ERROR("register module {} failed", + module->GetModuleIdentifier()); return false; } @@ -124,18 +126,19 @@ class GlobalModuleContext::Impl { // Register the module with its identifier. module_register_table_[module->GetModuleIdentifier()] = register_info; - SPDLOG_DEBUG("successfully registered module: {}", - module->GetModuleIdentifier()); + GF_CORE_LOG_DEBUG("successfully registered module: {}", + module->GetModuleIdentifier()); return true; } auto ActiveModule(ModuleIdentifier module_id) -> bool { - SPDLOG_DEBUG("attempting to activate module: {}", module_id); + GF_CORE_LOG_DEBUG("attempting to activate module: {}", module_id); // Search for the module in the register table. auto module_info_opt = search_module_register_table(module_id); if (!module_info_opt.has_value()) { - SPDLOG_ERROR("cannot find module id {} at register table", module_id); + GF_CORE_LOG_ERROR("cannot find module id {} at register table", + module_id); return false; } @@ -144,7 +147,7 @@ class GlobalModuleContext::Impl { // try to get module from module info auto module = module_info->module; if (module == nullptr) { - SPDLOG_ERROR( + GF_CORE_LOG_ERROR( "module id {} at register table is releated to a null module", module_id); return false; @@ -156,19 +159,19 @@ class GlobalModuleContext::Impl { module_info->activate = true; } - SPDLOG_DEBUG("module activation status: {}", module_info->activate); + GF_CORE_LOG_DEBUG("module activation status: {}", module_info->activate); return module_info->activate; } auto ListenEvent(ModuleIdentifier module_id, EventIdentifier event) -> bool { - SPDLOG_DEBUG("module: {} is attempting to listen to event {}", module_id, - event); + GF_CORE_LOG_DEBUG("module: {} is attempting to listen to event {}", + module_id, event); // Check if the event exists, if not, create it. auto met_it = module_events_table_.find(event); if (met_it == module_events_table_.end()) { module_events_table_[event] = std::unordered_set<ModuleIdentifier>(); met_it = module_events_table_.find(event); - SPDLOG_INFO("new event {} of module system created", event); + GF_CORE_LOG_INFO("new event {} of module system created", event); } auto& listeners_set = met_it->second; @@ -184,7 +187,8 @@ 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()) { - SPDLOG_ERROR("cannot find module id {} at register table", module_id); + GF_CORE_LOG_ERROR("cannot find module id {} at register table", + module_id); return false; } @@ -199,13 +203,13 @@ class GlobalModuleContext::Impl { auto TriggerEvent(const EventRefrernce& event) -> bool { auto event_id = event->GetIdentifier(); - SPDLOG_DEBUG("attempting to trigger event: {}", event_id); + GF_CORE_LOG_DEBUG("attempting to trigger event: {}", event_id); // Find the set of listeners associated with the given event in the table 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 - SPDLOG_WARN( + GF_CORE_LOG_WARN( "event {} is not listening by anyone and not registered as well", event_id); return false; @@ -217,14 +221,14 @@ 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 - SPDLOG_WARN("event {} is not listening by anyone", - event->GetIdentifier()); + GF_CORE_LOG_WARN("event {} is not listening by anyone", + event->GetIdentifier()); return false; } // Log the number of listeners for this event - SPDLOG_DEBUG("event {}'s current listeners size: {}", - event->GetIdentifier(), listeners_set.size()); + GF_CORE_LOG_DEBUG("event {}'s current listeners size: {}", + event->GetIdentifier(), listeners_set.size()); // Iterate through each listener and execute the corresponding module for (const auto& listener_module_id : listeners_set) { @@ -233,8 +237,8 @@ class GlobalModuleContext::Impl { // Log an error if the module is not found in the registration table if (!module_info_opt.has_value()) { - SPDLOG_ERROR("cannot find module id {} at register table", - listener_module_id); + GF_CORE_LOG_ERROR("cannot find module id {} at register table", + listener_module_id); continue; } @@ -242,9 +246,10 @@ class GlobalModuleContext::Impl { auto module_info = module_info_opt.value(); auto module = module_info->module; - SPDLOG_DEBUG("module {} is listening to event {}, activate state: {}", - module_info->module->GetModuleIdentifier(), - event->GetIdentifier(), module_info->activate); + GF_CORE_LOG_DEBUG( + "module {} is listening to event {}, activate state: {}", + module_info->module->GetModuleIdentifier(), event->GetIdentifier(), + module_info->activate); // Check if the module is activated if (!module_info->activate) continue; @@ -256,7 +261,7 @@ class GlobalModuleContext::Impl { int code, DataObjectPtr) { if (code < 0) { // Log an error if the module execution fails - SPDLOG_ERROR( + GF_CORE_LOG_ERROR( "module {} execution failed of event {}: exec return code {}", listener_module_id, event_id, code); } |