refactor: Move all messages that are checked for by GUI in the log to new IPC Level so the gui can work with any filter level

This commit is contained in:
sithlord48
2025-08-23 13:38:30 -04:00
committed by Nick Bolton
parent 78eb353985
commit cba3881f41
7 changed files with 22 additions and 15 deletions

View File

@ -100,7 +100,13 @@ std::vector<char> makeMessage(const char *filename, int lineNumber, const char *
makeTimeString(timeBuffer);
size_t timestampLength = strnlen(timeBuffer.data(), timeBufferSize);
size_t priorityLength = strnlen(g_priority[currentPriority], priorityMaxSize);
auto sectionName = "IPC";
if (priority != LogLevel::IPC) {
sectionName = g_priority[currentPriority];
}
size_t priorityLength = strnlen(sectionName, priorityMaxSize);
size_t messageLength = strnlen(message, SIZE_MAX);
size_t bufferSize = baseSize + timestampLength + priorityLength + messageLength;
@ -113,22 +119,20 @@ std::vector<char> makeMessage(const char *filename, int lineNumber, const char *
std::vector<char> buffer(bufferSize);
#ifndef __APPLE__
std::format_to_n(
buffer.data(), bufferSize, "[{}] {}: {}\n\t{}:{}", timeBuffer.data(), g_priority[currentPriority], message,
filename, lineNumber
buffer.data(), bufferSize, "[{}] {}: {}\n\t{}:{}", timeBuffer.data(), sectionName, message, filename, lineNumber
);
#else
snprintf(
buffer.data(), bufferSize, "[%s] %s: %s\n\t%s:%d", timeBuffer.data(), g_priority[currentPriority], message,
filename, lineNumber
buffer.data(), bufferSize, "[%s] %s: %s\n\t%s:%d", timeBuffer.data(), sectionName, message, filename, lineNumber
);
#endif
return buffer;
} else {
std::vector<char> buffer(bufferSize);
#ifndef __APPLE__
std::format_to_n(buffer.data(), bufferSize, "[{}] {}: {}", timeBuffer.data(), g_priority[currentPriority], message);
std::format_to_n(buffer.data(), bufferSize, "[{}] {}: {}", timeBuffer.data(), sectionName, message);
#else
snprintf(buffer.data(), bufferSize, "[%s] %s: %s", timeBuffer.data(), g_priority[currentPriority], message);
snprintf(buffer.data(), bufferSize, "[%s] %s: %s", timeBuffer.data(), sectionName, message);
#endif
return buffer;
}
@ -288,7 +292,7 @@ LogLevel Log::getFilter() const
void Log::output(LogLevel priority, const char *msg)
{
assert(static_cast<int>(priority) >= -1 && static_cast<int>(priority) < g_numPriority);
assert(static_cast<int>(priority) >= -2 && static_cast<int>(priority) < g_numPriority);
assert(msg != nullptr);
if (!msg)
return;

View File

@ -197,6 +197,7 @@ otherwise it expands to a call that doesn't.
// end, then we resort to using non-numerical chars. this still works (since
// to deduce the number we subtract octal \060, so '/' is -1, and ':' is 10
#define CLOG_IPC CLOG_TRACE "%z\056" // char is '' ?
#define CLOG_PRINT CLOG_TRACE "%z\057" // char is '/'
#define CLOG_CRIT CLOG_TRACE "%z\060" // char is '0'
#define CLOG_ERR CLOG_TRACE "%z\061"
@ -210,6 +211,7 @@ otherwise it expands to a call that doesn't.
#define CLOG_DEBUG4 CLOG_TRACE "%z\071" // char is '9'
#define CLOG_DEBUG5 CLOG_TRACE "%z\072" // char is ':'
#define LOG_IPC(...) LOG((CLOG_IPC __VA_ARGS__))
#define LOG_PRINT(...) LOG((CLOG_PRINT __VA_ARGS__))
#define LOG_CRIT(...) LOG((CLOG_CRIT __VA_ARGS__))
#define LOG_ERR(...) LOG((CLOG_ERR __VA_ARGS__))

View File

@ -13,6 +13,7 @@ The logging priority levels in order of highest to lowest priority.
*/
enum class LogLevel
{
IPC = -2, //!< For IPC Messages the gui must see, remove when IPC works proper
Print = -1, //!< For print only (no file or time)
Fatal, //!< For fatal errors
Error, //!< For serious errors

View File

@ -110,9 +110,9 @@ void Client::connect(size_t addressIndex)
// m_serverAddress will be null if the hostname address is not reolved
if (m_serverAddress.getAddress() != nullptr) {
// to help users troubleshoot, show server host name (issue: 60)
LOG(
(CLOG_NOTE "connecting to '%s': %s:%i", m_serverAddress.getHostname().c_str(),
ARCH->addrToString(m_serverAddress.getAddress()).c_str(), m_serverAddress.getPort())
LOG_IPC(
"connecting to '%s': %s:%i", m_serverAddress.getHostname().c_str(),
ARCH->addrToString(m_serverAddress.getAddress()).c_str(), m_serverAddress.getPort()
);
}

View File

@ -637,7 +637,7 @@ bool SecureSocket::verifyCertFingerprint(const QString &FingerprintDatabasePath)
return false;
// Gui Must Parse this line, DO NOT CHANGE
LOG_NOTE("peer fingerprint: %s", qPrintable(deskflow::formatSSLFingerprint(sha256.data, false)));
LOG_IPC("peer fingerprint: %s", qPrintable(deskflow::formatSSLFingerprint(sha256.data, false)));
QFile file(FingerprintDatabasePath);

View File

@ -185,7 +185,7 @@ bool ClientProxy1_0::parseMessage(const uint8_t *code)
void ClientProxy1_0::handleDisconnect()
{
LOG_NOTE("client \"%s\" has disconnected", getName().c_str());
LOG_IPC("client \"%s\" has disconnected", getName().c_str());
disconnect();
}
@ -198,7 +198,7 @@ void ClientProxy1_0::handleWriteError()
void ClientProxy1_0::handleFlatline()
{
// didn't get a heartbeat fast enough. assume client is dead.
LOG_NOTE("client \"%s\" is dead", getName().c_str());
LOG_IPC("client \"%s\" is dead", getName().c_str());
disconnect();
}

View File

@ -246,7 +246,7 @@ void Server::adoptClient(BaseClientProxy *client)
closeClient(client, kMsgEBusy);
return;
}
LOG_NOTE("client \"%s\" has connected", getName(client).c_str());
LOG_IPC("client \"%s\" has connected", getName(client).c_str());
// send configuration options to client
sendOptions(client);