diff --git a/src/lib/base/Log.cpp b/src/lib/base/Log.cpp index 442f57682..f01cb67f5 100644 --- a/src/lib/base/Log.cpp +++ b/src/lib/base/Log.cpp @@ -100,7 +100,13 @@ std::vector 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 makeMessage(const char *filename, int lineNumber, const char * std::vector 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 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(priority) >= -1 && static_cast(priority) < g_numPriority); + assert(static_cast(priority) >= -2 && static_cast(priority) < g_numPriority); assert(msg != nullptr); if (!msg) return; diff --git a/src/lib/base/Log.h b/src/lib/base/Log.h index f18905a2a..c2d2a2a2e 100644 --- a/src/lib/base/Log.h +++ b/src/lib/base/Log.h @@ -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__)) diff --git a/src/lib/base/LogLevel.h b/src/lib/base/LogLevel.h index 5e1ff48c8..a4d877d12 100644 --- a/src/lib/base/LogLevel.h +++ b/src/lib/base/LogLevel.h @@ -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 diff --git a/src/lib/client/Client.cpp b/src/lib/client/Client.cpp index ce2ee049c..375b6b750 100644 --- a/src/lib/client/Client.cpp +++ b/src/lib/client/Client.cpp @@ -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() ); } diff --git a/src/lib/net/SecureSocket.cpp b/src/lib/net/SecureSocket.cpp index 765270870..2a4516712 100644 --- a/src/lib/net/SecureSocket.cpp +++ b/src/lib/net/SecureSocket.cpp @@ -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); diff --git a/src/lib/server/ClientProxy1_0.cpp b/src/lib/server/ClientProxy1_0.cpp index feadccd3c..904c0361f 100644 --- a/src/lib/server/ClientProxy1_0.cpp +++ b/src/lib/server/ClientProxy1_0.cpp @@ -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(); } diff --git a/src/lib/server/Server.cpp b/src/lib/server/Server.cpp index 9da6e3e44..df15a5186 100644 --- a/src/lib/server/Server.cpp +++ b/src/lib/server/Server.cpp @@ -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);