#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
{
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++)
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();
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;
}