You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2007/05/30 18:14:02 UTC

svn commit: r542855 [1/2] - in /incubator/qpid/trunk/qpid/cpp: docs/man/ src/ src/qpid/ src/qpid/broker/ src/qpid/client/ src/qpid/log/ src/qpid/sys/ src/qpid/sys/apr/ src/qpid/sys/posix/ src/tests/ src/tests/unit/

Author: aconway
Date: Wed May 30 09:13:58 2007
New Revision: 542855

URL: http://svn.apache.org/viewvc?view=rev&rev=542855
Log:
Logging infrastructure: See qpidd --long-help for details.

* src/qpid/log/*: Logging infrastructure, QPID_LOG macro.
* src/*: changed output to cout/cerr to logging.
* src/qpidd.cpp: logging options.
* src/tests/Makefile.am: fixed issues with valgrind
* src/tests/kill|start_broker: use broker daemon options.
* src/tests/run_test: run tests in valgrind. Disabled till leaks in
  client_test are fixed.
* src/test/unit/logging.cpp: Logging unit test using boost test framework.
  Eventually we should move all unit tests to boost & drop CppUnit.
* src/test/unit/test_tools.h: useful extensions to boost framework:
  Regular expression check, ostream << for vectors.

Added:
    incubator/qpid/trunk/qpid/cpp/src/qpid/log/
    incubator/qpid/trunk/qpid/cpp/src/qpid/log/Logger.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/log/Logger.h   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/log/Options.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/log/Options.h   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/log/Selector.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/log/Selector.h   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/log/Statement.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/log/Statement.h   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/memory.h   (with props)
    incubator/qpid/trunk/qpid/cpp/src/tests/.valgrind.supp-default
      - copied unchanged from r542623, incubator/qpid/trunk/qpid/cpp/src/tests/.valgrind.supp
    incubator/qpid/trunk/qpid/cpp/src/tests/run_test   (with props)
    incubator/qpid/trunk/qpid/cpp/src/tests/unit/   (with props)
    incubator/qpid/trunk/qpid/cpp/src/tests/unit/logging.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/src/tests/unit/test_tools.h   (with props)
Removed:
    incubator/qpid/trunk/qpid/cpp/src/tests/.valgrind.supp
Modified:
    incubator/qpid/trunk/qpid/cpp/docs/man/Makefile.am
    incubator/qpid/trunk/qpid/cpp/src/Makefile.am
    incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/QpidError.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/AutoDelete.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerMessage.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerQueue.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Connection.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DirectExchange.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/NullMessageStore.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/TxAck.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/TxPublish.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/BasicMessageChannel.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/ClientChannel.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/ClientConnection.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/MessageMessageChannel.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRAcceptor.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRBase.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRSocket.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFProcessor.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFSessionContext.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFSessionContext.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Module.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Thread.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannel.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelConnection.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelThreads.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Module.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Thread.h
    incubator/qpid/trunk/qpid/cpp/src/qpidd.cpp
    incubator/qpid/trunk/qpid/cpp/src/tests/   (props changed)
    incubator/qpid/trunk/qpid/cpp/src/tests/AccumulatedAckTest.cpp
    incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am
    incubator/qpid/trunk/qpid/cpp/src/tests/kill_broker
    incubator/qpid/trunk/qpid/cpp/src/tests/start_broker

Modified: incubator/qpid/trunk/qpid/cpp/docs/man/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/docs/man/Makefile.am?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/docs/man/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/docs/man/Makefile.am Wed May 30 09:13:58 2007
@@ -15,6 +15,6 @@
 .x.1:
 	@rm -f $@
 	@echo "Updating man page $@"
-	$(HELP2MAN) --no-info --include=$(srcdir)/$*.x --output=$@-t ../../src/$*
+	$(HELP2MAN) --no-info --include=$(srcdir)/$*.x --output=$@-t -h --long-help ../../src/$*
 	@chmod a-w $@-t
 	@mv $@-t $@

Modified: incubator/qpid/trunk/qpid/cpp/src/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/Makefile.am?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/Makefile.am Wed May 30 09:13:58 2007
@@ -21,7 +21,7 @@
 
 AM_CXXFLAGS = $(WARNING_CFLAGS) $(APR_CXXFLAGS)
 AM_LDFLAGS = -version-info $(LIBTOOL_VERSION_INFO_ARG)
-INCLUDES = -I$(builddir)/gen -I$(srcdir)/gen
+INCLUDES = -Igen -I$(srcdir)/gen
 
 qpidd_LDADD =					\
   libqpidbroker.la				\
@@ -103,11 +103,22 @@
 
 lib_LTLIBRARIES = libqpidcommon.la libqpidbroker.la libqpidclient.la
 
+# The logger library uses boost::date_time to format time.
+# We have to disable the unused parameters warning to get around
+# unused parameters in boost::date_time headers. So we build it
+# in a convenience library to link into libqpid_common.
+# 
+noinst_LTLIBRARIES=libLogger.la
+libLogger_la_SOURCES=qpid/log/Logger.cpp qpid/log/Logger.h  
+libLogger_la_CXXFLAGS=$(AM_CXXFLAGS) -Wno-unused-parameter
+
 libqpidcommon_la_LIBADD = \
   -lboost_program_options \
+  libLogger.la \
   $(APR_LIBS) \
   $(LIB_DLOPEN) \
   $(LIB_CLOCK_GETTIME)
+
 libqpidcommon_la_SOURCES = \
   $(platform_src) \
   qpid/framing/AMQBody.cpp \
@@ -143,8 +154,14 @@
   qpid/QpidError.cpp \
   qpid/sys/Runnable.cpp \
   qpid/sys/ProducerConsumer.cpp \
-  qpid/CommonOptions.cpp
-
+  qpid/CommonOptions.cpp \
+  qpid/log/Options.cpp \
+  qpid/log/Options.h \
+  qpid/log/Selector.cpp \
+  qpid/log/Selector.h \
+  qpid/log/Statement.cpp \
+  qpid/log/Statement.h \
+  qpid/memory.h
 
 libqpidbroker_la_LIBADD = libqpidcommon.la -ldaemon -lboost_filesystem
 libqpidbroker_la_SOURCES = \

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.cpp Wed May 30 09:13:58 2007
@@ -17,6 +17,7 @@
  */
 
 #include "CommonOptions.h"
+#include "qpid/Exception.h"
 #include <fstream>
 #include <algorithm>
 #include <iostream>
@@ -39,6 +40,10 @@
     return std::string();
 } 
 
+std::string prettyArg(const std::string& name, const std::string& value) {
+    return value.empty() ? name : name+" (="+value+")";
+}
+
 } // namespace program_options
 
 const int CommonOptions::DEFAULT_PORT=5672;
@@ -69,13 +74,19 @@
         throw po::error(std::string("parsing environment variables: ")
                           + e.what());
     }
-    po::notify(vm);         // So we can use the value of config.
-    try {
-        std::ifstream conf(configFile.c_str());
-        po::store(po::parse_config_file(conf, desc), vm);
-    }
-    catch (const po::error& e) {
-        throw po::error(std::string("parsing config file: ")+ e.what());
+    po::notify(vm);         // configFile may be updated from arg/env options.
+    if (!configFile.empty()) {
+        try {
+            using namespace std;
+            ifstream conf(configFile.c_str());
+            if (conf.good()) {
+                conf.exceptions(ifstream::failbit|ifstream::badbit);
+                po::store(po::parse_config_file(conf, desc), vm);
+            }
+        }
+        catch (const std::exception& e) {
+            throw Exception(std::string("error parsing config file: ")+ e.what());
+        }
     }
     po::notify(vm);
 }

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.h?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/CommonOptions.h Wed May 30 09:13:58 2007
@@ -24,6 +24,9 @@
 
 #include <boost/program_options.hpp>
 #include <boost/format.hpp>
+#include <sstream>
+#include <iterator>
+#include <algorithm>
 
 namespace qpid { 
 
@@ -43,9 +46,12 @@
     std::string argName;
 };
 
+///@internal
+std::string prettyArg(const std::string& name, const std::string& value);
+
 /**
  * Like boost::program_options::value() with more convenient signature
- * for updating a value by reference and nicer help formatting.
+ * for updating a value by reference and prettier help formatting.
  * 
  *@param value displayed as default in help, updated from options.
  * Must support ostream << operator.
@@ -54,12 +60,20 @@
  *@see CommonOptions.cpp for example of use.
  */ 
 template<class T>
-value_semantic* optValue(T& value, const char* arg) {
-    std::string val(boost::lexical_cast<std::string>(value));
-    std::string argName(
-        val.empty() ? std::string(arg) :
-        (boost::format("%s (=%s) ") % arg % val).str());
-    return new OptionValue<T>(value, argName);
+value_semantic* optValue(T& value, const char* name) {
+    std::string valstr(boost::lexical_cast<std::string>(value));
+    return new OptionValue<T>(value, prettyArg(name, valstr));
+}
+
+template <class T>
+value_semantic* optValue(std::vector<T>& value, const char* name) {
+    using namespace std;
+    ostringstream os;
+    copy(value.begin(), value.end(), ostream_iterator<T>(os, " "));
+    string val=os.str();
+    if (!val.empty())
+        val.erase(val.end()-1); // Remove trailing " "
+    return (new OptionValue<vector<T> >(value, prettyArg(name, val)));
 }
 
 /** Environment-to-option name mapping.

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/QpidError.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/QpidError.h?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/QpidError.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/QpidError.h Wed May 30 09:13:58 2007
@@ -69,6 +69,8 @@
 
 #define THROW_QPID_ERROR(CODE, MESSAGE) throw QPID_ERROR(CODE,MESSAGE)
 
+#define THROW_QPID_ERRNO_IF(cond) if (cond) QPID_ERROR(INTERNAL, strError(errno));
+
 const int PROTOCOL_ERROR = 10000;
 const int APR_ERROR = 20000;
 const int FRAMING_ERROR = 30000;

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/AutoDelete.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/AutoDelete.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/AutoDelete.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/AutoDelete.cpp Wed May 30 09:13:58 2007
@@ -19,6 +19,7 @@
  *
  */
 #include "AutoDelete.h"
+#include "qpid/log/Statement.h"
 #include "qpid/sys/Time.h"
 
 using namespace qpid::broker;
@@ -51,7 +52,7 @@
         }else if(q->canAutoDelete()){
             std::string name(q->getName());
             registry->destroy(name);
-            std::cout << "INFO: Auto-deleted queue named " << name << std::endl;
+            QPID_LOG(info, "Auto-deleted queue named " << name);
         }else{
             add(q);
             if(!seen) seen = q;

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerMessage.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerMessage.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerMessage.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerMessage.cpp Wed May 30 09:13:58 2007
@@ -26,6 +26,7 @@
 #include "InMemoryContent.h"
 #include "LazyLoadedContent.h"
 #include "MessageStore.h"
+#include "qpid/log/Statement.h"
 #include "qpid/framing/BasicDeliverBody.h"
 #include "qpid/framing/BasicGetOkBody.h"
 #include "qpid/framing/AMQContentBody.h"
@@ -76,8 +77,6 @@
                            const string& consumerTag, uint64_t deliveryTag, 
                            uint32_t framesize)
 {
-    // CCT -- TODO - Update code generator to take pointer/ not
-    // instance to avoid extra contruction
     channel.send(
     	new BasicDeliverBody(
             channel.getVersion(), consumerTag, deliveryTag,
@@ -91,8 +90,6 @@
                              uint64_t deliveryTag, 
                              uint32_t framesize)
 {
-    // CCT -- TODO - Update code generator to take pointer/ not
-    // instance to avoid extra contruction
     context.channel->send(
         new BasicGetOkBody(
             context.channel->getVersion(),
@@ -155,7 +152,7 @@
 {    
     uint64_t expected = expectedContentSize();
     if (expected != buffer.available()) {
-        std::cout << "WARN: Expected " << expectedContentSize() << " bytes, got " << buffer.available() << std::endl;
+        QPID_LOG(error, "Expected " << expectedContentSize() << " bytes, got " << buffer.available());
         throw Exception("Cannot decode content, buffer not large enough.");
     }
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerQueue.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerQueue.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerQueue.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerQueue.cpp Wed May 30 09:13:58 2007
@@ -21,6 +21,7 @@
 
 #include <boost/format.hpp>
 
+#include "qpid/log/Statement.h"
 #include "BrokerQueue.h"
 #include "MessageStore.h"
 #include "qpid/sys/Monitor.h"
@@ -78,7 +79,7 @@
         return false;
     }else if(exclusive){
         if(!exclusive->deliver(msg)){
-            std::cout << "WARNING: Dropping undeliverable message from queue with exclusive consumer." << std::endl;
+            QPID_LOG(warning, "Dropping undeliverable message from queue with exclusive consumer.");
         }
         return true;
     }else{

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Connection.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Connection.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Connection.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Connection.cpp Wed May 30 09:13:58 2007
@@ -18,6 +18,7 @@
  * under the License.
  *
  */
+#include "qpid/log/Statement.h"
 #include <iostream>
 #include <assert.h>
 
@@ -99,8 +100,8 @@
             exclusiveQueues.erase(exclusiveQueues.begin());
         }
     } catch(std::exception& e) {
-        std::cout << "Caught unhandled exception while closing session: " <<
-            e.what() << std::endl;
+        QPID_LOG(error, " Unhandled exception while closing session: " <<
+                 e.what());
         assert(0);
     }
 }

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DirectExchange.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DirectExchange.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DirectExchange.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/DirectExchange.cpp Wed May 30 09:13:58 2007
@@ -18,6 +18,7 @@
  * under the License.
  *
  */
+#include "qpid/log/Statement.h"
 #include "DirectExchange.h"
 #include <iostream>
 
@@ -64,7 +65,7 @@
         msg.deliverTo(*i);
     }
     if(!count){
-        std::cout << "WARNING: DirectExchange " << getName() << " could not route message with key " << routingKey << std::endl;
+        QPID_LOG(warning, "DirectExchange " << getName() << " could not route message with key " << routingKey);
     }
 }
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/NullMessageStore.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/NullMessageStore.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/NullMessageStore.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/NullMessageStore.cpp Wed May 30 09:13:58 2007
@@ -20,8 +20,8 @@
  */
 
 #include "NullMessageStore.h"
-
 #include "RecoveryManager.h"
+#include "qpid/log/Statement.h"
 
 #include <iostream>
 
@@ -31,60 +31,60 @@
 
 void NullMessageStore::create(const PersistableQueue& queue)
 {
-    if (warn) std::cout << "WARNING: Can't create durable queue '" << queue.getName() << "'. Persistence not enabled." << std::endl;
+    QPID_LOG(warning, "Can't create durable queue '" << queue.getName() << "'. Persistence not enabled.");
 }
 
 void NullMessageStore::destroy(const PersistableQueue& queue)
 {
-    if (warn) std::cout << "WARNING: Can't destroy durable queue '" << queue.getName() << "'. Persistence not enabled." << std::endl;
+    QPID_LOG(warning, "Can't destroy durable queue '" << queue.getName() << "'. Persistence not enabled.");
 }
 
 void NullMessageStore::create(const PersistableExchange& exchange)
 {
-    if (warn) std::cout << "WARNING: Can't create durable exchange '" << exchange.getName() << "'. Persistence not enabled." << std::endl;
+    QPID_LOG(warning, "Can't create durable exchange '"
+             << exchange.getName() << "'. Persistence not enabled.");
 }
 
-void NullMessageStore::destroy(const PersistableExchange& exchange)
-{
-    if (warn) std::cout << "WARNING: Can't destroy durable exchange '" << exchange.getName() << "'. Persistence not enabled." << std::endl;
-}
+void NullMessageStore::destroy(const PersistableExchange& )
+{}
+
 void NullMessageStore::bind(const PersistableExchange&, const PersistableQueue&, const std::string&, const framing::FieldTable&){}
 
 void NullMessageStore::unbind(const PersistableExchange&, const PersistableQueue&, const std::string&, const framing::FieldTable&){}
 
 void NullMessageStore::recover(RecoveryManager&)
 {
-    if (warn) std::cout << "WARNING: Persistence not enabled, no recovery of queues or messages." << std::endl;
+    QPID_LOG(warning, "Persistence not enabled, no recovery of queues or messages.");
 }
 
 void NullMessageStore::stage(PersistableMessage&)
 {
-    if (warn) std::cout << "WARNING: Can't stage message. Persistence not enabled." << std::endl;
+    QPID_LOG(warning, "Can't stage message. Persistence not enabled.");
 }
 
 void NullMessageStore::destroy(PersistableMessage&)
 {
-    if (warn) std::cout << "WARNING: No need to destroy staged message. Persistence not enabled." << std::endl;
+    QPID_LOG(warning, "No need to destroy staged message. Persistence not enabled.");
 }
 
 void NullMessageStore::appendContent(PersistableMessage&, const string&)
 {
-    if (warn) std::cout << "WARNING: Can't append content. Persistence not enabled." << std::endl;
+    QPID_LOG(warning, "Can't load content. Persistence not enabled.");
 }
 
 void NullMessageStore::loadContent(PersistableMessage&, string&, uint64_t, uint32_t)
 {
-    if (warn) std::cout << "WARNING: Can't load content. Persistence not enabled." << std::endl;
+    QPID_LOG(warning, "WARNING: Can't load content. Persistence not enabled.");
 }
 
 void NullMessageStore::enqueue(TransactionContext*, PersistableMessage&, const PersistableQueue& queue)
 {
-    if (warn) std::cout << "WARNING: Can't enqueue message onto '" << queue.getName() << "'. Persistence not enabled." << std::endl;
+    QPID_LOG(warning, "Can't enqueue message onto '" << queue.getName() << "'. Persistence not enabled.");
 }
 
 void NullMessageStore::dequeue(TransactionContext*, PersistableMessage&, const PersistableQueue& queue)
 {
-    if (warn) std::cout << "WARNING: Can't dequeue message from '" << queue.getName() << "'. Persistence not enabled." << std::endl;
+    QPID_LOG(warning, "Can't dequeue message from '" << queue.getName() << "'. Persistence not enabled.");
 }
 
 std::auto_ptr<TransactionContext> NullMessageStore::begin()

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/TxAck.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/TxAck.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/TxAck.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/TxAck.cpp Wed May 30 09:13:58 2007
@@ -19,6 +19,7 @@
  *
  */
 #include "TxAck.h"
+#include "qpid/log/Statement.h"
 
 using std::bind1st;
 using std::bind2nd;
@@ -40,7 +41,7 @@
         }
         return true;
     }catch(...){
-        std::cout << "TxAck::prepare() - Failed to prepare" << std::endl;
+        QPID_LOG(error, "Failed to prepare");
         return false;
     }
 }

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/TxPublish.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/TxPublish.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/TxPublish.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/TxPublish.cpp Wed May 30 09:13:58 2007
@@ -18,6 +18,7 @@
  * under the License.
  *
  */
+#include "qpid/log/Statement.h"
 #include "TxPublish.h"
 
 using namespace qpid::broker;
@@ -29,7 +30,7 @@
         for_each(queues.begin(), queues.end(), Prepare(ctxt, msg));
         return true;
     }catch(...){
-        std::cout << "TxPublish::prepare() - Failed to prepare" << std::endl;
+        QPID_LOG(error, "Failed to prepare");
         return false;
     }
 }

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/BasicMessageChannel.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/BasicMessageChannel.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/BasicMessageChannel.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/BasicMessageChannel.cpp Wed May 30 09:13:58 2007
@@ -15,6 +15,7 @@
  * limitations under the License.
  *
  */
+#include "qpid/log/Statement.h"
 #include "BasicMessageChannel.h"
 #include "qpid/framing/AMQMethodBody.h"
 #include "ClientChannel.h"
@@ -320,12 +321,11 @@
             }
         }
         catch (const ShutdownException&) {
-            /* Orderly shutdown */
+            // Orderly shutdown.
         }
         catch (const Exception& e) {
             // FIXME aconway 2007-02-20: Report exception to user.
-            cout << "client::BasicMessageChannel::run() terminated by: "
-                 << e.toString() << endl;
+            QPID_LOG(error,  e.what());
         }
     }
 }

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/ClientChannel.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/ClientChannel.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/ClientChannel.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/ClientChannel.cpp Wed May 30 09:13:58 2007
@@ -18,6 +18,7 @@
  * under the License.
  *
  */
+#include "qpid/log/Statement.h"
 #include <iostream>
 #include "ClientChannel.h"
 #include "qpid/sys/Monitor.h"
@@ -112,8 +113,7 @@
         //ignore for now
         ConnectionRedirectBody::shared_ptr redirect(
             shared_polymorphic_downcast<ConnectionRedirectBody>(openResponse));
-        cout << "Received redirection to " << redirect->getHost()
-             << endl;
+        QPID_LOG(error, "Ignoring redirect to " << redirect->getHost());
     } else {
         THROW_QPID_ERROR(PROTOCOL_ERROR, "Bad response to Connection.open");
     }
@@ -189,9 +189,8 @@
 void Channel::handleMethodInContext(
     AMQMethodBody::shared_ptr method, const MethodContext&)
 {
-    // TODO aconway 2007-03-23: Special case for consume OK as it
-    // is both an expected response and needs handling in this thread.
-    // Need to review & reationalize the client-side processing model.
+    // Special case for consume OK as it is both an expected response
+    // and needs handling in this thread.
     if (method->isA<BasicConsumeOkBody>()) {
         messaging->handle(method);
         responses.signalResponse(method);

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/ClientConnection.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/ClientConnection.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/ClientConnection.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/ClientConnection.cpp Wed May 30 09:13:58 2007
@@ -25,6 +25,7 @@
 #include "Connection.h"
 #include "ClientChannel.h"
 #include "ClientMessage.h"
+#include "qpid/log/Statement.h"
 #include "qpid/QpidError.h"
 #include <iostream>
 #include <sstream>
@@ -78,7 +79,7 @@
     //this indicates that the socket to the server has closed we do
     //not want to send a close request (or any other requests)
     if(markClosed()) {
-        std::cout << "Connection to peer closed!" << std::endl;
+        QPID_LOG(info, "Connection to peer closed!");
         closeChannels();
     }
 }
@@ -88,11 +89,13 @@
 )
 {
     if(markClosed()) {
-        // TODO aconway 2007-01-29: Exception handling - could end up
-        // partly closed with threads left unjoined.
-        channel0.sendAndReceive<ConnectionCloseOkBody>(
-            make_shared_ptr(new ConnectionCloseBody(
-                getVersion(), code, msg, classId, methodId)));
+        try {
+            channel0.sendAndReceive<ConnectionCloseOkBody>(
+                make_shared_ptr(new ConnectionCloseBody(
+                                    getVersion(), code, msg, classId, methodId)));
+        } catch (const std::exception& e) {
+            QPID_LOG(error, "Exception closing channel: " << e.what());
+        }
         closeChannels();
         connector->close();
     }

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp Wed May 30 09:13:58 2007
@@ -19,6 +19,7 @@
  *
  */
 #include <iostream>
+#include "qpid/log/Statement.h"
 #include "qpid/QpidError.h"
 #include "qpid/sys/Time.h"
 #include "Connector.h"
@@ -82,7 +83,7 @@
     std::auto_ptr<AMQFrame> frame(f);
     AMQBody::shared_ptr body = frame->getBody();
     writeBlock(frame.get());
-    if(debug) std::cout << "SENT: " << *frame << std::endl; 
+    QPID_LOG(trace, "SENT: " << *frame);
 }
 
 void Connector::writeBlock(AMQDataBlock* data){
@@ -182,7 +183,7 @@
 		
 		AMQFrame frame(version);
 		while(frame.decode(inbuf)){
-                    if(debug) std::cout << "RECV: " << frame << std::endl; 
+                    QPID_LOG(trace, "RECV: " << frame);
 		    input->received(&frame);
 		}
                 //need to compact buffer to preserve any 'extra' data
@@ -190,7 +191,7 @@
 	    }
 	}
     } catch (const std::exception& e) {
-	std::cout << e.what() << std::endl;
+        QPID_LOG(error, e.what());
         handleClosed();
     }
 }

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/MessageMessageChannel.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/MessageMessageChannel.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/MessageMessageChannel.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/MessageMessageChannel.cpp Wed May 30 09:13:58 2007
@@ -381,7 +381,7 @@
 //                 }
 //                 if(handler == 0) {
 //                     // TODO aconway 2007-02-20: proper logging.
-//                     cout << "Message returned: " << msg.getData() << endl;
+//                     QPID_LOG(warn, "No handler for message.");
 //                 }
 //                 else 
 //                     handler->returned(msg);
@@ -407,9 +407,7 @@
 //             /* Orderly shutdown */
 //         }
 //         catch (const Exception& e) {
-//             // FIXME aconway 2007-02-20: Report exception to user.
-//             cout << "client::Message::run() terminated by: " << e.toString()
-//                  << "(" << typeid(e).name() << ")" << endl;
+//             QPID_LOG(error, e.what());
 //         }
 //     }
 }

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Logger.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/log/Logger.cpp?view=auto&rev=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/log/Logger.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/log/Logger.cpp Wed May 30 09:13:58 2007
@@ -0,0 +1,204 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "Logger.h"
+#include "Options.h"
+#include "qpid/memory.h"
+#include "qpid/sys/Thread.h"
+#include <boost/pool/detail/singleton.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/scoped_ptr.hpp>
+#include <algorithm>
+#include <sstream>
+#include <fstream>
+#include <iomanip>
+#include <syslog.h>
+
+
+namespace qpid {
+namespace log {
+
+using namespace std;
+
+typedef sys::Mutex::ScopedLock ScopedLock;
+
+inline void Logger::enable_unlocked(Statement* s) {
+    s->enabled=selector.isEnabled(s->level, s->file);
+}
+
+struct OstreamOutput : public Logger::Output {
+    OstreamOutput(std::ostream& o) : out(&o) {}
+
+    OstreamOutput(const string& file)
+        : out(new ofstream(file.c_str())), mine(out)
+    {
+        if (!out->good())
+            throw Exception("Can't open log file: "+file);
+    }
+
+    void log(const Statement&, const std::string& m) {
+        *out << m << flush;
+    }
+    
+    ostream* out;
+    boost::scoped_ptr<ostream> mine;
+};
+
+struct SyslogOutput : public Logger::Output {
+    SyslogOutput(const std::string& name, int facility_=LOG_USER)
+        : progName(name), facility(facility_)
+    {
+        ::openlog(name.c_str(), LOG_PID, facility);
+    }
+
+    ~SyslogOutput() {
+        ::closelog();
+    }
+    
+    void log(const Statement& s, const std::string& m)
+    {
+        syslog(LevelTraits::priority(s.level), "%s", m.c_str());
+    }
+    
+    std::string progName;
+    int facility;
+};
+
+Logger& Logger::instance() {
+    return boost::details::pool::singleton_default<Logger>::instance();
+}
+
+Logger::Logger() : flags(0) {}
+Logger::~Logger() {}
+
+void Logger::select(const Selector& s) {
+    ScopedLock l(lock);
+    selector=s;
+    std::for_each(statements.begin(), statements.end(),
+                  boost::bind(&Logger::enable_unlocked, this, _1));
+}
+
+Logger::Output::Output()  {}
+Logger::Output::~Output() {}
+
+void Logger::log(const Statement& s, const std::string& msg) {
+    // Format the message outside the lock.
+    std::ostringstream os;
+    if (flags&TIME) 
+        os << boost::posix_time::second_clock::local_time() << " ";
+    if (flags&LEVEL)
+        os << LevelTraits::name(s.level) << " ";
+    if (flags&THREAD)
+        os << "[" << hex << qpid::sys::Thread::logId() << "] ";
+    if (flags&FILE)
+        os << s.file << ":";
+    if (flags&LINE)
+        os << dec << s.line << ":";
+    if (flags&FUNCTION)
+        os << s.function << ":";
+    if (flags & (FILE|LINE|FUNCTION))
+        os << " ";
+    os << msg << endl;
+    std::string formatted=os.str();
+    
+    {
+        ScopedLock l(lock);
+        std::for_each(outputs.begin(), outputs.end(),
+                      boost::bind(&Output::log, _1, s, formatted));
+    }
+}
+
+void Logger::output(std::auto_ptr<Output> out) {
+    ScopedLock l(lock);
+    outputs.push_back(out.release());
+}
+
+void Logger::output(std::ostream& out) {
+    output(make_auto_ptr<Output>(new OstreamOutput(out)));
+}
+
+void Logger::syslog(const std::string& progName) {
+    output(make_auto_ptr<Output>(new SyslogOutput(progName)));
+}
+
+void Logger::output(const std::string& name) {
+    if (name=="stderr")
+        output(clog);
+    else if (name=="stdout")
+        output(cout);
+    else if (name=="syslog")
+        syslog(syslogName);
+    else 
+        output(make_auto_ptr<Output>(new OstreamOutput(name)));
+}
+
+void Logger::clear() {
+    select(Selector());         // locked
+    format(0);                  // locked
+    ScopedLock l(lock);
+    outputs.clear();
+}
+
+void Logger::format(int formatFlags) {
+    ScopedLock l(lock);
+    flags=formatFlags;
+}
+
+static int bitIf(bool test, int bit) {
+    return test ? bit : 0;
+}
+
+int Logger::format(const Options& opts) {
+    int flags=
+        bitIf(opts.level, LEVEL) |
+        bitIf(opts.time, TIME) |
+        bitIf(opts.source, (FILE|LINE)) |
+        bitIf(opts.function, FUNCTION) |
+        bitIf(opts.thread, THREAD);
+    format(flags);
+    return flags;
+}
+
+void Logger::add(Statement& s) {
+    ScopedLock l(lock);
+    enable_unlocked(&s);
+    statements.insert(&s);
+}
+
+void Logger::remove(Statement& s) {
+    ScopedLock l(lock);
+    s.enabled = false;
+    statements.erase(&s);
+}
+
+void Logger::configure(const Options& o, const std::string& prog)
+{
+    {
+        ScopedLock l(lock);
+        syslogName=prog;
+    }
+    format(o); 
+    select(Selector(o));
+    void (Logger::* outputFn)(const std::string&) = &Logger::output;
+    for_each(o.outputs.begin(), o.outputs.end(),
+             boost::bind(outputFn, this, _1));
+}
+
+}} // namespace qpid::log

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Logger.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Logger.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Logger.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/log/Logger.h?view=auto&rev=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/log/Logger.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/log/Logger.h Wed May 30 09:13:58 2007
@@ -0,0 +1,116 @@
+#ifndef LOGGER_H
+#define LOGGER_H
+
+/*
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "Selector.h"
+#include "qpid/sys/Mutex.h"
+#include <boost/ptr_container/ptr_vector.hpp>
+#include <boost/noncopyable.hpp>
+#include <set>
+
+namespace qpid {
+namespace log {
+
+class Options;
+
+/**
+ * Central logging agent.
+ *
+ * Thread safe, singleton.
+ */
+class Logger : private boost::noncopyable {
+  public:
+    /** Flags indicating what to include in the log output */
+    enum FormatFlag { FILE=1, LINE=2, FUNCTION=4, LEVEL=8, TIME=16, THREAD=32};
+
+    /** Interface for log output destination.
+     * 
+     * Implementations must be thread safe.
+     */
+    class Output {
+      public:
+        Output();
+        virtual ~Output();
+        /** Receives the statemnt of origin and formatted message to log. */
+        virtual void log(const Statement&, const std::string&) =0;
+    };
+    
+    static Logger& instance();
+
+    Logger();
+    ~Logger();
+    
+    /** Select the messages to be logged. */
+    void select(const Selector& s);
+
+    /** Set the formatting flags, bitwise OR of FormatFlag values. */
+    void format(int formatFlags);
+
+    /** Set format flags from options object.
+     *@returns computed flags.
+     */
+    int format(const Options&);
+
+    /** Configure logger from Options */
+    void configure(const Options& o, const std::string& progname);
+
+    /** Add a statement. */
+    void add(Statement& s);
+
+    /** Remove a statement */
+    void remove(Statement& s);
+    
+    /** Log a message. */
+    void log(const Statement&, const std::string&);
+
+    /** Add an ostream to outputs.
+     * 
+     * The ostream must not be destroyed while the Logger might
+     * still be using it. This is the case for std streams cout,
+     * cerr, clog. 
+     */
+    void output(std::ostream&);
+
+    /** Add syslog to outputs. */
+    void syslog(const std::string& programName);
+
+    /** Add an output.
+     *@param name a file name or one of the special tokens:
+     *stdout, stderr, syslog.
+     */
+    void output(const std::string& name);
+
+    /** Add an output destination for messages */
+    void output(std::auto_ptr<Output> out); 
+
+    /** Reset the logger to it's original state */
+    void clear();
+
+  private:
+    typedef boost::ptr_vector<Output> Outputs;
+    typedef std::set<Statement*> Statements;
+
+    sys::Mutex lock;
+    inline void enable_unlocked(Statement* s);
+
+    std::string syslogName;
+    Statements statements;
+    Outputs outputs;
+    Selector selector;
+    int flags;
+};
+
+}} // namespace qpid::log
+
+
+#endif  /*!LOGGER_H*/

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Logger.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Logger.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Options.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/log/Options.cpp?view=auto&rev=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/log/Options.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/log/Options.cpp Wed May 30 09:13:58 2007
@@ -0,0 +1,69 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "Options.h"
+#include "Statement.h"
+#include "qpid/CommonOptions.h"
+
+namespace qpid {
+namespace log {
+
+using namespace std;
+
+Options::Options() :
+    time(true), level(true), thread(false), source(false), function(false)
+{
+    outputs.push_back("stderr");
+    selectors.push_back("error+");
+}
+
+void Options::addTo(po::options_description& desc) {
+    using namespace po;
+    ostringstream levels;
+    levels << LevelTraits::name(Level(0));
+    for (int i = 1; i < LevelTraits::COUNT; ++i)
+        levels << " " << LevelTraits::name(Level(i));
+    desc.add_options()
+        ("log.enable", optValue(selectors, "RULE"),
+         "You can specify this option mutliple times.\n"
+         "RULE is of the form 'LEVEL[+][:COMPONENT]'"
+         "Levels are: trace, debug, info, notice, warning, error, critical."
+         "For example:\n"
+         "\t'--log.enable warning+' "
+         "enables all warning, error and critical messages.\n"
+         "\t'--log.enable debug:framing' "
+         "enables debug messages from the framing component.")
+        ("log.output", optValue(outputs, "FILE"),
+         "File to receive log output, or one of these special values: "
+         "'stderr', 'stdout', 'syslog'.")
+        ("log.time", optValue(time, "yes|no"),
+         "Include time in log messages")
+        ("log.level", optValue(level,"yes|no"),
+         "Include severity level in log messages")
+        ("log.source", optValue(source,"yes|no"),
+         "Include source file:line in log messages")
+        ("log.thread", optValue(thread,"yes|no"),
+         "Include thread ID in log messages")
+        ("log.function", optValue(function,"yes|no"),
+         "Include function signature in log messages");
+    
+}        
+        
+
+
+}} // namespace qpid::log

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Options.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Options.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Options.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/log/Options.h?view=auto&rev=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/log/Options.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/log/Options.h Wed May 30 09:13:58 2007
@@ -0,0 +1,42 @@
+#ifndef OPTIONS_H
+#define OPTIONS_H
+
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include "qpid/CommonOptions.h"
+
+
+namespace qpid {
+namespace log {
+
+/** Logging options for config parser. */
+struct Options {
+    Options();
+    void addTo(po::options_description&);
+
+    std::vector<std::string> selectors;
+    std::vector<std::string> outputs;
+    bool time, level, thread, source, function;
+};
+
+
+}} // namespace qpid::log
+
+
+
+#endif  /*!OPTIONS_H*/

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Options.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Options.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Selector.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/log/Selector.cpp?view=auto&rev=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/log/Selector.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/log/Selector.cpp Wed May 30 09:13:58 2007
@@ -0,0 +1,66 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "Selector.h"
+#include "Options.h"
+#include <boost/bind.hpp>
+#include <algorithm>
+
+namespace qpid {
+namespace log {
+
+using namespace std;
+
+void Selector::enable(const string& enableStr) {
+    string level, pattern;
+    size_t c=enableStr.find(':');
+    if (c==string::npos) {
+        level=enableStr;
+    }
+    else {
+        level=enableStr.substr(0,c);
+        pattern=enableStr.substr(c+1);
+    }
+    if (!level.empty() && level[level.size()-1]=='+') {
+        for (int i =  LevelTraits::level(level.substr(0,level.size()-1));
+             i < LevelTraits::COUNT;
+             ++i)
+            enable(Level(i), pattern);
+    }
+    else {
+        enable(LevelTraits::level(level), pattern);
+    }
+}
+
+Selector::Selector(const Options& opt){
+    for_each(opt.selectors.begin(), opt.selectors.end(),
+             boost::bind(&Selector::enable, this, _1));
+}
+
+bool Selector::isEnabled(Level level, const std::string& file) {
+    for (std::vector<std::string>::iterator i=substrings[level].begin();
+         i != substrings[level].end();
+         ++i)
+    {
+        if (file.find(*i) != std::string::npos)
+            return true;
+    }
+    return false;
+}
+
+}} // namespace qpid::log

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Selector.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Selector.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Selector.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/log/Selector.h?view=auto&rev=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/log/Selector.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/log/Selector.h Wed May 30 09:13:58 2007
@@ -0,0 +1,68 @@
+#ifndef SELECTOR_H
+#define SELECTOR_H
+
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "Statement.h"
+#include <vector>
+
+namespace qpid {
+namespace log {
+class Options;
+
+/**
+ * A selector identifies the set of log messages to enable.
+ * 
+ * Thread object unsafe, pass-by-value type. 
+ */
+class Selector {
+  public:
+    /** Empty selector selects nothing */
+    Selector() {}
+
+    /** Set selector from Options */
+    Selector(const Options&);
+    
+    /** Equavlient to: Selector s; s.enable(l, s) */
+    Selector(Level l, const std::string& s=std::string()) {
+        enable(l,s);
+    }
+    /**
+     * Enable messages with level in levels where the file 
+     * name contains substring. Empty string matches all.
+     */
+    void enable(Level level, const std::string& substring=std::string()) {
+        substrings[level].push_back(substring);
+    }
+
+    /** Enable based on a 'level[+]:file' string */
+    void enable(const std::string& enableStr);
+
+    /** True if level is enabld for file. */
+    bool isEnabled(Level level, const std::string& file);
+
+  private:
+    std::vector<std::string> substrings[LevelTraits::COUNT];
+};
+
+
+}} // namespace qpid::log
+
+
+#endif  /*!SELECTOR_H*/

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Selector.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Selector.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Statement.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/log/Statement.cpp?view=auto&rev=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/log/Statement.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/log/Statement.cpp Wed May 30 09:13:58 2007
@@ -0,0 +1,67 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "Statement.h"
+#include "Logger.h"
+#include "qpid/Exception.h"
+#include <syslog.h>
+
+namespace qpid {
+namespace log {
+
+void Statement::log(const std::string& message) {
+    Logger::instance().log(*this,message);
+}
+
+Statement::Initializer::Initializer(Statement& s) : statement(s) {
+    Logger::instance().add(s);
+}
+
+Statement::Initializer::~Initializer() {
+    Logger::instance().remove(statement);
+}
+
+namespace {
+const char* names[LevelTraits::COUNT] = {
+    "trace", "debug", "info", "notice", "warning", "error", "critical"
+};
+
+int priorities[LevelTraits::COUNT] = {
+    LOG_DEBUG, LOG_DEBUG, LOG_INFO, LOG_NOTICE,
+    LOG_WARNING, LOG_ERR, LOG_CRIT
+};
+
+} // namespace
+
+Level LevelTraits::level(const char* name) {
+    for (int i =0; i < LevelTraits::COUNT; ++i) {
+        if (strcmp(names[i], name)==0)
+            return Level(i);
+    }
+    throw qpid::Exception(std::string("Invalid log level name: ")+name);
+}
+
+const char* LevelTraits::name(Level l) {
+    return names[l];
+}
+
+int LevelTraits::priority(Level l) {
+    return priorities[l];
+}
+
+}} // namespace qpid::log

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Statement.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Statement.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Statement.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/log/Statement.h?view=auto&rev=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/log/Statement.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/log/Statement.h Wed May 30 09:13:58 2007
@@ -0,0 +1,124 @@
+#ifndef STATEMENT_H
+#define STATEMENT_H
+
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "qpid/log/Statement.h"
+#include <boost/current_function.hpp>
+#include <sstream>
+
+namespace qpid {
+namespace log {
+
+/** Debugging severity levels
+ * - trace: High-volume debugging messages.
+ * - debug: Debugging messages.
+ * - info: Informational messages.
+ * - notice: Normal but significant condition.
+ * - warning: Warn of a possible problem.
+ * - error: A definite error has occured. 
+ * - critical: System in danger of severe failure.
+ */
+enum Level { trace, debug, info, notice, warning, error, critical };
+struct LevelTraits {
+    static const int COUNT=critical+1;
+
+    /** Get level from string name.
+     *@exception if name invalid.
+     */
+    static Level level(const char* name); 
+
+    /** Get level from string name.
+     *@exception if name invalid.
+     */
+    static  Level level(const std::string& name) {
+        return level(name.c_str());
+    }
+
+    /** String name of level */
+    static const char* name(Level); 
+
+    /** Syslog priority of level */
+    static int priority(Level);
+};
+    
+/** POD struct representing a logging statement in source code. */
+struct Statement {
+    bool enabled;
+    const char* file;
+    int line;        
+    const char* function;
+    Level level;           
+
+    void log(const std::string& message);
+
+    struct Initializer {
+        Initializer(Statement& s);
+        ~Initializer();
+        Statement& statement;
+    };
+};
+
+///@internal trickery to make QPID_LOG_STRINGSTREAM work.
+inline std::ostream& noop(std::ostream& s) { return s; }
+
+///@internal static initializer for a Statement.
+#define QPID_LOG_STATEMENT_INIT(level) \
+    { 0, __FILE__, __LINE__,  BOOST_CURRENT_FUNCTION, (::qpid::log::level) }
+
+///@internal Stream streamable message and return a string.
+#define QPID_LOG_STRINGSTREAM(message) \
+    static_cast<std::ostringstream&>( \
+        std::ostringstream() << qpid::log::noop << message).str()
+
+/**
+ * Macro for log statements. Example of use:
+ * @code
+ * QPID_LOG(debug, "There are " << foocount << " foos in the bar.");
+ * QPID_LOG(error, boost::format("Dohickey %s exploded") % dohicky.name());
+ * @endcode
+ *
+ * All code with logging statements should be built with
+ *   -DQPID_COMPONENT=<component name>
+ * where component name is the name of the component this file belongs to.
+ * 
+ * You can subscribe to log messages by level, by component, by filename
+ * or a combination @see Configuration.
+
+ *@param LEVEL severity Level for message, should be one of:
+ * debug, info, notice, warning, error, critical. NB no qpid::log:: prefix.
+ *@param MESSAGE any object with an @eostream operator<<, or a sequence
+ * like of ostreamable objects separated by @e<<.
+ */
+#define QPID_LOG(level, message)                                        \
+    do {                                                                \
+        static ::qpid::log::Statement stmt_= QPID_LOG_STATEMENT_INIT(level); \
+        static ::qpid::log::Statement::Initializer init_(stmt_);        \
+        if (stmt_.enabled)                                              \
+            stmt_.log(QPID_LOG_STRINGSTREAM(message));                \
+    } while(0)
+
+
+}} // namespace qpid::log
+
+
+
+
+#endif  /*!STATEMENT_H*/
+ 

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Statement.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/log/Statement.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/memory.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/memory.h?view=auto&rev=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/memory.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/memory.h Wed May 30 09:13:58 2007
@@ -0,0 +1,32 @@
+#ifndef QPID_AUTO_PTR_H
+#define QPID_AUTO_PTR_H
+
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <memory>
+namespace qpid {
+/** Convenient template for creating auto_ptr in-place in an argument list. */
+template <class T>
+std::auto_ptr<T> make_auto_ptr(T* ptr) { return std::auto_ptr<T>(ptr); }
+
+} // namespace qpid
+
+
+
+#endif  /*!QPID_AUTO_PTR_H*/

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/memory.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/memory.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h Wed May 30 09:13:58 2007
@@ -29,4 +29,3 @@
 #endif
 
 #endif //ifndef _sys_Module_h
-

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRAcceptor.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRAcceptor.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRAcceptor.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRAcceptor.cpp Wed May 30 09:13:58 2007
@@ -18,6 +18,7 @@
  * under the License.
  *
  */
+#include "qpid/log/Statement.h"
 #include "qpid/sys/Acceptor.h"
 #include "qpid/sys/ConnectionInputHandlerFactory.h"
 #include "qpid/sys/Mutex.h"
@@ -80,7 +81,7 @@
 void APRAcceptor::run(ConnectionInputHandlerFactory* factory) {
     running = true;
     processor.start();
-    std::cout << "Listening on port " << getPort() << "..." << std::endl;
+    QPID_LOG(info, "Listening on port " << getPort());
     while(running) {
             apr_socket_t* client;
             apr_status_t status = apr_socket_accept(&client, socket, APRPool::get());
@@ -97,7 +98,7 @@
             Mutex::ScopedLock locker(shutdownLock);                
             if(running) {
                 if(status != APR_EINTR){
-                    std::cout << "ERROR: " << get_desc(status) << std::endl;
+                    QPID_LOG(error, get_desc(status));
                 }
                 shutdownImpl();
             }

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRBase.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRBase.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRBase.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRBase.cpp Wed May 30 09:13:58 2007
@@ -19,6 +19,7 @@
  *
  */
 #include <iostream>
+#include "qpid/log/Statement.h"
 #include "qpid/QpidError.h"
 #include "APRBase.h"
 
@@ -73,9 +74,8 @@
 
 void APRBase::increment(){
     int count = 0;
-    while(count++ < 2 && !getInstance()->_increment()){
-        std::cout << "WARNING: APR initialization triggered concurrently with termination." << std::endl;
-    }
+    while(count++ < 2 && !getInstance()->_increment())
+        QPID_LOG(warning, "APR initialization triggered concurrently with termination.");
 }
 
 void APRBase::decrement(){

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRSocket.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRSocket.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRSocket.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRSocket.cpp Wed May 30 09:13:58 2007
@@ -20,6 +20,7 @@
  */
 #include "APRBase.h"
 #include "APRSocket.h"
+#include "qpid/log/Statement.h"
 #include <assert.h>
 #include <iostream>
 
@@ -53,7 +54,7 @@
 
 void APRSocket::close(){
     if(!closed){
-        std::cout << "Closing socket " << socket << "@" << this << std::endl;
+        QPID_LOG(warning, "Closing socket " << socket << "@" << this);
         CHECK_APR_SUCCESS(apr_socket_close(socket));
         closed = true;
     }

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFProcessor.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFProcessor.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFProcessor.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFProcessor.cpp Wed May 30 09:13:58 2007
@@ -19,6 +19,7 @@
  *
  */
 #include <sstream>
+#include "qpid/log/Statement.h"
 #include "qpid/QpidError.h"
 #include "qpid/sys/Mutex.h"
 #include "LFProcessor.h"
@@ -136,7 +137,7 @@
             }
         }
     }catch(std::exception e){
-	std::cout << e.what() << std::endl;
+	QPID_LOG(error,  e.what());
     }
 }
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFSessionContext.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFSessionContext.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFSessionContext.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFSessionContext.cpp Wed May 30 09:13:58 2007
@@ -21,6 +21,7 @@
 #include "LFSessionContext.h"
 #include "APRBase.h"
 #include "qpid/QpidError.h"
+#include "qpid/log/Statement.h"
 #include <assert.h>
 
 using namespace qpid::sys;
@@ -60,20 +61,18 @@
         AMQFrame frame;
         try{
             while(frame.decode(in)){
-                if(debug) log("RECV", &frame);
+                QPID_LOG(debug, "RECV: " << frame);
                 handler->received(&frame);
             }
-        }catch(QpidError error){
-            std::cout << "Error [" << error.code << "] " << error.msg
-                      << " (" << error.loc.file << ":" << error.loc.line
-                      << ")" << std::endl;
+        }catch(const std::exception& e){
+            QPID_LOG(error, e.what());
         }
     }else{
         ProtocolInitiation protocolInit;
         if(protocolInit.decode(in)){
             handler->initiated(protocolInit);
             initiated = true;
-            if(debug) std::cout << "INIT [" << &socket << "]" << std::endl;
+            QPID_LOG(debug, "INIT [" << &socket << "]");
         }
     }
     in.compact();
@@ -99,7 +98,7 @@
                 while(frame && out.available() >= frame->size()){
                     encoded = true;
                     frame->encode(out);
-                    if(debug) log("SENT", frame);
+                    QPID_LOG(debug, "SENT: " << frame);
                     delete frame;
                     framesToWrite.pop();
                     frame = framesToWrite.empty() ? 0 : framesToWrite.front();
@@ -156,7 +155,7 @@
 
 void LFSessionContext::handleClose(){
     handler->closed();
-    std::cout << "Session closed [" << &socket << "]" << std::endl;
+    QPID_LOG(info, "Session closed [" << &socket << "]");
     delete handler;
     delete this;
 }
@@ -171,9 +170,3 @@
     processor->add(&fd);
 }
 
-void LFSessionContext::log(const std::string& desc, AMQFrame* const frame){
-    Mutex::ScopedLock l(logLock);
-    std::cout << desc << " [" << &socket << "]: " << *frame << std::endl;
-}
-
-Mutex LFSessionContext::logLock;

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFSessionContext.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFSessionContext.h?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFSessionContext.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFSessionContext.h Wed May 30 09:13:58 2007
@@ -61,11 +61,6 @@
     bool processing;
     bool closing;
 
-    static qpid::sys::Mutex logLock;
-    void log(const std::string& desc,
-             qpid::framing::AMQFrame* const frame);
-        
-
   public:
     LFSessionContext(apr_pool_t* pool, apr_socket_t* socket, 
                      LFProcessor* const processor, 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Module.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Module.h?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Module.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Module.h Wed May 30 09:13:58 2007
@@ -21,7 +21,7 @@
  * under the License.
  *
  */
-
+#include "qpid/log/Statement.h"
 #include "qpid/QpidError.h"
 #include "APRBase.h"
 #include "APRPool.h"
@@ -85,7 +85,7 @@
         }
         if (handle) unload();
     } catch (std::exception& e) {
-        std::cout << "Error while destroying module: " << e.what() << std::endl;
+        QPID_LOG(error, "Error while destroying module: " << e.what());
     }
     destroy = 0;
     handle = 0;

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Thread.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Thread.h?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Thread.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Thread.h Wed May 30 09:13:58 2007
@@ -37,6 +37,12 @@
 {
   public:
     inline static Thread current();
+
+    /** ID of current thread for logging.
+     * Workaround for broken Thread::current() in APR 
+     */
+    inline static long logId();
+
     inline static void yield();
 
     inline Thread();
@@ -46,7 +52,7 @@
     inline void join();
 
     inline long id();
-        
+
   private:
     static void* APR_THREAD_FUNC runRunnable(apr_thread_t* thread, void *data);
     inline Thread(apr_thread_t* t);
@@ -73,6 +79,13 @@
 
 long Thread::id() {
     return long(thread);
+}
+
+/** ID of current thread for logging.
+ * Workaround for broken Thread::current() in APR
+ */
+long Thread::logId() {
+    return static_cast<long>(apr_os_thread_current());
 }
 
 Thread::Thread(apr_thread_t* t) : thread(t) {}

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannel.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannel.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannel.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannel.cpp Wed May 30 09:13:58 2007
@@ -33,6 +33,7 @@
 
 #include "qpid/QpidError.h"
 #include "qpid/sys/Monitor.h"
+#include "qpid/log/Statement.h"
 
 #include "check.h"
 #include "EventChannel.h"
@@ -190,9 +191,8 @@
                                     &epollEvent, 1, infiniteTimeout);
         if (eventCount < 0) {
             if (errno != EINTR) {
-                // TODO aconway 2006-11-28: Proper handling/logging of errors.
-                cerr << BOOST_CURRENT_FUNCTION << " ignoring error "
-                     << PosixError::getMessage(errno) << endl;
+                QPID_LOG(warn, "Ignoring error: "
+                         << PosixError::getMessage(errno));
                 assert(0);
             }
         }

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelConnection.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelConnection.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelConnection.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelConnection.cpp Wed May 30 09:13:58 2007
@@ -24,6 +24,7 @@
 #include "EventChannelConnection.h"
 #include "qpid/sys/ConnectionInputHandlerFactory.h"
 #include "qpid/QpidError.h"
+#include "qpid/log/Statement.h"
 
 using namespace std;
 using namespace qpid;
@@ -132,8 +133,7 @@
     }
     // No need to lock here - only one thread can be writing at a time.
     out.clear();
-    if (isTrace)
-        cout << "Send on socket " << writeFd << ": " << *frame << endl;
+    QPID_LOG(trace, "Send on socket " << writeFd << ": " << *frame);
     frame->encode(out);
     out.flip();
     writeEvent = WriteEvent(
@@ -215,10 +215,8 @@
         in.flip();
         AMQFrame frame;
         while (frame.decode(in)) {
-            // TODO aconway 2006-11-30: received should take Frame&
-            if (isTrace)
-                cout << "Received on socket " << readFd
-                     << ": " << frame << endl;
+            QPID_LOG(trace, "Received on socket " << readFd
+                     << ": " << frame);
             handler->received(&frame); 
         }
         in.compact();

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelThreads.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelThreads.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelThreads.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelThreads.cpp Wed May 30 09:13:58 2007
@@ -18,6 +18,7 @@
 
 #include "EventChannelThreads.h"
 #include "qpid/sys/Runnable.h"
+#include "qpid/log/Statement.h"
 #include <iostream>
 using namespace std;
 #include <boost/bind.hpp>
@@ -106,13 +107,10 @@
         }
     }
     catch (const std::exception& e) {
-        // TODO aconway 2006-11-15: need better logging across the board.
-        std::cerr << "EventChannelThreads::run() caught: " << e.what()
-                  << std::endl;
+        QPID_LOG(error, e.what());
     }
     catch (...) {
-        std::cerr << "EventChannelThreads::run() caught unknown exception."
-                  << std::endl;
+        QPID_LOG(error, "unknown exception");
     }
 }
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Module.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Module.h?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Module.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Module.h Wed May 30 09:13:58 2007
@@ -23,6 +23,7 @@
  */
  
 #include "qpid/QpidError.h"
+#include "qpid/log/Statement.h"
 
 #include <boost/noncopyable.hpp>
 #include <iostream>
@@ -83,7 +84,7 @@
         }
         if (handle) unload();
     } catch (std::exception& e) {
-        std::cout << "Error while destroying module: " << e.what() << std::endl;
+        QPID_LOG(error, "Error while destroying module: " << e.what());
     }
     destroy = 0;
     handle = 0;

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Thread.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Thread.h?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Thread.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Thread.h Wed May 30 09:13:58 2007
@@ -34,6 +34,12 @@
 {
   public:
     inline static Thread current();
+
+    /** ID of current thread for logging.
+     * Workaround for broken Thread::current() in APR
+     */
+    static long logId() { return current().id(); }
+
     inline static void yield();
 
     inline Thread();

Modified: incubator/qpid/trunk/qpid/cpp/src/qpidd.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpidd.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpidd.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpidd.cpp Wed May 30 09:13:58 2007
@@ -19,12 +19,15 @@
  *
  */
 #include "qpid/broker/Broker.h"
+#include "qpid/sys/posix/check.h"
+#include "qpid/broker/Daemon.h"
+#include "qpid/log/Statement.h"
+#include "qpid/log/Options.h"
+#include "qpid/log/Logger.h"
+#include "config.h"
 #include <iostream>
 #include <fstream>
 #include <signal.h>
-#include "config.h"
-#include "qpid/sys/posix/check.h"
-#include "qpid/broker/Daemon.h"
 
 using namespace qpid;
 using namespace qpid::broker;
@@ -34,15 +37,16 @@
 Broker::shared_ptr brokerPtr;
 
 void handle_signal(int /*signal*/){
-    std::cerr << "Shutting down..." << std::endl;
+    QPID_LOG(notice, "Shutting down...");
     brokerPtr->shutdown();
 }
 
 
 /** Command line options */
-struct QpiddOptions : public Broker::Options
+struct QpiddOptions : public Broker::Options, public log::Options
 {
     bool help;
+    bool longHelp;
     bool version;
     bool daemon;
     bool quit;
@@ -51,50 +55,56 @@
     bool ppid;
     int wait;
     string config;
-    po::options_description desc;
+    po::options_description mainOpts;
+    po::options_description allOpts;
+    po::options_description logOpts;
     
     QpiddOptions() :
         help(false), version(false), daemon(false),
         quit(false), kill(false), check(false), ppid(false), wait(10),
         config("/etc/qpidd.conf"),
-        desc("Options")
+        mainOpts("Options"),
+        logOpts("Logging Options")
     {
         using namespace po;
-        desc.add_options()
+        mainOpts.add_options()
             ("daemon,d", optValue(daemon), "Run as a daemon.")
             ("quit,q", optValue(quit), "Stop the running daemon politely.")
             ("kill,k", optValue(kill), "Kill the running daemon harshly.")
             ("check,c", optValue(check), "If daemon is running return 0.")
             ("wait", optValue(wait, "SECONDS"),
              "Maximum wait for daemon response.")
-            ("ppid", optValue(ppid), "Print daemon pid to stdout" );
+            ("ppid", optValue(ppid), "Print daemon pid to stdout." );
         po::options_description brokerOpts;
-        Broker::Options::addTo(desc);
-        desc.add_options()
-            ("config", optValue(config, "FILE"), "Configuration file")
-            ("help,h", optValue(help), "Print help message")
-            ("version,v", optValue(version), "Print version information");
+        Broker::Options::addTo(mainOpts);
+        mainOpts.add_options()
+            ("config", optValue(config, "FILE"), "Configuation file.")
+            ("help,h", optValue(help), "Print help message.")
+            ("long-help", optValue(longHelp), "Show complete list of options.")
+            ("version,v", optValue(version), "Print version information.");
+
+        log::Options::addTo(logOpts);
+        allOpts.add(mainOpts).add(logOpts);
     }
 
     void parse(int argc, char* argv[]) {
-        parseOptions(desc, argc, argv, config);
+        parseOptions(allOpts, argc, argv, config);
     }
     
-    void usage(ostream& out) const {
-        out << "Usage: qpidd [OPTIONS]" << endl << endl
-            << desc << endl;
+    void usage(const po::options_description& opts) const {
+        cout << "Usage: qpidd [OPTIONS]" << endl << endl
+                  << opts << endl;
     };
 };
 
-ostream& operator<<(ostream& out, const QpiddOptions& config)  {
-    config.usage(out); return out;
-}
-
 int main(int argc, char* argv[])
 {
     QpiddOptions config;
     try {
         config.parse(argc, argv);
+        if (config.trace)
+            config.selectors.push_back("trace");
+        log::Logger::instance().configure(config, argv[0]);
         string name=(boost::format("%s.%d")
                      % Daemon::nameFromArgv0(argv[0])
                      % (config.port)).str();
@@ -102,17 +112,18 @@
         Daemon demon(name, config.wait);
 
         // Options that just print information.
-        if(config.help) {
-            config.usage(cout);
-            return 0;
-        }
-        if (config.version) {
-            cout << "qpidd (" << PACKAGE_NAME << ") version "
-                 << PACKAGE_VERSION << endl;
+        if(config.help || config.longHelp || config.version) {
+            if (config.version) 
+                cout << "qpidd (" << PACKAGE_NAME << ") version "
+                     << PACKAGE_VERSION << endl;
+            if (config.longHelp)
+                config.usage(config.allOpts);
+            else if (config.help)
+                config.usage(config.mainOpts);
             return 0;
         }
 
-        // Options that affect an already running daemon.
+        // Options that act on an already running daemon.
         if (config.quit || config.kill || config.check) {
             pid_t pid = demon.check();
             if (config.ppid && pid > 0)
@@ -136,8 +147,7 @@
                     demon.ready();   // Notify parent we're ready.
                     brokerPtr->run();
                 } catch (const exception& e) {
-                    // TODO aconway 2007-04-26: Log this, cerr is lost.
-                    cerr << "Broker daemon failed: " << e.what() << endl;
+                    QPID_LOG(critical, "Broker daemon startup failed: " << e.what());
                     demon.failed(); // Notify parent we failed.
                     return 1;
                 }
@@ -147,7 +157,7 @@
                     cout << pid << endl;
                 return 0;
             }
-            else { // pid < 0
+            else { // pid < 0 
                 throw Exception("fork failed"+strError(errno));
             }
         } // Non-daemon broker.
@@ -163,6 +173,8 @@
              << "Type 'qpidd --help' for usage." << endl;
     }
     catch(const exception& e) {
+        // Could be child or parent so log and print.
+        QPID_LOG(error, e.what());
         cerr << "Error: " << e.what() << endl;
     }
     return 1;

Propchange: incubator/qpid/trunk/qpid/cpp/src/tests/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed May 30 09:13:58 2007
@@ -11,3 +11,4 @@
 qpidd.pid
 valgrind.out
 .valgrindrc
+logging

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/AccumulatedAckTest.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/AccumulatedAckTest.cpp?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/AccumulatedAckTest.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/AccumulatedAckTest.cpp Wed May 30 09:13:58 2007
@@ -1,3 +1,4 @@
+
 /*
  *
  * Licensed to the Apache Software Foundation (ASF) under one

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am Wed May 30 09:13:58 2007
@@ -1,6 +1,17 @@
 AM_CXXFLAGS = $(WARNING_CFLAGS) $(CPPUNIT_CXXFLAGS)   $(APR_CXXFLAGS)
 INCLUDES =  -I$(srcdir)/.. -I$(srcdir)/../gen -I$(top_builddir)/src/gen
 
+
+# Unit test programs
+UNIT_TESTS=
+
+UNIT_TESTS+=logging
+logging_SOURCES=unit/logging.cpp unit/test_tools.h
+logging_LDADD=-lboost_unit_test_framework -lboost_regex $(lib_common)
+
+# NB: CppUnit test libraries below will be migrated to boost test programs.
+# UNIT_TESTS+= ...
+
 # Unit tests
 broker_unit_tests =	\
   AccumulatedAckTest	\
@@ -52,19 +63,24 @@
   topic_listener	\
   topic_publisher
 
-noinst_PROGRAMS = $(testprogs)
+check_PROGRAMS = $(UNIT_TESTS) $(testprogs)
 
+# FIXME aconway 2007-05-30: TESTS_ENVIRONMENT should have ./run_test
+# as below to run valgrind on all test programs.
+# Disabled temporarily till leaks in client_test are fixed.
+#
+#TESTS_ENVIRONMENT = VALGRIND=$(VALGRIND) srcdir=$(srcdir) ./run_test
 TESTS_ENVIRONMENT = VALGRIND=$(VALGRIND) srcdir=$(srcdir)
 
-CLIENT_TESTS = client_test quick_topictest
-TESTS = run-unit-tests start_broker $(CLIENT_TESTS) python_tests kill_broker daemon_test
+SYSTEM_TESTS = client_test quick_topictest
+TESTS = $(UNIT_TESTS) run-unit-tests start_broker $(SYSTEM_TESTS) python_tests kill_broker daemon_test
 
 EXTRA_DIST =								\
   test_env								\
   run-unit-tests start_broker python_tests kill_broker daemon_test	\
   quick_topictest							\
   topictest								\
-  .valgrind.supp							\
+  .valgrind.supp-default						\
   .valgrindrc-default							\
   InProcessBroker.h							\
   MockChannel.h								\
@@ -103,20 +119,21 @@
 	> $@-t
 	mv $@-t $@
 
-check: .valgrindrc ../qpidd
+check: .valgrindrc .valgrind.supp
 
 check-unit:
-	$(MAKE) check TESTS=run-unit-tests
+	$(MAKE) check TESTS=$(UNIT_TESTS) run-unit-tests
 
 # Create a copy so that can be modified without risk of committing the changes.
 .valgrindrc: .valgrindrc-default
-	cp $(srcdir)/.valgrindrc-default .valgrindrc
+	cp $^ $@
+.valgrind.supp: .valgrind.supp-default
+	cp $^ $@
 
 # Tell GNU make not to build targets in this directory in parallel.
 # This is necessary because with two or more identical and simultaneous
 # ltmain invocations, one may corrupt the temporaries of the other.
 .NOTPARALLEL:
 
-CLEANFILES=valgrind.out qpidd.log
-DISTCLEANFILES=.valgrindrc 
+CLEANFILES=valgrind.out qpidd.log .valgrindrc .valgrind.supp
 MAINTAINERCLEANFILES=gen.mk

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/kill_broker
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/kill_broker?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/kill_broker (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/kill_broker Wed May 30 09:13:58 2007
@@ -1,3 +1,2 @@
 #!/bin/sh
-PID=qpidd.pid
-if [ -f $PID ] ; then kill -9 `cat $PID` ; rm -f $PID ; fi
+../qpidd --quit

Added: incubator/qpid/trunk/qpid/cpp/src/tests/run_test
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/run_test?view=auto&rev=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/run_test (added)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/run_test Wed May 30 09:13:58 2007
@@ -0,0 +1,60 @@
+#!/bin/sh
+#
+# Run a test executable. Output nothing if test passes,
+# show the output if it fails. Leave output in <test>.log for 
+# examination. 
+# 
+# If $VALGRIND if is set run under valgrind. If there are
+# valgrind erros show valgrind output, also leave it in
+# <test>.valgrind for examination.
+#
+
+vg_failed() {
+    cat $VG_LOG 1>&2
+    echo $1 1>&2
+    exit 1
+}
+
+vg_check()
+{
+    test -f $VG_LOG || vg_failed Valgrind log file $VG_LOG missing.
+    # Ensure there is an ERROR SUMMARY line.
+    grep -E '^==[0-9]+== ERROR SUMMARY:' $VG_LOG > /dev/null || \
+	vg_failed "No valgrind ERROR SUMMARY line in $$vg_failed."
+    # Ensure that the number of errors is 0.
+    grep -E '^==[0-9]+== ERROR SUMMARY: [^0] ' $VG_LOG > /dev/null && \
+	vg_failed "Valgrind reported errors in $vg_out; see above." 
+    # Check for leaks.
+    grep -E '^==[0-9]+== +.* lost: [^0]' $VG_LOG && \
+	vg_failed "Found memory leaks (see log file, $VG_LOG); see above."
+    true
+}
+
+# Export variables from makefile.
+export VALGRIND srcdir
+
+VG_LOG="$1.vglog"
+TEST_LOG="$1.log"
+rm -f $VG_LOG $TEST_LOG
+
+if grep -l "^# Generated by .*libtool" "$1" >/dev/null 2>&1; then
+    # This is a libtool "executable". Valgrind it if VALGRIND specified.
+    test -n "$VALGRIND" && VALGRIND="$VALGRIND --log-file-exactly=$VG_LOG --"
+    # Hide output unless there's an error.
+    libtool --mode=execute $VALGRIND "$@" >$TEST_LOG 2>&1 || {
+	ERROR=$?
+	cat $TEST_LOG  
+    }
+    test -n "$VALGRIND" && vg_check
+else
+    # This is a non-libtool shell script, just execute it.
+    "$@"
+fi
+
+if test -z "$ERROR"; then
+    # Clean up logs if there was no error.
+    rm -f $VG_LOG $TEST_LOG
+    exit 0
+else
+    exit $ERROR
+fi

Propchange: incubator/qpid/trunk/qpid/cpp/src/tests/run_test
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/start_broker
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/start_broker?view=diff&rev=542855&r1=542854&r2=542855
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/start_broker (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/start_broker Wed May 30 09:13:58 2007
@@ -1,14 +1,5 @@
 #!/bin/sh
-set -e
-
-LOG=`pwd`/qpidd.log
-PID=`pwd`/qpidd.pid
-
-rm -rf $LOG $PID
-
-# Start the daemon, recording its PID.
-../qpidd > $LOG 2>&1 & echo $! > $PID
-
-# FIXME aconway 2007-01-18: qpidd should not return till it is accepting
-# connections, remove arbitrary sleep.
-sleep 30
+fail() { echo FAIL: $0:$* 1>&2; exit 1; }
+qpidd=../qpidd
+PID=`$qpidd --check --ppid` && fail $qpidd already running $PID
+$qpidd --log.output qpidd.log --daemon || fail $qpidd startup: `cat qpidd.log`

Propchange: incubator/qpid/trunk/qpid/cpp/src/tests/unit/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed May 30 09:13:58 2007
@@ -0,0 +1,3 @@
+logging
+Makefile.in
+Makefile