From f203694d367f822bc33934c8a5088e509e2b73ed Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Fri, 4 Oct 2024 18:00:49 +0800 Subject: [PATCH] =?utf8?q?=E7=B3=BB=E7=BB=9F=EF=BC=9A=E5=A2=9E=E5=8A=A0?= =?utf8?q?=E7=B3=BB=E7=BB=9F=E6=97=A5=E5=BF=97=E6=98=BE=E7=A4=BAUI?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../debug_output_notification.h | 2 + .../debug_output_notification.cpp | 69 ++++++++++++++++++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h index b8d622ed4..6f9a6e843 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h @@ -9,6 +9,7 @@ #define DEBUG_OUTPUT_NOTIFICATION_H #include "BaseView.h" #include "../notify/debug_output_notification/debug_output_notification_item.h" +#include namespace OHOS { UIViewGroup *CreateDebugOutputMainView(void); @@ -34,6 +35,7 @@ namespace OHOS std::string get_bt_runtime_status_t(void); std::string get_cat1_runtime_status_t(void); std::string get_runtime_status_t(void); + std::string get_system_log(void); private: DebugOutputViewEventListener(); diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp index a8ce2ce67..134522814 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp @@ -8,7 +8,12 @@ #include "../notify/debug_output_notification/debug_output_notification_itemview.h" #include #include +#include +#include +#include #include "bluetooth/include/BluetoothModel.h" +#include "system/include/SystemLogModel.h" +#include "wearable_log.h" namespace OHOS { @@ -42,6 +47,7 @@ namespace OHOS debugOutputItemInfo[index++] = {1, "bt_ble_connectstat"}; debugOutputItemInfo[index++] = {2, "cat1_runtime_status_t"}; debugOutputItemInfo[index++] = {3, "runtime_status_t"}; + debugOutputItemInfo[index++] = {4, "system_log"}; usedLen = index; /* -------------------------------- Add data -------------------------------- */ for (uint8_t i = 0; i < usedLen; i++) @@ -156,6 +162,64 @@ namespace OHOS return result; } + std::string DebugOutputViewEventListener::get_system_log() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_system_log"); + + // 获取系统日志实例 + auto logModel = SystemLogModel::GetInstance(); + uint8_t logSize = logModel->getLogSize(); + if (logSize == 0) + { + return "目前没有日志"; + } + + std::vector systemlogs = logModel->getLogData(); + std::ostringstream str; + + for (int i = 0; i < logSize; i++) + { + // 处理日志类型 + switch (systemlogs[i].type) + { + case SystemLogType::POWER_ON: + str << "开机:"; + break; + case SystemLogType::POWER_OFF: + str << "关机:"; + break; + case SystemLogType::RESTART: + str << "重启:"; + break; + case SystemLogType::FACTORY_RESET: + str << "恢复出厂设置:"; + break; + case SystemLogType::SOFTWARE_UPDATE: + str << "软件更新:"; + break; + default: + str << "UNKNOWN:"; + break; + } + + // 格式化时间 + char labelTime[20]; + std::string timestr; + if (uapi_get_TIME_STR(systemlogs[i].timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) + { + timestr = "--"; + } + else + { + timestr = labelTime; + } + + str << "[" << timestr << "] "<< "\n"; // 拼接日志内容 + } + + return str.str(); // 返回拼接后的字符串 + } + bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) { std::string viewId = view.GetViewId(); @@ -203,7 +267,10 @@ namespace OHOS str = get_runtime_status_t(); debugOutputLabel->SetText(str.c_str()); break; - + case 4: + str = get_system_log(); + debugOutputLabel->SetText(str.c_str()); + break; default: break; } -- 2.17.1