Skip to content

Commit

Permalink
Logger: avoid leaking fullpath (#1250)
Browse files Browse the repository at this point in the history
  • Loading branch information
clementperon authored Dec 2, 2023
1 parent ec14cab commit 4e8702a
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions Common++/header/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@
#define LOG_MODULE UndefinedLogModule
#endif

// Use __FILE_NAME__ to avoid leaking complete full path
#ifdef __FILE_NAME__
#define PCAPPP_FILENAME __FILE_NAME__
#else
#define PCAPPP_FILENAME __FILE__
#endif

#define PCPP_LOG(level, message) do \
{ \
std::ostringstream* sstream = pcpp::Logger::getInstance().internalCreateLogStream(); \
(*sstream) << message; \
pcpp::Logger::getInstance().internalPrintLogMessage(sstream, level, PCAPPP_FILENAME, __FUNCTION__, __LINE__); \
} while(0)

#define PCPP_LOG_DEBUG(message) do \
{ \
if (pcpp::Logger::getInstance().logsEnabled() && pcpp::Logger::getInstance().isDebugEnabled(LOG_MODULE)) \
{ \
PCPP_LOG(pcpp::Logger::Debug, message); \
} \
} while(0)

#define PCPP_LOG_ERROR(message) do \
{ \
PCPP_LOG(pcpp::Logger::Error, message); \
} while (0)

/// @file

/**
Expand Down Expand Up @@ -230,24 +257,6 @@ namespace pcpp

static void defaultLogPrinter(LogLevel logLevel, const std::string& logMessage, const std::string& file, const std::string& method, const int line);
};

#define PCPP_LOG_DEBUG(message) do \
{ \
if (pcpp::Logger::getInstance().logsEnabled() && pcpp::Logger::getInstance().isDebugEnabled(LOG_MODULE)) \
{ \
std::ostringstream* sstream = pcpp::Logger::getInstance().internalCreateLogStream(); \
(*sstream) << message; \
pcpp::Logger::getInstance().internalPrintLogMessage(sstream, pcpp::Logger::Debug, __FILE__, __FUNCTION__, __LINE__); \
} \
} while(0)

#define PCPP_LOG_ERROR(message) do \
{ \
std::ostringstream* sstream = pcpp::Logger::getInstance().internalCreateLogStream(); \
(*sstream) << message; \
pcpp::Logger::getInstance().internalPrintLogMessage(sstream, pcpp::Logger::Error, __FILE__, __FUNCTION__, __LINE__); \
} while (0)

} // namespace pcpp

#endif /* PCAPPP_LOGGER */

0 comments on commit 4e8702a

Please sign in to comment.