diff options
author | Charles E. Rolke <chug@apache.org> | 2012-06-04 18:24:22 +0000 |
---|---|---|
committer | Charles E. Rolke <chug@apache.org> | 2012-06-04 18:24:22 +0000 |
commit | 870873220ea769ea9ed2ab71ece988ef9995ccbb (patch) | |
tree | ad7969aff93bf0a3bb96b616bfb0d75a6358d0a4 | |
parent | 219e068084f926dc0bd3847818fedc3b87fedae2 (diff) | |
download | qpid-python-870873220ea769ea9ed2ab71ece988ef9995ccbb.tar.gz |
Get rid of macro-based comparisons and do same work with a class.
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/qpid-3902@1346076 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/include/qpid/log/Statement.h | 56 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/log/Statement.cpp | 78 |
2 files changed, 76 insertions, 58 deletions
diff --git a/qpid/cpp/include/qpid/log/Statement.h b/qpid/cpp/include/qpid/log/Statement.h index 94e38d721b..b379afac90 100644 --- a/qpid/cpp/include/qpid/log/Statement.h +++ b/qpid/cpp/include/qpid/log/Statement.h @@ -22,6 +22,7 @@ #include "qpid/Msg.h" #include "qpid/CommonImportExport.h" #include <boost/current_function.hpp> +#include <list> namespace qpid { namespace log { @@ -55,7 +56,7 @@ struct LevelTraits { static const char* name(Level); }; -/** Add formal message categories +/** Formal message categories * https://issues.apache.org/jira/browse/QPID-3902 * * Category Source code directory @@ -98,6 +99,58 @@ struct CategoryTraits { }; +class CategoryFileNameHints { +public: + CategoryFileNameHints(){ + hintList.push_back(std::make_pair("AsynchIo", io)); + hintList.push_back(std::make_pair("TCP", io)); + hintList.push_back(std::make_pair("epoll", io)); + hintList.push_back(std::make_pair("Pollable", io)); + hintList.push_back(std::make_pair("Socket", io)); + + hintList.push_back(std::make_pair("Sasl", security)); + hintList.push_back(std::make_pair("Ssl", security)); + hintList.push_back(std::make_pair("Acl", security)); + hintList.push_back(std::make_pair("acl", security)); + hintList.push_back(std::make_pair("cyrus", security)); + + hintList.push_back(std::make_pair("amqp_", amqp)); + hintList.push_back(std::make_pair("framing", amqp)); + + hintList.push_back(std::make_pair("management", management)); + hintList.push_back(std::make_pair("qmf", management)); + hintList.push_back(std::make_pair("console", management)); + + hintList.push_back(std::make_pair("cluster", ha)); + hintList.push_back(std::make_pair("qpid/ha", ha)); + hintList.push_back(std::make_pair("qpid\\ha", ha)); + hintList.push_back(std::make_pair("replication", ha)); + hintList.push_back(std::make_pair("ClusterSafe", ha)); + + hintList.push_back(std::make_pair("broker", broker)); + hintList.push_back(std::make_pair("SessionState",broker)); + hintList.push_back(std::make_pair("DataDir", broker)); + hintList.push_back(std::make_pair("qpidd", broker)); + + hintList.push_back(std::make_pair("store", store)); + + hintList.push_back(std::make_pair("assert", system)); + hintList.push_back(std::make_pair("Exception", system)); + hintList.push_back(std::make_pair("sys", system)); + hintList.push_back(std::make_pair("SCM", system)); + + hintList.push_back(std::make_pair("tests", test)); + + hintList.push_back(std::make_pair("messaging", messaging)); + hintList.push_back(std::make_pair("types", messaging)); + } + + static Category categoryOf(const char*const fName); + +private: + std::list<std::pair<const char* const, Category> > hintList; +}; + /** POD struct representing a logging statement in source code. */ struct Statement { bool enabled; @@ -109,7 +162,6 @@ struct Statement { QPID_COMMON_EXTERN void log(const std::string& message); QPID_COMMON_EXTERN static void categorize(Statement& s); - QPID_COMMON_EXTERN static Category categoryOf(const char* const function); struct Initializer { QPID_COMMON_EXTERN Initializer(Statement& s); diff --git a/qpid/cpp/src/qpid/log/Statement.cpp b/qpid/cpp/src/qpid/log/Statement.cpp index 2347b2b4cb..56ee581c80 100644 --- a/qpid/cpp/src/qpid/log/Statement.cpp +++ b/qpid/cpp/src/qpid/log/Statement.cpp @@ -50,60 +50,21 @@ std::string quote(const std::string& str) { } } -void Statement::log(const std::string& message) { - Logger::instance().log(*this, quote(message)); -} - -#define test(STR, CAT) \ -if (strstr(fName, (STR)) != 0) {\ - return (::qpid::log::CAT); \ -} -// std::cout << "File: " << fName << " categorized as " << CategoryTraits::name(::qpid::log::CAT) << std::endl; - -Category Statement::categoryOf(const char*const fName) { - test("AsynchIO", io); - test("TCP", io); - test("epoll", io); - test("Pollable", io); - test("Socket", io); - - test("Sasl", security); - test("Ssl", security); - test("Acl", security); - test("acl", security); - test("cyrus", security); - - test("amqp_", amqp); - test("framing", amqp); - - test("management", management); - test("qmf", management); - test("console", management); - - test("cluster", ha); - test("qpid/ha", ha); - test("qpid\\ha", ha); - test("replication", ha); - test("ClusterSafe", ha); - - test("broker", broker); - test("SessionState",broker); - test("DataDir", broker); - test("qpidd", broker); - - test("store", store); - - test("assert", system); - test("Exception", system); - test("sys", system); - test("SCM", system); - - test("tests", test); - - test("messaging", messaging); - test("types", messaging); - - std::cout << "Unspecified file:" << fName << std::endl; +// +// Instance of name hints +// +static CategoryFileNameHints filenameHints; + + +Category CategoryFileNameHints::categoryOf(const char* const fName) { + for (std::list<std::pair<const char* const, Category> >::iterator + it = filenameHints.hintList.begin(); + it != filenameHints.hintList.end(); + ++it) { + if (strstr(fName, (const char* const)it->first) != 0) { + return it->second; + } + } return unspecified; } @@ -111,15 +72,20 @@ Category Statement::categoryOf(const char*const fName) { void Statement::categorize(Statement& s) { // given a statement and it's category // if the category is Unspecified then try to find a - // better category based on the path/file function name. + // better category based on the path and file name. if (s.category == log::unspecified) { - s.category = categoryOf(s.file); + s.category = CategoryFileNameHints::categoryOf(s.file); } else { // already has a category so leave it alone } } +void Statement::log(const std::string& message) { + Logger::instance().log(*this, quote(message)); +} + + Statement::Initializer::Initializer(Statement& s) : statement(s) { // QPID-3891 // From the given BOOST_CURRENT_FUNCTION name extract only the |