diff options
author | Charles E. Rolke <chug@apache.org> | 2012-03-09 20:02:33 +0000 |
---|---|---|
committer | Charles E. Rolke <chug@apache.org> | 2012-03-09 20:02:33 +0000 |
commit | 35abed69dfd8972b15be07c3d8863cc0c7b0a1f6 (patch) | |
tree | d5106ae15787839b4d8948c9677557c390d73f53 | |
parent | 6c101f2b7ca22619dc4c0874f918c4654f6bbc89 (diff) | |
download | qpid-python-35abed69dfd8972b15be07c3d8863cc0c7b0a1f6.tar.gz |
QPID-3891 C++ Broker --log-function is too chatty.
Print only class-qualified function names and no args.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1299015 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/src/qpid/log/Statement.cpp | 44 | ||||
-rw-r--r-- | qpid/cpp/src/tests/logging.cpp | 5 |
2 files changed, 48 insertions, 1 deletions
diff --git a/qpid/cpp/src/qpid/log/Statement.cpp b/qpid/cpp/src/qpid/log/Statement.cpp index 7dfdf08703..79f7a28100 100644 --- a/qpid/cpp/src/qpid/log/Statement.cpp +++ b/qpid/cpp/src/qpid/log/Statement.cpp @@ -55,6 +55,50 @@ void Statement::log(const std::string& message) { } Statement::Initializer::Initializer(Statement& s) : statement(s) { + // QPID-3891 + // From the given BOOST_CURRENT_FUNCTION name extract only the + // namespace-qualified-functionName, skipping return and calling args. + // Given: + // <possible return value type> qpid::name::space::Function(args) + // Return: + // "qpid::name::space::Function". + if (s.function != NULL) { + bool foundOParen(false); + const char * opPtr; + for (opPtr = s.function; *opPtr != '\0'; opPtr++) { + if (*opPtr == '(') { + foundOParen = true; + break; + } + } + + if (foundOParen) { + const char * bPtr = opPtr; + for (bPtr = opPtr; bPtr > s.function; bPtr--) { + if (bPtr[-1] == ' ') { + break; + } + } + + size_t nStoreSize = opPtr - bPtr; + if (nStoreSize > 0) { + // Note: the struct into which this name is stored + // is static and is never deleted. + char * nStore = new char[nStoreSize + 1]; + std::copy (bPtr, opPtr, nStore); + nStore[nStoreSize] = '\0'; + + s.function = nStore; + } else { + // Ignore zero length name + } + } else { + // No name found - do nothing + } + } else { + // no function-name pointer to process + } + Logger::instance().add(s); } diff --git a/qpid/cpp/src/tests/logging.cpp b/qpid/cpp/src/tests/logging.cpp index fc55d642c3..dcecf0b54c 100644 --- a/qpid/cpp/src/tests/logging.cpp +++ b/qpid/cpp/src/tests/logging.cpp @@ -29,6 +29,7 @@ #endif #include <boost/test/floating_point_comparison.hpp> +#include <boost/algorithm/string/predicate.hpp> #include <boost/format.hpp> #include "unit_test.h" @@ -176,7 +177,9 @@ QPID_AUTO_TEST_CASE(testLoggerFormat) { l.format(Logger::FUNCTION); QPID_LOG(critical, "foo"); - BOOST_CHECK_EQUAL(string(BOOST_CURRENT_FUNCTION) + ": foo\n", out->last()); + BOOST_CHECK( ends_with( out->last(), ": foo\n")); + string name = out->last().substr(0, out->last().length() - 6); + BOOST_CHECK( contains( string(BOOST_CURRENT_FUNCTION), name)); l.format(Logger::LEVEL); QPID_LOG(critical, "foo"); |