Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pretty function magic constant overwriting #424

Merged
merged 2 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/g3log/g3log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@
#include <functional>


#if !(defined(__PRETTY_FUNCTION__))
#define __PRETTY_FUNCTION__ __FUNCTION__
#if defined(__GNUC__) // GCC extension compatible
#define G3LOG_PRETTY_FUNCTION __PRETTY_FUNCTION__
#elif defined(_MSC_VER) // Microsoft
#define G3LOG_PRETTY_FUNCTION __FUNCSIG__
#else // Fallback to c99 / c++11
#define G3LOG_PRETTY_FUNCTION __func__
#endif

// thread_local doesn't exist before VS2013
Expand Down Expand Up @@ -138,10 +142,10 @@ namespace g3 {
} // internal
} // g3

#define INTERNAL_LOG_MESSAGE(level) LogCapture(__FILE__, __LINE__, static_cast<const char*>(__PRETTY_FUNCTION__), level)
#define INTERNAL_LOG_MESSAGE(level) LogCapture(__FILE__, __LINE__, static_cast<const char*>(G3LOG_PRETTY_FUNCTION), level)

#define INTERNAL_CONTRACT_MESSAGE(boolean_expression) \
LogCapture(__FILE__, __LINE__, __PRETTY_FUNCTION__, g3::internal::CONTRACT, boolean_expression)
LogCapture(__FILE__, __LINE__, G3LOG_PRETTY_FUNCTION, g3::internal::CONTRACT, boolean_expression)


// LOG(level) is the API for the stream log
Expand Down
6 changes: 3 additions & 3 deletions test_unit/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ TEST(CustomLogLevels, AddANonFatal) {
logger.reset();
std::string file_content = readFileToText(logger.logFile());
std::string expected;
expected += "MY_INFO_LEVEL [test_io.cpp->" + std::string(__FUNCTION__) + ":" + std::to_string(line);
expected += "MY_INFO_LEVEL [test_io.cpp->" + std::string(G3LOG_PRETTY_FUNCTION) + ":" + std::to_string(line);
EXPECT_TRUE(verifyContent(file_content, expected)) << file_content
<< "\n\nExpected: \n" << expected;
}
Expand All @@ -663,7 +663,7 @@ TEST(CustomLogLevels, AddFatal) {

std::string file_content = readFileToText(logger.logFile());
std::string expected;
expected += "DEADLY [test_io.cpp->" + std::string(__FUNCTION__) + ":" + std::to_string(line);
expected += "DEADLY [test_io.cpp->" + std::string(G3LOG_PRETTY_FUNCTION) + ":" + std::to_string(line);
EXPECT_TRUE(verifyContent(file_content, expected)) << file_content
<< "\n\nExpected: \n" << expected;
g_fatal_counter.store(0); // restore
Expand Down Expand Up @@ -734,7 +734,7 @@ TEST(CustomLogLevels, AddANonFatal__DidtAddItToEnabledValue) {
logger.reset();
std::string file_content = readFileToText(logger.logFile());
std::string expected;
expected += "MY_INFO_LEVEL [test_io.cpp->" + std::string(__FUNCTION__) + ":" + std::to_string(line);
expected += "MY_INFO_LEVEL [test_io.cpp->" + std::string(G3LOG_PRETTY_FUNCTION) + ":" + std::to_string(line);
EXPECT_TRUE(verifyContent(file_content, expected)) << file_content
<< "\n\nExpected: \n" << expected;
}
Expand Down