[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
Fri Sep 24 17:20:14 CDT 2010


branch "master" has been updated
       via  83bb32fe76d77fb9fde339d8d54f6bfa6e7bdff3 (commit)
       via  2c3a265e493b031a3f3e1691324d01d84afb77c6 (commit)
      from  bc8098b6d7474d80bb183c02acd0af6b30202a61 (commit)

Summary of changes:
 server/src/CMakeLists.txt           |    8 ++++
 server/src/ChainedLogOut.cpp        |   64 +++++++++++++++++++++++++++++++++
 server/src/ChainedLogOut.h          |   66 +++++++++++++++++++++++++++++++++++
 server/src/FileChainedLogOut.cpp    |   40 +++++++++++++++++++++
 server/src/FileChainedLogOut.h      |   53 ++++++++++++++++++++++++++++
 server/src/LoggingServer.cpp        |   48 ++++++-------------------
 server/src/LoggingServer.h          |   11 ++----
 server/src/OstreamChainedLogOut.cpp |   20 ++++++++++
 server/src/OstreamChainedLogOut.h   |   47 +++++++++++++++++++++++++
 server/src/main.cpp                 |   13 ++++++-
 server/test/CMakeLists.txt          |   13 ++++++-
 11 files changed, 336 insertions(+), 47 deletions(-)
 create mode 100644 server/src/ChainedLogOut.cpp
 create mode 100644 server/src/ChainedLogOut.h
 create mode 100644 server/src/FileChainedLogOut.cpp
 create mode 100644 server/src/FileChainedLogOut.h
 create mode 100644 server/src/OstreamChainedLogOut.cpp
 create mode 100644 server/src/OstreamChainedLogOut.h


- Log -----------------------------------------------------------------
commit 83bb32fe76d77fb9fde339d8d54f6bfa6e7bdff3
Author: David M. Lee <dlee at digium.com>
Date:   Fri Sep 24 17:17:57 2010 -0500

    Server now logging to a file.

diff --git a/server/config/logging-server.conf b/server/config/logging-server.conf
index 5745db4..a601ad9 100644
--- a/server/config/logging-server.conf
+++ b/server/config/logging-server.conf
@@ -9,10 +9,6 @@ ServiceLocatorManagement.Proxy=LocatorServiceManagement:tcp -p 4422
 # A proxy to the IceStorm topic manager
 TopicManager.Proxy=HydraIceStorm/TopicManager:default -p 10000
 
-# output
-#AsteriskSCF.Logging.sink=stdout
-AsteriskSCF.Logging.sink=file:asterisk-scf.log
-
 # Log levels
 AsteriskSCF.Logging.logger=Error
 AsteriskSCF.Logging.logger.AsteriskSCF=Info
\ No newline at end of file
diff --git a/server/src/CMakeLists.txt b/server/src/CMakeLists.txt
index ecd50ec..02198f9 100644
--- a/server/src/CMakeLists.txt
+++ b/server/src/CMakeLists.txt
@@ -16,10 +16,12 @@ hydra_component_add_slice(logging-service ServiceLocatorIf)
 hydra_component_add_file(logging-service ChainedLogOut.cpp)
 hydra_component_add_file(logging-service FileChainedLogOut.cpp)
 hydra_component_add_file(logging-service LoggingServer.cpp)
+hydra_component_add_file(logging-service OstreamChainedLogOut.cpp)
 hydra_component_add_file(logging-service main.cpp)
 
 hydra_component_add_file(logging-service ChainedLogOut.h)
 hydra_component_add_file(logging-service FileChainedLogOut.h)
+hydra_component_add_file(logging-service OstreamChainedLogOut.h)
 hydra_component_add_file(logging-service LoggingServer.h)
 
 hydra_add_ice_libraries(IceStorm)
diff --git a/server/src/ChainedLogOut.cpp b/server/src/ChainedLogOut.cpp
index 7cf04fc..707ad5c 100644
--- a/server/src/ChainedLogOut.cpp
+++ b/server/src/ChainedLogOut.cpp
@@ -56,7 +56,7 @@ std::ostream &ChainedLogOut::logs(std::ostream &out, std::string const &name,
    {
       std::ostream::fmtflags flags = out.flags();
       out << getCurrentTime() << ' ' << std::setw(9) << logLevel << ' '
-         << std::setw(9) << std::left << lastname << ' ' << message << '\n';
+         << std::setw(9) << std::left << lastname << ' ' << message << std::endl;
       out.flags(flags);
    }
    return out;
diff --git a/server/src/FileChainedLogOut.cpp b/server/src/FileChainedLogOut.cpp
index 4c9f1a1..4732916 100644
--- a/server/src/FileChainedLogOut.cpp
+++ b/server/src/FileChainedLogOut.cpp
@@ -22,13 +22,13 @@ void FileChainedLogOut::myLogs(std::string const &name, Level logLevel,
    std::string const &message)
 {
    IceUtil::Mutex::Lock lock(fileMutex);
-   if (!out)
+   if (!out || !out.is_open())
    {
       // reopen the file
       out.open(logFile.c_str());
    }
 
-   if (out)
+   if (out && out.is_open())
    {
       logs(out, name, logLevel, message);
    }
diff --git a/server/src/FileChainedLogOut.h b/server/src/FileChainedLogOut.h
index 964eca5..7054b3c 100644
--- a/server/src/FileChainedLogOut.h
+++ b/server/src/FileChainedLogOut.h
@@ -28,7 +28,7 @@ public:
       ChainedLogOut(), logFile(logFile)
    {
    }
-   FileChainedLogOut(std::string const &out, std::auto_ptr<ChainedLogOut> next) :
+   FileChainedLogOut(std::string const &logFile, std::auto_ptr<ChainedLogOut> next) :
       ChainedLogOut(next), logFile(logFile)
    {
    }
diff --git a/server/src/LoggingServer.cpp b/server/src/LoggingServer.cpp
index 9c873aa..07c81f6 100644
--- a/server/src/LoggingServer.cpp
+++ b/server/src/LoggingServer.cpp
@@ -131,10 +131,11 @@ bool LoggingServerI::isSubpathOf(std::string const &path,
 
 // <prefix>.logger=level
 // <prefix>.logger.<name>=level
-void LoggingServerI::configure(
+void LoggingServerI::configure(std::auto_ptr<ChainedLogOut> out,
    ServerConfigurationListenerPrx configurationListener,
    Ice::PropertiesPtr props)
 {
+   this->out = out;
    this->configurationListener = configurationListener;
 
    Ice::PropertyDict myProps = props->getPropertiesForPrefix(
diff --git a/server/src/LoggingServer.h b/server/src/LoggingServer.h
index 8f035ec..5f2ea2a 100644
--- a/server/src/LoggingServer.h
+++ b/server/src/LoggingServer.h
@@ -68,7 +68,7 @@ public:
    Level getEffectiveLevel(std::string const &name) const;
    void setLevel(std::string const &name, Level level);
 
-   void configure(ServerConfigurationListenerPrx configurationListener, Ice::PropertiesPtr props);
+   void configure(std::auto_ptr<ChainedLogOut> out, ServerConfigurationListenerPrx configurationListener, Ice::PropertiesPtr props);
 
    static const std::string LoggingPropertyPrefix;
 
diff --git a/server/src/OstreamChainedLogOut.cpp b/server/src/OstreamChainedLogOut.cpp
new file mode 100644
index 0000000..4852865
--- /dev/null
+++ b/server/src/OstreamChainedLogOut.cpp
@@ -0,0 +1,20 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+
+#include <IceUtil/IceUtil.h>
+
+#include "OstreamChainedLogOut.h"
+
+using namespace AsteriskSCF::System::Logging;
+
+void OstreamChainedLogOut::myLogs(std::string const &name, Level logLevel,
+   std::string const &message)
+{
+   IceUtil::Mutex::Lock lock(outMutex);
+   logs(out, name, logLevel, message);
+}
diff --git a/server/src/OstreamChainedLogOut.h b/server/src/OstreamChainedLogOut.h
new file mode 100644
index 0000000..8b422d2
--- /dev/null
+++ b/server/src/OstreamChainedLogOut.h
@@ -0,0 +1,47 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+
+#pragma once
+
+#include <IceUtil/IceUtil.h>
+
+#include <ostream>
+
+#include "ChainedLogOut.h"
+
+namespace AsteriskSCF
+{
+namespace System
+{
+namespace Logging
+{
+
+class OstreamChainedLogOut : public ChainedLogOut
+{
+public:
+   OstreamChainedLogOut(std::ostream &out) :
+      ChainedLogOut(), out(out)
+   {
+   }
+   OstreamChainedLogOut(std::ostream &out, std::auto_ptr<ChainedLogOut> next) :
+      ChainedLogOut(next), out(out)
+   {
+   }
+
+protected:
+   void myLogs(std::string const &name, Level logLevel,
+      std::string const &message);
+
+private:
+   IceUtil::Mutex outMutex;
+   std::ostream &out;
+};
+
+} // Logging
+} // System
+} // AsteriskSCF
diff --git a/server/src/main.cpp b/server/src/main.cpp
index 9abb626..60664ec 100644
--- a/server/src/main.cpp
+++ b/server/src/main.cpp
@@ -13,13 +13,16 @@
 #include "Core/Discovery/ServiceLocatorIf.h"
 
 #include "LoggingServer.h"
+#include "FileChainedLogOut.h"
+#include "OstreamChainedLogOut.h"
 
 using namespace AsteriskSCF::System::Logging;
 using namespace AsteriskSCF::Core::Discovery::V1;
 
 namespace
 {
-static const std::string AdapterName = "AsteriskSCF.LoggingService";
+const std::string AdapterName = "AsteriskSCF.LoggingService";
+const std::string LogFileName = "asterisk-scf.log";
 
 class LoggingServerDaemon : public Ice::Service
 {
@@ -131,8 +134,14 @@ bool LoggingServerDaemon::start(int argc, char *argv[], int &status)
       std::clog << e.what() << '\n';
    }
 
+   std::auto_ptr<ChainedLogOut> logOut(new FileChainedLogOut(LogFileName));
+   if (std::cout)
+   {
+      // only append stdout if cout is open.
+      logOut.reset(new OstreamChainedLogOut(std::cout, logOut));
+   }
    IceUtil::Handle<LoggingServerI> server = new LoggingServerI;
-   server->configure(ServerConfigurationListenerPrx(),
+   server->configure(logOut, configurationListener,
       communicator()->getProperties());
 
    LoggingServerPrx serverProxy = LoggingServerPrx::uncheckedCast(
diff --git a/server/test/CMakeLists.txt b/server/test/CMakeLists.txt
index 349e27a..cbaa25b 100644
--- a/server/test/CMakeLists.txt
+++ b/server/test/CMakeLists.txt
@@ -15,10 +15,12 @@ hydra_component_add_slice(logging-service-test LoggerIf)
 
 hydra_component_add_file(logging-service-test ../src/ChainedLogOut.cpp)
 hydra_component_add_file(logging-service-test ../src/FileChainedLogOut.cpp)
+hydra_component_add_file(logging-service-test ../src/OstreamChainedLogOut.cpp)
 hydra_component_add_file(logging-service-test ../src/LoggingServer.cpp)
 
 hydra_component_add_file(logging-service-test ../src/ChainedLogOut.h)
 hydra_component_add_file(logging-service-test ../src/FileChainedLogOut.h)
+hydra_component_add_file(logging-service-test ../src/OstreamChainedLogOut.h)
 hydra_component_add_file(logging-service-test ../src/LoggingServer.h)
 
 hydra_component_add_file(logging-service-test LoggingServer-test.cpp)

commit 2c3a265e493b031a3f3e1691324d01d84afb77c6
Author: David M. Lee <dlee at digium.com>
Date:   Fri Sep 24 16:50:32 2010 -0500

    Close to configurable server log outputs.

diff --git a/server/config/logging-server.conf b/server/config/logging-server.conf
index a601ad9..5745db4 100644
--- a/server/config/logging-server.conf
+++ b/server/config/logging-server.conf
@@ -9,6 +9,10 @@ ServiceLocatorManagement.Proxy=LocatorServiceManagement:tcp -p 4422
 # A proxy to the IceStorm topic manager
 TopicManager.Proxy=HydraIceStorm/TopicManager:default -p 10000
 
+# output
+#AsteriskSCF.Logging.sink=stdout
+AsteriskSCF.Logging.sink=file:asterisk-scf.log
+
 # Log levels
 AsteriskSCF.Logging.logger=Error
 AsteriskSCF.Logging.logger.AsteriskSCF=Info
\ No newline at end of file
diff --git a/server/src/CMakeLists.txt b/server/src/CMakeLists.txt
index fb49ccb..ecd50ec 100644
--- a/server/src/CMakeLists.txt
+++ b/server/src/CMakeLists.txt
@@ -13,9 +13,15 @@ include_directories(../../common)
 hydra_component_add_slice(logging-service LoggerIf)
 hydra_component_add_slice(logging-service ServiceLocatorIf)
 
+hydra_component_add_file(logging-service ChainedLogOut.cpp)
+hydra_component_add_file(logging-service FileChainedLogOut.cpp)
 hydra_component_add_file(logging-service LoggingServer.cpp)
 hydra_component_add_file(logging-service main.cpp)
 
+hydra_component_add_file(logging-service ChainedLogOut.h)
+hydra_component_add_file(logging-service FileChainedLogOut.h)
+hydra_component_add_file(logging-service LoggingServer.h)
+
 hydra_add_ice_libraries(IceStorm)
 
 hydra_component_build_standalone(logging-service)
diff --git a/server/src/ChainedLogOut.cpp b/server/src/ChainedLogOut.cpp
new file mode 100644
index 0000000..7cf04fc
--- /dev/null
+++ b/server/src/ChainedLogOut.cpp
@@ -0,0 +1,64 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+
+#include <iomanip>
+
+#include "ChainedLogOut.h"
+
+using namespace AsteriskSCF::System::Logging;
+
+namespace
+{
+
+/**
+ * Current time, as formatted string.
+ */
+std::string getCurrentTime()
+{
+   char timeBuf[24];
+   time_t now = time(0);
+   strftime(timeBuf, sizeof(timeBuf), "%Y-%m-%d %H:%M:%S %Z", localtime(&now));
+   return timeBuf;
+}
+
+} // namespace
+
+ChainedLogOut::~ChainedLogOut()
+{
+   // no-op
+}
+
+void ChainedLogOut::logs(std::string const &name, Level logLevel,
+   std::string const &message)
+{
+   myLogs(name, logLevel, message);
+   if (next.get())
+   {
+      next->logs(name, logLevel, message);
+   }
+}
+
+std::ostream &ChainedLogOut::logs(std::ostream &out, std::string const &name,
+   Level logLevel, std::string const &message)
+{
+   // date level name(1) message
+   std::string::size_type lastDot = name.rfind('.');
+   if (lastDot == std::string::npos)
+   {
+      lastDot = -1;
+   }
+   std::string lastname = name.substr(lastDot + 1);
+   {
+      std::ostream::fmtflags flags = out.flags();
+      out << getCurrentTime() << ' ' << std::setw(9) << logLevel << ' '
+         << std::setw(9) << std::left << lastname << ' ' << message << '\n';
+      out.flags(flags);
+   }
+   return out;
+
+}
diff --git a/server/src/ChainedLogOut.h b/server/src/ChainedLogOut.h
new file mode 100644
index 0000000..3587671
--- /dev/null
+++ b/server/src/ChainedLogOut.h
@@ -0,0 +1,66 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+
+#pragma once
+
+#include <memory>
+#include "Level.h"
+
+
+#include <iomanip>
+
+namespace AsteriskSCF
+{
+namespace System
+{
+namespace Logging
+{
+
+class ChainedLogOut
+{
+public:
+   ChainedLogOut()
+   {
+   }
+   ChainedLogOut(std::auto_ptr<ChainedLogOut> next) :
+      next(next)
+   {
+   }
+   virtual ~ChainedLogOut();
+
+   /**
+    * Log the message, for me and the next ChainedLogOut.
+    *
+    * @param name Name of the source.
+    * @param logLevel Level of the message.
+    * @param message Message.
+    */
+   void logs(std::string const &name, Level logLevel,
+      std::string const &message);
+
+   /**
+    * Convenient method for logging messages to an ostream, so we have a consistent
+    * format.
+    * @param name Name of the source.
+    * @param logLevel Level of the message.
+    * @param message Message.
+    * @return out
+    */
+   static std::ostream &logs(std::ostream &out, std::string const &name,
+      Level logLevel, std::string const &message);
+
+protected:
+   virtual void myLogs(std::string const &name, Level logLevel,
+      std::string const &message) = 0;
+
+   std::auto_ptr<ChainedLogOut> next;
+};
+
+} // Logging
+} // System
+} // AsteriskSCF
diff --git a/server/src/FileChainedLogOut.cpp b/server/src/FileChainedLogOut.cpp
new file mode 100644
index 0000000..4c9f1a1
--- /dev/null
+++ b/server/src/FileChainedLogOut.cpp
@@ -0,0 +1,40 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+
+#include <IceUtil/IceUtil.h>
+
+#include "FileChainedLogOut.h"
+
+using namespace AsteriskSCF::System::Logging;
+
+void FileChainedLogOut::reopen()
+{
+   IceUtil::Mutex::Lock lock(fileMutex);
+   out.close();
+}
+
+void FileChainedLogOut::myLogs(std::string const &name, Level logLevel,
+   std::string const &message)
+{
+   IceUtil::Mutex::Lock lock(fileMutex);
+   if (!out)
+   {
+      // reopen the file
+      out.open(logFile.c_str());
+   }
+
+   if (out)
+   {
+      logs(out, name, logLevel, message);
+   }
+   else
+   {
+      // error opening the file.  send message to clog.
+      logs(std::clog, name, logLevel, message);
+   }
+}
diff --git a/server/src/FileChainedLogOut.h b/server/src/FileChainedLogOut.h
new file mode 100644
index 0000000..964eca5
--- /dev/null
+++ b/server/src/FileChainedLogOut.h
@@ -0,0 +1,53 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+
+#pragma once
+
+#include <IceUtil/IceUtil.h>
+
+#include <fstream>
+
+#include "ChainedLogOut.h"
+
+namespace AsteriskSCF
+{
+namespace System
+{
+namespace Logging
+{
+
+class FileChainedLogOut : public ChainedLogOut
+{
+public:
+   FileChainedLogOut(std::string const &logFile) :
+      ChainedLogOut(), logFile(logFile)
+   {
+   }
+   FileChainedLogOut(std::string const &out, std::auto_ptr<ChainedLogOut> next) :
+      ChainedLogOut(next), logFile(logFile)
+   {
+   }
+
+   /**
+    * Causes output stream to be closed/reopened.  Used for log rotation.
+    */
+   void reopen();
+
+protected:
+   void myLogs(std::string const &name, Level logLevel,
+      std::string const &message);
+
+private:
+   IceUtil::Mutex fileMutex;
+   const std::string logFile;
+   std::ofstream out;
+};
+
+} // Logging
+} // System
+} // AsteriskSCF
diff --git a/server/src/LoggingServer.cpp b/server/src/LoggingServer.cpp
index f3c72d1..9c873aa 100644
--- a/server/src/LoggingServer.cpp
+++ b/server/src/LoggingServer.cpp
@@ -13,22 +13,6 @@
 
 using namespace AsteriskSCF::System::Logging;
 
-namespace
-{
-
-/**
- * Current time, as formatted string.
- */
-std::string getCurrentTime()
-{
-   char timeBuf[24];
-   time_t now = time(0);
-   strftime(timeBuf, sizeof(timeBuf), "%Y-%m-%d %H:%M:%S %Z", localtime(&now));
-   return timeBuf;
-}
-
-} // namespace
-
 const std::string LoggingServerI::LoggingPropertyPrefix =
    "AsteriskSCF.Logging.";
 const std::string RootLoggerProperty = LoggingServerI::LoggingPropertyPrefix
@@ -87,7 +71,15 @@ void LoggingServerI::logs(std::string const &name, Level level,
 {
    if (isEnabledFor(name, level))
    {
-      reallyLog(name, level, message);
+      if (out.get())
+      {
+         out->logs(name, level, message);
+      }
+      else
+      {
+         // we we don't have a LogOut, send to stderr.
+         ChainedLogOut::logs(std::clog, name, level, message);
+      }
    }
 }
 
@@ -112,25 +104,6 @@ Configuration LoggingServerI::getConfiguration() const
    return r;
 }
 
-void LoggingServerI::reallyLog(std::string const &name, Level level,
-   const std::string &message) const
-{
-   // date level name(1) message
-   std::string::size_type lastDot = name.rfind('.');
-   if (lastDot == std::string::npos)
-   {
-      lastDot = -1;
-   }
-   std::string lastname = name.substr(lastDot + 1);
-   {
-      IceUtil::Mutex::Lock sourcesLock(outputMutex);
-      std::ostream::fmtflags flags = std::cout.flags();
-      std::cout << getCurrentTime() << ' ' << std::setw(9) << level << ' '
-         << std::setw(9) << std::left << lastname << ' ' << message << '\n';
-      std::cout.flags(flags);
-   }
-}
-
 bool LoggingServerI::isSubpathOf(std::string const &path,
    std::string const &subpath)
 {
diff --git a/server/src/LoggingServer.h b/server/src/LoggingServer.h
index 1c2505f..8f035ec 100644
--- a/server/src/LoggingServer.h
+++ b/server/src/LoggingServer.h
@@ -15,6 +15,7 @@
 #include <Ice/Properties.h>
 
 #include "LoggerIf.h"
+#include "ChainedLogOut.h"
 
 namespace AsteriskSCF
 {
@@ -77,11 +78,6 @@ private:
          Sources;
 
    /**
-    * Unconditionally logs the given message.
-    */
-   void reallyLog(std::string const &, Level, const std::string&) const;
-
-   /**
     * Returns true is subpath is a subpath of path.
     *
     * @param path Full path to search.
@@ -91,10 +87,11 @@ private:
    static bool isSubpathOf(std::string const &path, std::string const &subpath);
 
    IceUtil::Mutex sourcesMutex;
-   IceUtil::Mutex outputMutex;
    Sources sources;
 
    ServerConfigurationListenerPrx configurationListener;
+
+   std::auto_ptr<ChainedLogOut> out;
 };
 
 } // Logging
diff --git a/server/test/CMakeLists.txt b/server/test/CMakeLists.txt
index 5bd5dfd..349e27a 100644
--- a/server/test/CMakeLists.txt
+++ b/server/test/CMakeLists.txt
@@ -13,7 +13,16 @@ include_directories(../../common)
 
 hydra_component_add_slice(logging-service-test LoggerIf)
 
-hydra_component_add_file(logging-service-test ../src/LoggingServer.cpp LoggingServer-test.cpp server-test.cpp)
+hydra_component_add_file(logging-service-test ../src/ChainedLogOut.cpp)
+hydra_component_add_file(logging-service-test ../src/FileChainedLogOut.cpp)
+hydra_component_add_file(logging-service-test ../src/LoggingServer.cpp)
+
+hydra_component_add_file(logging-service-test ../src/ChainedLogOut.h)
+hydra_component_add_file(logging-service-test ../src/FileChainedLogOut.h)
+hydra_component_add_file(logging-service-test ../src/LoggingServer.h)
+
+hydra_component_add_file(logging-service-test LoggingServer-test.cpp)
+hydra_component_add_file(logging-service-test server-test.cpp)
 
 hydra_component_build_standalone(logging-service-test)
 

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


-- 
asterisk-scf/integration/logger.git



More information about the asterisk-scf-commits mailing list