Browse Source

2.4|添加调试日志

master
zhaohe 3 months ago
parent
commit
ce2e36f431
  1. 8
      resources/spd_logger_cfg.json
  2. 2
      src/configs/version.hpp
  3. 19
      src/service/extapi_service.cpp
  4. 2
      src/service/wbesocket_connect_mgr_service.cpp
  5. 15
      src/service/wbesocket_connect_mgr_service.hpp
  6. 2
      tools/deply.sh

8
resources/spd_logger_cfg.json

@ -20,6 +20,14 @@
"type": "stdout_color_sink_mt" "type": "stdout_color_sink_mt"
}, },
{ {
"name": "ZCanReceiverHost",
"level": 0
},
{
"name": "ExtAPIService",
"level": 0
},
{
"name": "root", "name": "root",
"type": "logger", "type": "logger",
"level": 2, "level": 2,

2
src/configs/version.hpp

@ -1,2 +1,2 @@
#pragma once #pragma once
#define VERSION "2.3"
#define VERSION "2.4"

19
src/service/extapi_service.cpp

@ -120,7 +120,16 @@ void ExtAPIService::initialize() {
} }
string chname = webSocket.getUrl().substr(1); string chname = webSocket.getUrl().substr(1);
WbesocketConnectMgrService::insertNewClient(chname, findws(&webSocket), make_shared<WebSocketConnectInfo>(connectionState->getRemoteIp()));
static int id;
auto cinfo = make_shared<WebSocketConnectInfo>( //
msg->openInfo.uri, // url
connectionState->getRemoteIp(), // ip
chname, // chanme
fmt::format("{}{}({})", chname, id++, connectionState->getRemoteIp()) //
);
WbesocketConnectMgrService::insertNewClient(chname, findws(&webSocket), cinfo);
} else if (msg->type == ix::WebSocketMessageType::Message) { } else if (msg->type == ix::WebSocketMessageType::Message) {
string chname = webSocket.getUrl().substr(1); string chname = webSocket.getUrl().substr(1);
auto channel = DataChannelMgr::findByChannel(chname); auto channel = DataChannelMgr::findByChannel(chname);
@ -143,6 +152,8 @@ void ExtAPIService::initialize() {
WbesocketConnectMgrService::findClientByName(fromch->getAlias(), clients); WbesocketConnectMgrService::findClientByName(fromch->getAlias(), clients);
for (auto ch : clients) { for (auto ch : clients) {
if (ch) { if (ch) {
shared_ptr<WebSocketConnectInfo> cinfo = WbesocketConnectMgrService::findwsinfo(ch);
WebSocketSendInfo sendInfo; WebSocketSendInfo sendInfo;
if (binary) { if (binary) {
sendInfo = ch->sendBinary(string(data, len)); sendInfo = ch->sendBinary(string(data, len));
@ -150,8 +161,10 @@ void ExtAPIService::initialize() {
sendInfo = ch->sendText(string(data, len)); sendInfo = ch->sendText(string(data, len));
} }
if (!sendInfo.success) {
logger->error("send data to client {} failed", (int64_t)ch.get());
if (sendInfo.success) {
logger->debug("send data to client {} {} success", cinfo->getConnUniqueId(), binary ? StringUtils().bytesToString(data, len) : string(data, len));
} else {
logger->error("send data to client {} failed", cinfo->getConnUniqueId());
} }
} }
} }

2
src/service/wbesocket_connect_mgr_service.cpp

@ -11,7 +11,7 @@ static map<string, list<shared_ptr<WebSocket>>> wsClients;
static map<void *, shared_ptr<WebSocketConnectInfo>> wsClientsInfo; static map<void *, shared_ptr<WebSocketConnectInfo>> wsClientsInfo;
static std::mutex wsClientsLock; static std::mutex wsClientsLock;
shared_ptr<WebSocketConnectInfo> findwsinfo(shared_ptr<WebSocket> client) {
shared_ptr<WebSocketConnectInfo> WbesocketConnectMgrService::findwsinfo(shared_ptr<WebSocket> client) {
if (client == nullptr) return nullptr; if (client == nullptr) return nullptr;
auto it = wsClientsInfo.find((void *)client.get()); auto it = wsClientsInfo.find((void *)client.get());
if (it == wsClientsInfo.end()) return nullptr; if (it == wsClientsInfo.end()) return nullptr;

15
src/service/wbesocket_connect_mgr_service.hpp

@ -31,12 +31,23 @@ using namespace nlohmann;
using namespace ix; using namespace ix;
class WebSocketConnectInfo { class WebSocketConnectInfo {
string url;
string remoteIp; string remoteIp;
string chname;
string connUniqueId;
public: public:
WebSocketConnectInfo() {} WebSocketConnectInfo() {}
WebSocketConnectInfo(string ip) : remoteIp(ip) {}
WebSocketConnectInfo(string url, string remoteIp, string chname, string connUniqueId) {
this->url = url;
this->remoteIp = remoteIp;
this->chname = chname;
this->connUniqueId = connUniqueId;
}
string getRemoteIp() { return remoteIp; } string getRemoteIp() { return remoteIp; }
string getUrl() { return url; }
string getChannelName() { return chname; }
string getConnUniqueId() { return connUniqueId; }
}; };
class WbesocketConnectMgrService { class WbesocketConnectMgrService {
@ -47,6 +58,8 @@ class WbesocketConnectMgrService {
static json getConnectionList(); static json getConnectionList();
static void updateConnectList(); static void updateConnectList();
static shared_ptr<WebSocketConnectInfo> findwsinfo(shared_ptr<WebSocket> client);
}; };
} // namespace iflytop } // namespace iflytop

2
tools/deply.sh

@ -9,7 +9,9 @@ fi
server=$1 server=$1
ssh $server 'mkdir -p /iflytopd/iflytophald/' ssh $server 'mkdir -p /iflytopd/iflytophald/'
ssh $server 'systemctl stop iflytophald'
scp ./build/app/iflytophald $server:/iflytopd/iflytophald/ scp ./build/app/iflytophald $server:/iflytopd/iflytophald/
# scp ./resources/iflytophald.service $server:/lib/systemd/system/ # scp ./resources/iflytophald.service $server:/lib/systemd/system/
# scp ./resources/config.ini $server:/iflytopd/iflytophald/ # scp ./resources/config.ini $server:/iflytopd/iflytophald/
scp ./resources/spd_logger_cfg.json $server:/iflytopd/iflytophald/ scp ./resources/spd_logger_cfg.json $server:/iflytopd/iflytophald/
ssh $server 'systemctl start iflytophald'
Loading…
Cancel
Save