fix test shell print log
This commit is contained in:
@@ -3450,34 +3450,38 @@ void Worker::handleViewLogCommand(const QString& command, QTcpSocket* clientSock
|
|||||||
clientSocket->flush();
|
clientSocket->flush();
|
||||||
|
|
||||||
while (!stopViewLog) {
|
while (!stopViewLog) {
|
||||||
// **1. 监听输入,用户输入 ``` 退出**
|
// 1. 监听退出标志(收到反引号 `)
|
||||||
if (clientSocket->waitForReadyRead(500)) { // ? 监听输入
|
if (clientSocket->waitForReadyRead(500)) {
|
||||||
QByteArray input = clientSocket->readAll().trimmed();
|
QByteArray input = clientSocket->readAll().trimmed();
|
||||||
if (input == "`") { // ? 用户输入 ```,退出日志模式
|
if (input == "`") {
|
||||||
std::cout << "Received '`' from shell socket! Exiting viewlog...\n";
|
std::cout << "Received '`' from shell socket! Exiting viewlog...\n";
|
||||||
stopViewLog = true;
|
stopViewLog = true;
|
||||||
showinshellflag = false;
|
showinshellflag = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// **2. 获取日志内容并发送**
|
// 2. 批量获取日志并发送
|
||||||
pthread_mutex_lock(logMutex);
|
std::list<std::string> tempLogs;
|
||||||
if (!logList->empty()) {
|
|
||||||
std::string logEntry = logList->front();
|
|
||||||
logList->pop_front();
|
|
||||||
pthread_mutex_unlock(logMutex);
|
|
||||||
|
|
||||||
if (!logEntry.empty()) {
|
pthread_mutex_lock(logMutex);
|
||||||
clientSocket->write("\r\x1B[K");
|
if (!logList->empty()) {
|
||||||
clientSocket->write((logEntry + "\n").c_str());
|
tempLogs.swap(*logList); // 把 logList 中的内容全取出
|
||||||
clientSocket->flush();
|
}
|
||||||
}
|
pthread_mutex_unlock(logMutex);
|
||||||
} else {
|
|
||||||
pthread_mutex_unlock(logMutex);
|
if (!tempLogs.empty()) {
|
||||||
usleep(500000); // ? 防止 CPU 100% 占用
|
for (const auto& logEntry : tempLogs) {
|
||||||
}
|
if (!logEntry.empty()) {
|
||||||
}
|
clientSocket->write("\r\x1B[K"); // 清除当前行
|
||||||
|
clientSocket->write((logEntry + "\n").c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
clientSocket->flush();
|
||||||
|
} else {
|
||||||
|
usleep(500000); // 空闲等待,降低 CPU 占用
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// **3. 退出 `viewlog`,返回 Shell**
|
// **3. 退出 `viewlog`,返回 Shell**
|
||||||
clientSocket->write("\r\x1B[K");
|
clientSocket->write("\r\x1B[K");
|
||||||
@@ -6343,6 +6347,18 @@ protected:
|
|||||||
return traits_type::eof();
|
return traits_type::eof();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ✅ 如果当前级别未启用,不记录
|
||||||
|
bool shouldLog = false;
|
||||||
|
switch (m_level) {
|
||||||
|
case LOGERROR: shouldLog = errorOutputEnabled; break;
|
||||||
|
case LOGWARN: shouldLog = warnOutputEnabled; break;
|
||||||
|
case LOGNORMAL: shouldLog = normalOutputEnabled; break;
|
||||||
|
case LOGDEBUG: shouldLog = debugOutputEnabled; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shouldLog) return ch; // 🚫 日志开关未启用,直接跳过
|
||||||
|
|
||||||
// 2) 存到我们的临时缓存,注意加锁保护
|
// 2) 存到我们的临时缓存,注意加锁保护
|
||||||
pthread_mutex_lock(&m_mutex); //防止多线程推入崩溃lnk20250305
|
pthread_mutex_lock(&m_mutex); //防止多线程推入崩溃lnk20250305
|
||||||
m_buffer.push_back(static_cast<char>(ch));
|
m_buffer.push_back(static_cast<char>(ch));
|
||||||
|
|||||||
Reference in New Issue
Block a user