[asterisk-scf-commits] asterisk-scf/integration/logger.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Sep 27 13:55:30 CDT 2010


branch "master" has been updated
       via  8ce4322d4b18a28b6a3fdadae5f871f44ecd1764 (commit)
      from  46eb099971cf5755016c739c1f4cc14acde31ec9 (commit)

Summary of changes:
 client/src/Logger.cpp              |   20 ++++++++++++++++----
 client/src/LoggerFactory.cpp       |    7 ++++++-
 client/src/logger.h                |   12 ++++++------
 client/test/LoggerFactory-test.cpp |   19 +++++++++++++++++++
 4 files changed, 47 insertions(+), 11 deletions(-)


- Log -----------------------------------------------------------------
commit 8ce4322d4b18a28b6a3fdadae5f871f44ecd1764
Author: David M. Lee <dlee at digium.com>
Date:   Mon Sep 27 13:52:36 2010 -0500

    Added ability to change output after LoggerFactory creation.

diff --git a/client/src/Logger.cpp b/client/src/Logger.cpp
index bbe2d6a..93558a4 100644
--- a/client/src/Logger.cpp
+++ b/client/src/Logger.cpp
@@ -53,7 +53,7 @@ void LogBuf::sendBuffer()
 }
 
 Logger::Logger(std::string const &name, LogOut &out, Level logLevel) :
-   parent(0), name(name), out(out), logLevel(logLevel), inheritedLevel(false)
+   parent(0), name(name), out(&out), logLevel(logLevel), inheritedLevel(false)
 {
 }
 
@@ -67,14 +67,14 @@ Logger::Logger(Logger const &parent, std::string const &name) :
 
 CondStream Logger::operator()(Level level) const
 {
-   return CondStream(out, name, level, isEnabledFor(level));
+   return CondStream(*out, name, level, isEnabledFor(level));
 }
 
 void Logger::logs(Level level, std::string const &message) const
 {
    if (isEnabledFor(level))
    {
-      out.logs(name, level, message);
+      out->logs(name, level, message);
    }
 }
 
@@ -94,7 +94,7 @@ void Logger::vlogf(Level level, char const *fmt, va_list ap) const
       vasprintf(&message, fmt, ap);
       if (message)
       {
-         out.logs(name, level, message);
+         out->logs(name, level, message);
          free(message);
       }
       else
@@ -102,10 +102,22 @@ void Logger::vlogf(Level level, char const *fmt, va_list ap) const
          // vasprintf failed to log our message.  At least send it somewhere
          fprintf(stderr, "Failed to log: ");
          vfprintf(stderr, fmt, ap);
+         fprintf(stderr, "\n");
       }
    }
 }
 
+void Logger::setOutput(LogOut &out)
+{
+   this->out = &out;
+   for (std::map<std::string, Logger *>::const_iterator i = children.begin(); i
+      != children.end(); ++i)
+   {
+      i->second->setOutput(out);
+   }
+}
+
+
 void Logger::setLevel(Level logLevel)
 {
    this->logLevel = logLevel;
diff --git a/client/src/LoggerFactory.cpp b/client/src/LoggerFactory.cpp
index 9865f3c..2b0dcd1 100644
--- a/client/src/LoggerFactory.cpp
+++ b/client/src/LoggerFactory.cpp
@@ -44,7 +44,7 @@ LoggerFactory &AsteriskSCF::System::Logging::getLoggerFactory()
 }
 
 LoggerFactory::LoggerFactory(LogOut &out) :
-   out(out), root("", out)
+   root("", out)
 {
 }
 
@@ -86,3 +86,8 @@ void LoggerFactory::accumulateLoggerNames(Logger const &logger, std::vector<
       accumulateLoggerNames(**i, out);
    }
 }
+
+void LoggerFactory::setLogOutput(LogOut &out)
+{
+   root.setOutput(out);
+}
diff --git a/client/src/logger.h b/client/src/logger.h
index 746915a..f08fabd 100644
--- a/client/src/logger.h
+++ b/client/src/logger.h
@@ -191,9 +191,11 @@ public:
 
    LogOut &getOutput() const
    {
-      return out;
+      return *out;
    }
 
+   void setOutput(LogOut &out);
+
    /**
     * Set's the current logLevel.  Until unsetLevel() is called, we are no
     * longer affected by changes to our parent's log level.
@@ -232,7 +234,7 @@ private:
    /**
     * Output for log messages.
     */
-   LogOut &out;
+   LogOut *out;
    /**
     * Current level of this Logger.  Only applicable if inheritedLevel == false.
     */
@@ -267,11 +269,9 @@ public:
     */
    std::vector<std::string> getLoggerNames() const;
 
+   void setLogOutput(LogOut &out);
+
 private:
-   /**
-    * LogOut for new Logger's.
-    */
-   LogOut &out;
    Logger root;
 
    static void accumulateLoggerNames(Logger const &logger, std::vector<std::string> &out);
diff --git a/client/test/LoggerFactory-test.cpp b/client/test/LoggerFactory-test.cpp
index 110d541..3b84437 100644
--- a/client/test/LoggerFactory-test.cpp
+++ b/client/test/LoggerFactory-test.cpp
@@ -9,6 +9,7 @@
 #include <boost/test/unit_test.hpp>
 
 #include "logger.h"
+#include "ExpectedLogOut.h"
 
 using namespace AsteriskSCF::System::Logging;
 
@@ -58,4 +59,22 @@ BOOST_AUTO_TEST_CASE(testInheritence_on)
    BOOST_CHECK_EQUAL("AsteriskSCF:Debug:Should log\n", actual.str());
 }
 
+BOOST_AUTO_TEST_CASE(testChangeLogOut)
+{
+   ExpectedLogOut out1("src:Critical:Critical Message\n");
+   ExpectedLogOut out2("src:Debug:Debug Message\n");
+
+   Logger uut("src", out1, Debug);
+
+   uut.logs(Critical, "Critical Message");
+   out1.check();
+
+   uut.setOutput(out2);
+   uut.logs(Debug, "Debug Message");
+   out1.check();
+   out2.check();
+
+
+}
+
 BOOST_AUTO_TEST_SUITE_END()

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/logger.git



More information about the asterisk-scf-commits mailing list