From b77dc8cf5a4ee9b4a94f63b35eae57ee28bb0993 Mon Sep 17 00:00:00 2001 From: zjk <1553836110@qq.com> Date: Wed, 2 Sep 2026 20:47:47 +0800 Subject: [PATCH] =?UTF-8?q?pPowerManger=20=E7=BD=91=E9=A1=B5=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=9B=91=E6=8E=A7=E6=8C=87=E5=90=91=E5=AE=9E=E9=99=85?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=96=87=E4=BB=B6=EF=BC=9AHttpServer=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=20setLogFilePath=EF=BC=8COnStartUp=20?= =?UTF-8?q?=E4=B8=8E=20loguru=20=E5=85=B1=E7=94=A8=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=EF=BC=88=E4=BF=AE=E5=A4=8D=20systemd=20?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E7=9B=AE=E5=BD=95=E4=B8=8B=E7=9B=B8=E5=AF=B9?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E6=89=93=E5=BC=80=E5=A4=B1=E8=B4=A5=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pPowerManger/PowerManger.cpp | 3 +++ src/pPowerManger/httpserver/httpserver.h | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/pPowerManger/PowerManger.cpp b/src/pPowerManger/PowerManger.cpp index 34be737..2626847 100644 --- a/src/pPowerManger/PowerManger.cpp +++ b/src/pPowerManger/PowerManger.cpp @@ -246,6 +246,9 @@ bool PowerManger::OnStartUp() loguru::add_file(logPath.c_str(), loguru::Append, loguru::Verbosity_MAX); LOG_F(INFO, "日志文件路径: %s", logPath.c_str()); + // 网页日志监控使用同一文件(默认相对路径在 systemd WorkingDirectory 下打不开) + if (m_httpServer) m_httpServer->setLogFilePath(logPath); + // 初始化数据库:dbpath 未配置则默认当前目录 if (dbPath.empty()) dbPath = "power_data.db"; LOG_F(INFO, "数据库存储路径: %s", dbPath.c_str()); diff --git a/src/pPowerManger/httpserver/httpserver.h b/src/pPowerManger/httpserver/httpserver.h index 7323c7c..de2d770 100644 --- a/src/pPowerManger/httpserver/httpserver.h +++ b/src/pPowerManger/httpserver/httpserver.h @@ -86,6 +86,11 @@ private: static const size_t MAX_CACHE_SIZE = 1000; // 最大缓存条数 static const size_t MAX_WS_BACKLOG = 256 * 1024; // WebSocket发送积压阈值,超过则跳过推送 +public: + // 设置被监控的日志文件路径(须与 logpath 配置一致; + // 默认相对路径在 systemd WorkingDirectory 下会打开失败) + void setLogFilePath(const std::string& path) { m_logFilePath = path; } + }; #endif // HTTP_SERVER_H