You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ch...@apache.org on 2012/03/09 21:02:34 UTC
svn commit: r1299015 - in /qpid/trunk/qpid/cpp/src: qpid/log/Statement.cpp
tests/logging.cpp
Author: chug
Date: Fri Mar 9 20:02:33 2012
New Revision: 1299015
URL: http://svn.apache.org/viewvc?rev=1299015&view=rev
Log:
QPID-3891 C++ Broker --log-function is too chatty.
Print only class-qualified function names and no args.
Modified:
qpid/trunk/qpid/cpp/src/qpid/log/Statement.cpp
qpid/trunk/qpid/cpp/src/tests/logging.cpp
Modified: qpid/trunk/qpid/cpp/src/qpid/log/Statement.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/log/Statement.cpp?rev=1299015&r1=1299014&r2=1299015&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/log/Statement.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/log/Statement.cpp Fri Mar 9 20:02:33 2012
@@ -55,6 +55,50 @@ void Statement::log(const std::string& m
}
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);
}
Modified: qpid/trunk/qpid/cpp/src/tests/logging.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/logging.cpp?rev=1299015&r1=1299014&r2=1299015&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/logging.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/logging.cpp Fri Mar 9 20:02:33 2012
@@ -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");
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org