系统:增加系统日志显示UI
authorCaisking <3449750381@qq.com>
Fri, 4 Oct 2024 10:00:49 +0000 (18:00 +0800)
committerCaisking <3449750381@qq.com>
Fri, 4 Oct 2024 10:00:49 +0000 (18:00 +0800)
code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h
code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp

index b8d622e..6f9a6e8 100644 (file)
@@ -9,6 +9,7 @@
 #define DEBUG_OUTPUT_NOTIFICATION_H
 #include "BaseView.h"
 #include "../notify/debug_output_notification/debug_output_notification_item.h"
+#include <string>
 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();
index a8ce2ce..1345228 100644 (file)
@@ -8,7 +8,12 @@
 #include "../notify/debug_output_notification/debug_output_notification_itemview.h"
 #include <custom_runtime.h>
 #include <custom_utils.h>
+#include <sstream>  
+#include <iomanip> 
+#include <sys/types.h>
 #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<SystemLogData> 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;
         }