From 8c6f7bb8196dff7acac5f9a1c4aa165d6668f7fa Mon Sep 17 00:00:00 2001 From: Jacob Barrett Date: Mon, 11 Jan 2021 20:19:10 -0800 Subject: [PATCH] Rebase cleanup. Clang-tidy. Clang-format. --- cppcache/src/Log.cpp | 3 +- cppcache/src/Utils.hpp | 13 ++-- cppcache/src/util/Log.hpp | 126 +++++++++++++++++++--------------- cppcache/test/LoggingTest.cpp | 7 +- 4 files changed, 83 insertions(+), 66 deletions(-) diff --git a/cppcache/src/Log.cpp b/cppcache/src/Log.cpp index 902272e207..4bf5609381 100644 --- a/cppcache/src/Log.cpp +++ b/cppcache/src/Log.cpp @@ -409,8 +409,7 @@ void Log::logInternal(LogLevel level, const std::string& msg) { removeOldestRolledLogFile(); } - if ((numChars = fprintf(g_log, "%s%s\n", buf.c_str(), msg.c_str())) == - 0 || + if (fprintf(g_log, "%s%s\n", buf.c_str(), msg.c_str()) == 0 || ferror(g_log)) { // Let's continue without throwing the exception. It should not cause // process to terminate diff --git a/cppcache/src/Utils.hpp b/cppcache/src/Utils.hpp index a419cab90b..ac9727f097 100644 --- a/cppcache/src/Utils.hpp +++ b/cppcache/src/Utils.hpp @@ -162,8 +162,9 @@ class APACHE_GEODE_EXPORT Utils { * Convert the byte array to a string as "%d %d ...". * maxLength as zero implies no limit. */ - static std::string convertBytesToString(const uint8_t* bytes, size_t length, - size_t maxLength = _GEODE_LOG_MESSAGE_LIMIT); + static std::string convertBytesToString( + const uint8_t* bytes, size_t length, + size_t maxLength = _GEODE_LOG_MESSAGE_LIMIT); /** * lib should be in the form originally required by ACE_DLL, typically just @@ -181,15 +182,17 @@ class APACHE_GEODE_EXPORT Utils { * Convert the byte array to a string as "%d %d ...". * maxLength as zero implies no limit. */ - static std::string convertBytesToString(const int8_t* bytes, size_t length, - size_t maxLength = _GEODE_LOG_MESSAGE_LIMIT); + static std::string convertBytesToString( + const int8_t* bytes, size_t length, + size_t maxLength = _GEODE_LOG_MESSAGE_LIMIT); /** * Convert the byte array to a string as "%d %d ...". * maxLength as zero implies no limit. */ inline static std::string convertBytesToString( - const char* bytes, size_t length, size_t maxLength = _GEODE_LOG_MESSAGE_LIMIT) { + const char* bytes, size_t length, + size_t maxLength = _GEODE_LOG_MESSAGE_LIMIT) { return convertBytesToString(reinterpret_cast(bytes), length, maxLength); } diff --git a/cppcache/src/util/Log.hpp b/cppcache/src/util/Log.hpp index 75a15cb96e..56137a7d29 100644 --- a/cppcache/src/util/Log.hpp +++ b/cppcache/src/util/Log.hpp @@ -219,60 +219,76 @@ class APACHE_GEODE_EXPORT Log { } // namespace geode } // namespace apache -#define LOGERROR(...) \ - if (::apache::geode::client::Log::enabled( \ - apache::geode::client::LogLevel::Error)) { \ - ::apache::geode::client::Log::log( \ - ::apache::geode::client::LogLevel::Error, __VA_ARGS__); \ - } - -#define LOGWARN(...) \ - if (::apache::geode::client::Log::enabled( \ - apache::geode::client::LogLevel::Warning)) { \ - ::apache::geode::client::Log::log( \ - ::apache::geode::client::LogLevel::Warning, __VA_ARGS__); \ - } - -#define LOGINFO(...) \ - if (::apache::geode::client::Log::enabled( \ - apache::geode::client::LogLevel::Info)) { \ - ::apache::geode::client::Log::log(::apache::geode::client::LogLevel::Info, \ - __VA_ARGS__); \ - } - -#define LOGCONFIG(...) \ - if (::apache::geode::client::Log::enabled( \ - apache::geode::client::LogLevel::Config)) { \ - ::apache::geode::client::Log::log( \ - ::apache::geode::client::LogLevel::Config, __VA_ARGS__); \ - } - -#define LOGFINE(...) \ - if (::apache::geode::client::Log::enabled( \ - apache::geode::client::LogLevel::Fine)) { \ - ::apache::geode::client::Log::log(::apache::geode::client::LogLevel::Fine, \ - __VA_ARGS__); \ - } - -#define LOGFINER(...) \ - if (::apache::geode::client::Log::enabled( \ - apache::geode::client::LogLevel::Finer)) { \ - ::apache::geode::client::Log::log( \ - ::apache::geode::client::LogLevel::Finer, __VA_ARGS__); \ - } - -#define LOGFINEST(...) \ - if (::apache::geode::client::Log::enabled( \ - apache::geode::client::LogLevel::Finest)) { \ - ::apache::geode::client::Log::log( \ - ::apache::geode::client::LogLevel::Finest, __VA_ARGS__); \ - } - -#define LOGDEBUG(...) \ - if (::apache::geode::client::Log::enabled( \ - apache::geode::client::LogLevel::Debug)) { \ - ::apache::geode::client::Log::log( \ - ::apache::geode::client::LogLevel::Debug, __VA_ARGS__); \ - } +#define LOGERROR(...) \ + do { \ + if (::apache::geode::client::Log::enabled( \ + apache::geode::client::LogLevel::Error)) { \ + ::apache::geode::client::Log::log( \ + ::apache::geode::client::LogLevel::Error, __VA_ARGS__); \ + } \ + } while (false) + +#define LOGWARN(...) \ + do { \ + if (::apache::geode::client::Log::enabled( \ + apache::geode::client::LogLevel::Warning)) { \ + ::apache::geode::client::Log::log( \ + ::apache::geode::client::LogLevel::Warning, __VA_ARGS__); \ + } \ + } while (false) + +#define LOGINFO(...) \ + do { \ + if (::apache::geode::client::Log::enabled( \ + apache::geode::client::LogLevel::Info)) { \ + ::apache::geode::client::Log::log( \ + ::apache::geode::client::LogLevel::Info, __VA_ARGS__); \ + } \ + } while (false) + +#define LOGCONFIG(...) \ + do { \ + if (::apache::geode::client::Log::enabled( \ + apache::geode::client::LogLevel::Config)) { \ + ::apache::geode::client::Log::log( \ + ::apache::geode::client::LogLevel::Config, __VA_ARGS__); \ + } \ + } while (false) + +#define LOGFINE(...) \ + do { \ + if (::apache::geode::client::Log::enabled( \ + apache::geode::client::LogLevel::Fine)) { \ + ::apache::geode::client::Log::log( \ + ::apache::geode::client::LogLevel::Fine, __VA_ARGS__); \ + } \ + } while (false) + +#define LOGFINER(...) \ + do { \ + if (::apache::geode::client::Log::enabled( \ + apache::geode::client::LogLevel::Finer)) { \ + ::apache::geode::client::Log::log( \ + ::apache::geode::client::LogLevel::Finer, __VA_ARGS__); \ + } \ + } while (false) + +#define LOGFINEST(...) \ + do { \ + if (::apache::geode::client::Log::enabled( \ + apache::geode::client::LogLevel::Finest)) { \ + ::apache::geode::client::Log::log( \ + ::apache::geode::client::LogLevel::Finest, __VA_ARGS__); \ + } \ + } while (false) + +#define LOGDEBUG(...) \ + do { \ + if (::apache::geode::client::Log::enabled( \ + apache::geode::client::LogLevel::Debug)) { \ + ::apache::geode::client::Log::log( \ + ::apache::geode::client::LogLevel::Debug, __VA_ARGS__); \ + } \ + } while (false) #endif // GEODE_LOG_H_ diff --git a/cppcache/test/LoggingTest.cpp b/cppcache/test/LoggingTest.cpp index cbeb4d348c..237f0f8a76 100644 --- a/cppcache/test/LoggingTest.cpp +++ b/cppcache/test/LoggingTest.cpp @@ -92,9 +92,9 @@ class LoggingTest : public testing::Test { } } - virtual void SetUp() { scrubTestLogFiles(); } + void SetUp() override { scrubTestLogFiles(); } - virtual void TearDown() { scrubTestLogFiles(); } + void TearDown() override { scrubTestLogFiles(); } public: static void writeRolledLogFile(const boost::filesystem::path& logdir, @@ -109,13 +109,12 @@ class LoggingTest : public testing::Test { static int numOfLinesInFile(const char* fname) { char line[2048]; - char* read; int ln_cnt = 0; FILE* fp = fopen(fname, "r"); if (fp == nullptr) { return 0; } - while (!!(read = fgets(line, sizeof line, fp))) { + while (!!(fgets(line, sizeof line, fp))) { ++ln_cnt; }