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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Jan 4 21:41:19 UTC 2011


branch "master" has been updated
       via  b3fcaefff15075d3d62a50868716def5d3d5641e (commit)
       via  869c886b995992b695893795f4dcaf4b36bf43fc (commit)
       via  71f2a6e6aec4ba5c50a678a142e44adbff3ccfcb (commit)
      from  d2dd67b7a2e5e77eb83a2c7bee65c7f8d6a2b6bf (commit)

Summary of changes:
 client/src/Logger.cpp              |   66 +++++-------
 client/src/LoggerFactory.cpp       |   16 ++--
 client/src/logger.h                |  204 +++++++++++++++++++++++++++++++----
 client/test/LoggerFactory-test.cpp |   26 +----
 4 files changed, 222 insertions(+), 90 deletions(-)


- Log -----------------------------------------------------------------
commit b3fcaefff15075d3d62a50868716def5d3d5641e
Author: David M. Lee <dlee at digium.com>
Date:   Tue Dec 14 18:38:33 2010 -0600

    impl -> mImpl
    
    Adjusted name to match the style guide that, for some reason, I'm
    having trouble adjusting to.  Is it me?  Is it too much like Hungarian
    notation for my subconcious to accept?  Must try harder.
    See CR-ASTSCF-24.

diff --git a/client/src/logger.h b/client/src/logger.h
index b57dcb2..f7f95fb 100644
--- a/client/src/logger.h
+++ b/client/src/logger.h
@@ -219,7 +219,7 @@ public:
     Level getEffectiveLevel() const;
 
 private:
-    boost::shared_ptr<LoggerImpl> impl;
+    boost::shared_ptr<LoggerImpl> mImpl;
 };
 
 class Logger::LoggerImpl
@@ -353,26 +353,26 @@ private:
 // since these are all simple delegates to LoggerImpl, inline them
 
 inline Logger::Logger(const boost::shared_ptr<LoggerImpl>& impl) :
-    impl(impl)
+    mImpl(impl)
 {
 }
 
 inline Logger::Logger(const std::string& name, LogOut& out, Level logLevel) :
-    impl(new LoggerImpl(name, out, logLevel))
+    mImpl(new LoggerImpl(name, out, logLevel))
 {
 }
 
 inline bool Logger::isEnabledFor(Level level) const
 {
-    return impl->isEnabledFor(level);
+    return mImpl->isEnabledFor(level);
 }
 inline CondStream Logger::operator()(Level level) const
 {
-    return (*impl)(level);
+    return (*mImpl)(level);
 }
 inline void Logger::logs(Level level, const std::string& message) const
 {
-    impl->logs(level, message);
+    mImpl->logs(level, message);
 }
 inline void Logger::logf(Level level, char const *fmt, ...) const
 {
@@ -380,7 +380,7 @@ inline void Logger::logf(Level level, char const *fmt, ...) const
     va_start(ap, fmt);
     try
     {
-        impl->vlogf(level, fmt, ap);
+        mImpl->vlogf(level, fmt, ap);
     }
     catch(...)
     {
@@ -391,39 +391,39 @@ inline void Logger::logf(Level level, char const *fmt, ...) const
 }
 inline void Logger::vlogf(Level level, char const *fmt, va_list ap) const
 {
-    impl->vlogf(level, fmt, ap);
+    mImpl->vlogf(level, fmt, ap);
 }
 inline Logger Logger::getChild(const std::string& childName)
 {
-    return impl->getChild(impl, childName);
+    return mImpl->getChild(mImpl, childName);
 }
 inline std::vector<Logger> Logger::getChildren() const
 {
-    return impl->getChildren();
+    return mImpl->getChildren();
 }
 inline const std::string& Logger::getName() const
 {
-    return impl->getName();
+    return mImpl->getName();
 }
 inline LogOut& Logger::getOutput() const
 {
-    return impl->getOutput();
+    return mImpl->getOutput();
 }
 inline void Logger::setOutput(LogOut& out)
 {
-    impl->setOutput(out);
+    mImpl->setOutput(out);
 }
 inline void Logger::setLevel(Level logLevel)
 {
-    impl->setLevel(logLevel);
+    mImpl->setLevel(logLevel);
 }
 inline void Logger::unsetLevel()
 {
-    impl->unsetLevel();
+    mImpl->unsetLevel();
 }
 inline Level Logger::getEffectiveLevel() const
 {
-    return impl->getEffectiveLevel();
+    return mImpl->getEffectiveLevel();
 }
 
 /**

commit 869c886b995992b695893795f4dcaf4b36bf43fc
Author: David M. Lee <dlee at digium.com>
Date:   Fri Dec 10 14:18:52 2010 -0600

    Changed Logger.mParent from raw ptr to weak_ptr.
    
    Raw pointers had the danger of dangling, since there's no longer any
    guarantee that parents will kill their children before dying (as
    gruesome as that sounds).  The use of weak_ptr's makes that safe, while
    avoiding memory leaks that would result from circular shared_ptr
    references.

diff --git a/client/src/Logger.cpp b/client/src/Logger.cpp
index ae74361..c1403e3 100644
--- a/client/src/Logger.cpp
+++ b/client/src/Logger.cpp
@@ -63,16 +63,18 @@ void LogBuf::sendBuffer()
 }
 
 Logger::LoggerImpl::LoggerImpl(const std::string& name, LogOut& out, Level logLevel) :
-    mParent(0), mName(name), mOut(&out), mLogLevel(logLevel), mInheritedLevel(false)
+    mParent(), mName(name), mOut(&out), mLogLevel(logLevel), mInheritedLevel(false)
 {
 }
 
-Logger::LoggerImpl::LoggerImpl(const LoggerImpl& parent, const std::string& name) :
-    mParent(&parent), mName(name), mOut(parent.mOut), mLogLevel(Off),
+Logger::LoggerImpl::LoggerImpl(const boost::shared_ptr<LoggerImpl>& parent, const std::string& name) :
+    mParent(parent), mName(name), mOut(parent->mOut), mLogLevel(Off),
     mInheritedLevel(true)
 {
+    // parent ptr must be non-null
+    assert(parent != 0);
     // our name must begin w/ parent's name
-    assert(name.find(parent.mName) == 0);
+    assert(name.find(parent->mName) == 0);
 }
 
 Logger::LoggerImpl::~LoggerImpl()
@@ -132,10 +134,13 @@ void Logger::LoggerImpl::unsetLevel()
 Level Logger::LoggerImpl::getEffectiveLevel() const
 {
     boost::shared_lock<boost::shared_mutex> lock(mLevelMutex);
+    // If parent is null, either we've never had a parent, or that
+    // parent has been destroyed.
+    boost::shared_ptr<const LoggerImpl> parent = mParent.lock();
     // if our level is unset, inherit level from our parent.
-    if (mInheritedLevel == true && mParent != 0)
+    if (mInheritedLevel == true && parent != 0)
     {
-        return mParent->getEffectiveLevel();
+        return parent->getEffectiveLevel();
     }
     else
     {
@@ -143,7 +148,8 @@ Level Logger::LoggerImpl::getEffectiveLevel() const
     }
 }
 
-Logger Logger::LoggerImpl::getChild(const std::string& childName)
+Logger Logger::LoggerImpl::getChild(const boost::shared_ptr<LoggerImpl>& self,
+    const std::string& childName)
 {
     boost::lock_guard<boost::mutex> childLock(mChildrenMutex);
 
@@ -153,7 +159,7 @@ Logger Logger::LoggerImpl::getChild(const std::string& childName)
     {
         std::string fullName = getName().empty() ? childName : getName() + "."
             + childName;
-        child.reset(new LoggerImpl(*this, fullName));
+        child.reset(new LoggerImpl(self, fullName));
     }
     return Logger(child);
 }
diff --git a/client/src/logger.h b/client/src/logger.h
index b1700b4..b57dcb2 100644
--- a/client/src/logger.h
+++ b/client/src/logger.h
@@ -22,6 +22,7 @@
 #include <boost/shared_ptr.hpp>
 #include <boost/thread/locks.hpp>
 #include <boost/thread/shared_mutex.hpp>
+#include <boost/weak_ptr.hpp>
 
 #include "System/Logger/LoggerIf.h"
 #include "Level.h"
@@ -161,11 +162,6 @@ public:
     Logger(const std::string& name, LogOut& out, Level logLevel = Debug);
 
     /**
-     * Construct a child Logger.
-     */
-    Logger(const LoggerImpl& parent, const std::string& name);
-
-    /**
      * If true, this Logger would log messages of the given Level.
      *
      * @param level Level to check.
@@ -232,12 +228,14 @@ public:
     /**
      * Construct a root Logger.
      */
-    ASTERISK_SCF_ICEBOX_EXPORT LoggerImpl(const std::string& name, LogOut& out, Level logLevel = Debug);
+    ASTERISK_SCF_ICEBOX_EXPORT LoggerImpl(const std::string& name, LogOut& out,
+        Level logLevel = Debug);
 
     /**
      * Construct a child Logger.
      */
-    ASTERISK_SCF_ICEBOX_EXPORT LoggerImpl(const LoggerImpl& parent, const std::string& name);
+    ASTERISK_SCF_ICEBOX_EXPORT LoggerImpl(
+        const boost::shared_ptr<LoggerImpl>& parent, const std::string& name);
 
     ASTERISK_SCF_ICEBOX_EXPORT ~LoggerImpl();
 
@@ -270,7 +268,8 @@ public:
      */
     ASTERISK_SCF_ICEBOX_EXPORT void vlogf(Level level, char const *fmt, va_list ap) const;
 
-    ASTERISK_SCF_ICEBOX_EXPORT Logger getChild(const std::string& childName);
+    ASTERISK_SCF_ICEBOX_EXPORT Logger getChild(
+        const boost::shared_ptr<LoggerImpl>& self, const std::string& childName);
     ASTERISK_SCF_ICEBOX_EXPORT std::vector<Logger> getChildren() const;
 
     const std::string& getName() const
@@ -314,8 +313,13 @@ private:
     /**
      * Parent pointer.  We cannot change which parent we have, nor can we change
      * our parent.
+     *
+     * This can't be a shared_ptr, because then the circular reference would
+     * cause memory leaks.
+     *
+     * It also can't be a raw pointer, since children can outlive their parents.
      */
-    LoggerImpl const * const mParent;
+    boost::weak_ptr<LoggerImpl const> const mParent;
     typedef std::map<std::string, boost::shared_ptr<LoggerImpl> > Children;
     /**
      * Map of children.  The key is the next final node in that child's name.
@@ -358,11 +362,6 @@ inline Logger::Logger(const std::string& name, LogOut& out, Level logLevel) :
 {
 }
 
-inline Logger::Logger(const LoggerImpl& parent, const std::string& name) :
-    impl(new LoggerImpl(parent, name))
-{
-}
-
 inline bool Logger::isEnabledFor(Level level) const
 {
     return impl->isEnabledFor(level);
@@ -396,7 +395,7 @@ inline void Logger::vlogf(Level level, char const *fmt, va_list ap) const
 }
 inline Logger Logger::getChild(const std::string& childName)
 {
-    return impl->getChild(childName);
+    return impl->getChild(impl, childName);
 }
 inline std::vector<Logger> Logger::getChildren() const
 {

commit 71f2a6e6aec4ba5c50a678a142e44adbff3ccfcb
Author: David M. Lee <dlee at digium.com>
Date:   Fri Dec 10 13:49:00 2010 -0600

    Added reference counting to Logger.
    
    Improved confidence in using the Logger by making Logger instances
    reference counted.  This is almost source compatible, with the only
    change to users is that getLogger() now returns a Logger instance rather
    than a Logger&.

diff --git a/client/src/Logger.cpp b/client/src/Logger.cpp
index 54b6c74..ae74361 100644
--- a/client/src/Logger.cpp
+++ b/client/src/Logger.cpp
@@ -62,29 +62,29 @@ void LogBuf::sendBuffer()
     mOut.logs(nName, mLogLevel, message);
 }
 
-Logger::Logger(const std::string& name, LogOut& out, Level logLevel) :
+Logger::LoggerImpl::LoggerImpl(const std::string& name, LogOut& out, Level logLevel) :
     mParent(0), mName(name), mOut(&out), mLogLevel(logLevel), mInheritedLevel(false)
 {
 }
 
-Logger::Logger(const Logger& parent, const std::string& name) :
-    mParent(&parent), mName(name), mOut(parent.mOut), mLogLevel(Off), mInheritedLevel(
-        true)
+Logger::LoggerImpl::LoggerImpl(const LoggerImpl& parent, const std::string& name) :
+    mParent(&parent), mName(name), mOut(parent.mOut), mLogLevel(Off),
+    mInheritedLevel(true)
 {
     // our name must begin w/ parent's name
     assert(name.find(parent.mName) == 0);
 }
 
-Logger::~Logger()
+Logger::LoggerImpl::~LoggerImpl()
 {
 }
 
-CondStream Logger::operator()(Level level) const
+CondStream Logger::LoggerImpl::operator()(Level level) const
 {
     return CondStream(*mOut, mName, level, isEnabledFor(level));
 }
 
-void Logger::logs(Level level, const std::string& message) const
+void Logger::LoggerImpl::logs(Level level, const std::string& message) const
 {
     if (isEnabledFor(level))
     {
@@ -92,23 +92,7 @@ void Logger::logs(Level level, const std::string& message) const
     }
 }
 
-void Logger::logf(Level level, char const *fmt, ...) const
-{
-    va_list ap;
-    va_start(ap, fmt);
-    try
-    {
-        vlogf(level, fmt, ap);
-    }
-    catch(...)
-    {
-        va_end(ap);
-        throw;
-    }
-    va_end(ap);
-}
-
-void Logger::vlogf(Level level, char const *fmt, va_list ap) const
+void Logger::LoggerImpl::vlogf(Level level, char const *fmt, va_list ap) const
 {
     if (isEnabledFor(level))
     {
@@ -118,7 +102,7 @@ void Logger::vlogf(Level level, char const *fmt, va_list ap) const
     }
 }
 
-void Logger::setOutput(LogOut& out)
+void Logger::LoggerImpl::setOutput(LogOut& out)
 {
     this->mOut = &out;
     boost::lock_guard<boost::mutex> childLock(mChildrenMutex);
@@ -131,21 +115,21 @@ void Logger::setOutput(LogOut& out)
 }
 
 
-void Logger::setLevel(Level logLevel)
+void Logger::LoggerImpl::setLevel(Level logLevel)
 {
     boost::unique_lock<boost::shared_mutex> lock(mLevelMutex);
     mLogLevel = logLevel;
     mInheritedLevel = false;
 }
 
-void Logger::unsetLevel()
+void Logger::LoggerImpl::unsetLevel()
 {
     boost::unique_lock<boost::shared_mutex> lock(mLevelMutex);
     mInheritedLevel = true;
     mLogLevel = Off;
 }
 
-Level Logger::getEffectiveLevel() const
+Level Logger::LoggerImpl::getEffectiveLevel() const
 {
     boost::shared_lock<boost::shared_mutex> lock(mLevelMutex);
     // if our level is unset, inherit level from our parent.
@@ -159,24 +143,24 @@ Level Logger::getEffectiveLevel() const
     }
 }
 
-Logger& Logger::getChild(const std::string& childName)
+Logger Logger::LoggerImpl::getChild(const std::string& childName)
 {
     boost::lock_guard<boost::mutex> childLock(mChildrenMutex);
 
     // ref to ptr allows us to update the map in-place
-    boost::shared_ptr<Logger>& child = mChildren[childName];
+    boost::shared_ptr<LoggerImpl>& child = mChildren[childName];
     if (child == 0)
     {
         std::string fullName = getName().empty() ? childName : getName() + "."
             + childName;
-        child.reset(new Logger(*this, fullName));
+        child.reset(new LoggerImpl(*this, fullName));
     }
-    return *child;
+    return Logger(child);
 }
 
-std::vector<boost::shared_ptr<const Logger> > Logger::getChildren() const
+std::vector<Logger> Logger::LoggerImpl::getChildren() const
 {
-    std::vector<boost::shared_ptr<const Logger> > r;
+    std::vector<Logger> r;
     boost::lock_guard<boost::mutex> childLock(mChildrenMutex);
     for (Children::const_iterator i = mChildren.begin();
          i != mChildren.end();
diff --git a/client/src/LoggerFactory.cpp b/client/src/LoggerFactory.cpp
index 81e349b..0b1e845 100644
--- a/client/src/LoggerFactory.cpp
+++ b/client/src/LoggerFactory.cpp
@@ -55,7 +55,7 @@ LoggerFactory::LoggerFactory(LogOut& out) :
 {
 }
 
-Logger& LoggerFactory::getLogger(const std::string& name)
+Logger LoggerFactory::getLogger(const std::string& name)
 {
     std::vector<std::string> path;
     // older versions of boost output a single entry when splitting an empty
@@ -65,13 +65,13 @@ Logger& LoggerFactory::getLogger(const std::string& name)
         split(path, name, std::bind1st(std::equal_to<char>(), '.'));
     }
 
-    Logger *logger = &mRoot;
+    Logger logger = mRoot;
     for (std::vector<std::string>::iterator i = path.begin(); i != path.end(); ++i)
     {
-        logger = &logger->getChild(*i);
+        logger = logger.getChild(*i);
     }
 
-    return *logger;
+    return logger;
 }
 
 std::vector<std::string> LoggerFactory::getLoggerNames() const
@@ -81,16 +81,16 @@ std::vector<std::string> LoggerFactory::getLoggerNames() const
     return r;
 }
 
-void LoggerFactory::accumulateLoggerNames(const Logger& logger,
+void LoggerFactory::accumulateLoggerNames(Logger logger,
     std::vector<std::string>& out)
 {
     out.push_back(logger.getName());
     // recurse through the children
-    const std::vector<boost::shared_ptr<const Logger> >& children = logger.getChildren();
-    for (std::vector<boost::shared_ptr<const Logger> >::const_iterator i = children.begin(); i
+    const std::vector<Logger>& children = logger.getChildren();
+    for (std::vector<Logger>::const_iterator i = children.begin(); i
              != children.end(); ++i)
     {
-        accumulateLoggerNames(**i, out);
+        accumulateLoggerNames(*i, out);
     }
 }
 
diff --git a/client/src/logger.h b/client/src/logger.h
index 1e94b62..b1700b4 100644
--- a/client/src/logger.h
+++ b/client/src/logger.h
@@ -138,22 +138,108 @@ inline CondStream& CondStream::operator<<(std::ostream& (*pf)(std::ostream&))
 }
 
 /**
- * The Logger for a particular source, identified by the given name.
+ * The Logger for a particular source, identified by the given name.  This is a
+ * small wrapper class, which should be passed around by copy.
  */
 class Logger
 {
+    // You may wonder why have this class at all.  It only delegates to
+    // LoggerImpl, so why not typedef shared_ptr<LoggerImpl> LoggerPtr
+    // and use that?  The problem with that approach is that we would lose
+    // the stream style debugging, or at least may it a bit more cumbersome.
+    //   (*lg)(Debug)      << "you'd have to dereference the smart pointer"
+    //   lg->stream(Debug) << "or have a named function"
+private:
+    /** Implementation class */
+    class LoggerImpl;
+public:
+    /** Construct a Logger for an existing implementation */
+    Logger(const boost::shared_ptr<LoggerImpl>& impl);
+    /**
+     * Construct a root Logger.
+     */
+    Logger(const std::string& name, LogOut& out, Level logLevel = Debug);
+
+    /**
+     * Construct a child Logger.
+     */
+    Logger(const LoggerImpl& parent, const std::string& name);
+
+    /**
+     * If true, this Logger would log messages of the given Level.
+     *
+     * @param level Level to check.
+     * @return true if enabled for given level.
+     */
+    bool isEnabledFor(Level level) const;
+
+    /**
+     * Ostream style logging.
+     *
+     * @param level Level for messages sent to this stream.
+     * @return LogStream that logs at the given level.
+     */
+    CondStream operator()(Level level) const;
+
+    /**
+     * Log a single message.
+     */
+    void logs(Level level, const std::string& message) const;
+
+    /**
+     * Log a single printf-formatted message.
+     */
+    void logf(Level level, char const *fmt, ...) const;
+
+    /**
+     * Log a single vprintf-formatted message.
+     */
+    void vlogf(Level level, char const *fmt, va_list ap) const;
+
+    Logger getChild(const std::string& childName);
+
+    std::vector<Logger> getChildren() const;
+
+    const std::string& getName() const;
+
+    LogOut& getOutput() const;
+
+    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.
+     */
+    void setLevel(Level logLevel);
+
+    /**
+     * Changes our logLevel to now inherit from out parent.
+     */
+    void unsetLevel();
+
+    /**
+     * Returns the effective level of this Logger.
+     */
+    Level getEffectiveLevel() const;
+
+private:
+    boost::shared_ptr<LoggerImpl> impl;
+};
+
+class Logger::LoggerImpl
+{
 public:
     /**
      * Construct a root Logger.
      */
-    ASTERISK_SCF_ICEBOX_EXPORT Logger(const std::string& name, LogOut& out, Level logLevel = Debug);
+    ASTERISK_SCF_ICEBOX_EXPORT LoggerImpl(const std::string& name, LogOut& out, Level logLevel = Debug);
 
     /**
      * Construct a child Logger.
      */
-    ASTERISK_SCF_ICEBOX_EXPORT Logger(const Logger& parent, const std::string& name);
+    ASTERISK_SCF_ICEBOX_EXPORT LoggerImpl(const LoggerImpl& parent, const std::string& name);
 
-    ASTERISK_SCF_ICEBOX_EXPORT ~Logger();
+    ASTERISK_SCF_ICEBOX_EXPORT ~LoggerImpl();
 
     /**
      * If true, this Logger would log messages of the given Level.
@@ -180,29 +266,19 @@ public:
     ASTERISK_SCF_ICEBOX_EXPORT void logs(Level level, const std::string& message) const;
 
     /**
-     * Log a single printf-formatted message.
-     */
-    ASTERISK_SCF_ICEBOX_EXPORT void logf(Level level, char const *fmt, ...) const;
-
-    /**
      * Log a single vprintf-formatted message.
      */
     ASTERISK_SCF_ICEBOX_EXPORT void vlogf(Level level, char const *fmt, va_list ap) const;
 
-    Logger const *getParent() const
-    {
-        return mParent;
-    }
+    ASTERISK_SCF_ICEBOX_EXPORT Logger getChild(const std::string& childName);
+    ASTERISK_SCF_ICEBOX_EXPORT std::vector<Logger> getChildren() const;
 
-    ASTERISK_SCF_ICEBOX_EXPORT Logger& getChild(const std::string& childName);
-    ASTERISK_SCF_ICEBOX_EXPORT std::vector<boost::shared_ptr<const Logger> > getChildren() const;
-
-    ASTERISK_SCF_ICEBOX_EXPORT const std::string& getName() const
+    const std::string& getName() const
     {
         return mName;
     }
 
-    ASTERISK_SCF_ICEBOX_EXPORT LogOut& getOutput() const
+    LogOut& getOutput() const
     {
         return *mOut;
     }
@@ -227,8 +303,8 @@ public:
 
 private:
     // non-copyable
-    Logger(const Logger&);
-    const Logger& operator=(const Logger&);
+    LoggerImpl(const Logger&);
+    const LoggerImpl& operator=(const LoggerImpl&);
 
     /**
      * Mutex for access to the children field.
@@ -239,8 +315,8 @@ private:
      * Parent pointer.  We cannot change which parent we have, nor can we change
      * our parent.
      */
-    Logger const * const mParent;
-    typedef std::map<std::string, boost::shared_ptr<Logger> > Children;
+    LoggerImpl const * const mParent;
+    typedef std::map<std::string, boost::shared_ptr<LoggerImpl> > Children;
     /**
      * Map of children.  The key is the next final node in that child's name.
      */
@@ -270,6 +346,87 @@ private:
     bool mInheritedLevel;
 };
 
+// since these are all simple delegates to LoggerImpl, inline them
+
+inline Logger::Logger(const boost::shared_ptr<LoggerImpl>& impl) :
+    impl(impl)
+{
+}
+
+inline Logger::Logger(const std::string& name, LogOut& out, Level logLevel) :
+    impl(new LoggerImpl(name, out, logLevel))
+{
+}
+
+inline Logger::Logger(const LoggerImpl& parent, const std::string& name) :
+    impl(new LoggerImpl(parent, name))
+{
+}
+
+inline bool Logger::isEnabledFor(Level level) const
+{
+    return impl->isEnabledFor(level);
+}
+inline CondStream Logger::operator()(Level level) const
+{
+    return (*impl)(level);
+}
+inline void Logger::logs(Level level, const std::string& message) const
+{
+    impl->logs(level, message);
+}
+inline void Logger::logf(Level level, char const *fmt, ...) const
+{
+    va_list ap;
+    va_start(ap, fmt);
+    try
+    {
+        impl->vlogf(level, fmt, ap);
+    }
+    catch(...)
+    {
+        va_end(ap);
+        throw;
+    }
+    va_end(ap);
+}
+inline void Logger::vlogf(Level level, char const *fmt, va_list ap) const
+{
+    impl->vlogf(level, fmt, ap);
+}
+inline Logger Logger::getChild(const std::string& childName)
+{
+    return impl->getChild(childName);
+}
+inline std::vector<Logger> Logger::getChildren() const
+{
+    return impl->getChildren();
+}
+inline const std::string& Logger::getName() const
+{
+    return impl->getName();
+}
+inline LogOut& Logger::getOutput() const
+{
+    return impl->getOutput();
+}
+inline void Logger::setOutput(LogOut& out)
+{
+    impl->setOutput(out);
+}
+inline void Logger::setLevel(Level logLevel)
+{
+    impl->setLevel(logLevel);
+}
+inline void Logger::unsetLevel()
+{
+    impl->unsetLevel();
+}
+inline Level Logger::getEffectiveLevel() const
+{
+    return impl->getEffectiveLevel();
+}
+
 /**
  * Main entry point into the Logger system.
  */
@@ -286,7 +443,7 @@ public:
      * @return Ref to the Logger.
      * @thread-safe
      */
-    ASTERISK_SCF_ICEBOX_EXPORT Logger& getLogger(const std::string& name);
+    ASTERISK_SCF_ICEBOX_EXPORT Logger getLogger(const std::string& name);
 
     /**
      * Returns a vector of the names of all currently configured Logger's.
@@ -299,7 +456,7 @@ public:
 private:
     Logger mRoot;
 
-    static void accumulateLoggerNames(const Logger& logger, std::vector<std::string>& out);
+    static void accumulateLoggerNames(Logger logger, std::vector<std::string>& out);
 };
 
 ASTERISK_SCF_ICEBOX_EXPORT boost::shared_ptr<LogOut> buildOstreamLogger(std::ostream& out);
diff --git a/client/test/LoggerFactory-test.cpp b/client/test/LoggerFactory-test.cpp
index 8d6c3cb..160b814 100644
--- a/client/test/LoggerFactory-test.cpp
+++ b/client/test/LoggerFactory-test.cpp
@@ -23,28 +23,16 @@ using namespace AsteriskSCF::System::Logging;
 
 BOOST_AUTO_TEST_SUITE(LoggerFactoryTest)
 
-BOOST_AUTO_TEST_CASE(testGetDistinct)
-{
-    std::stringstream tmp;
-    boost::shared_ptr<LogOut> logOut = buildOstreamLogger(tmp);
-    LoggerFactory uut(*logOut);
-
-    const Logger& asteriskScf = uut.getLogger("AsteriskSCF");
-    const Logger& core = uut.getLogger("AsteriskSCF.Core");
-
-    BOOST_CHECK_NE(&core, &asteriskScf);
-    BOOST_CHECK_EQUAL(&asteriskScf, core.getParent());
-    BOOST_CHECK_EQUAL(&uut.getLogger(""), asteriskScf.getParent());
-}
-
 BOOST_AUTO_TEST_CASE(testInheritence_off)
 {
     std::stringstream actual;
     boost::shared_ptr<LogOut> logOut = buildOstreamLogger(actual);
     LoggerFactory uut(*logOut);
 
-    Logger& root = uut.getLogger("");
-    Logger& asteriskScf = uut.getLogger("AsteriskSCF");
+    Logger root = uut.getLogger("");
+    Logger asteriskScf = uut.getLogger("AsteriskSCF");
+
+    root = asteriskScf;
 
     root.setLevel(Off);
 
@@ -58,8 +46,8 @@ BOOST_AUTO_TEST_CASE(testInheritence_on)
     boost::shared_ptr<LogOut> logOut = buildOstreamLogger(actual);
     LoggerFactory uut(*logOut);
 
-    Logger& root = uut.getLogger("");
-    Logger& asteriskScf = uut.getLogger("AsteriskSCF");
+    Logger root = uut.getLogger("");
+    Logger asteriskScf = uut.getLogger("AsteriskSCF");
 
     root.setLevel(Debug);
 
@@ -81,8 +69,6 @@ BOOST_AUTO_TEST_CASE(testChangeLogOut)
     uut.logs(Debug, "Debug Message");
     out1.check();
     out2.check();
-
-
 }
 
 BOOST_AUTO_TEST_SUITE_END()

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


-- 
asterisk-scf/release/logger.git



More information about the asterisk-scf-commits mailing list