[openrtm-commit:00666] r2311 - trunk/OpenRTM-aist/src/lib/rtm

openrtm @ openrtm.org openrtm @ openrtm.org
2012年 2月 7日 (火) 11:48:26 JST


Author: n-ando
Date: 2012-02-07 11:48:25 +0900 (Tue, 07 Feb 2012)
New Revision: 2311

Modified:
   trunk/OpenRTM-aist/src/lib/rtm/SystemLogger.cpp
   trunk/OpenRTM-aist/src/lib/rtm/SystemLogger.h
Log:
[incompat,impl/header,func/bugfix] Now Logger uses a clock from coil::ClockManager to get timestamp for logging. A bug that logger.date_format option has no effect has been fixed. refs #2358


Modified: trunk/OpenRTM-aist/src/lib/rtm/SystemLogger.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/SystemLogger.cpp	2012-02-07 02:09:55 UTC (rev 2310)
+++ trunk/OpenRTM-aist/src/lib/rtm/SystemLogger.cpp	2012-02-07 02:48:25 UTC (rev 2311)
@@ -41,10 +41,21 @@
   Logger::Logger(const char* name)
     : ::coil::LogStream(&(Manager::instance().getLogStreamBuf()),
                         RTL_SILENT, RTL_PARANOID, RTL_SILENT),
-      m_name(name), m_dateFormat("%b %d %H:%M:%S.%Q"),
+      m_name(name),
+      m_dateFormat("%b %d %H:%M:%S.%Q"),
+      m_clock(&coil::ClockManager::instance().getClock("system")),
       m_msEnable(0), m_usEnable(0)
   {
     setLevel(Manager::instance().getLogLevel().c_str());
+    coil::Properties& prop(Manager::instance().getConfig());
+    if (prop.findNode("logger.date_format") != NULL)
+      {
+        setDateFormat(prop["logger.date_foramt"].c_str());
+      }
+    if (prop.findNode("logger.clock_type") != NULL)
+      {
+        setClockType(prop["logger.clock_type"]);
+      }
     m_msEnable = coil::replaceString(m_dateFormat, "%Q", "#m#");
     m_usEnable = coil::replaceString(m_dateFormat, "%q", "#u#");
   }
@@ -52,7 +63,9 @@
   Logger::Logger(LogStreamBuf* streambuf)
     : ::coil::LogStream(streambuf,
                         RTL_SILENT, RTL_PARANOID,  RTL_SILENT),
-      m_name("unknown"), m_dateFormat("%b %d %H:%M:%S.%Q"),
+      m_name("unknown"),
+      m_dateFormat("%b %d %H:%M:%S.%Q"),
+      m_clock(&coil::ClockManager::instance().getClock("system")),
       m_msEnable(0), m_usEnable(0)
   {
     m_msEnable = coil::replaceString(m_dateFormat, "%Q", "#m#");
@@ -89,6 +102,10 @@
     m_usEnable = coil::replaceString(m_dateFormat, "%q", "#u#");
   }
 
+  void Logger::setClockType(std::string clocktype)
+  {
+    m_clock = &coil::ClockManager::instance().getClock(clocktype);
+  }
   /*!
    * @if jp
    * @brief ヘッダの日時の後に付加する文字列を設定する。
@@ -124,7 +141,7 @@
   {
     const int maxsize = 256;
     char buf[maxsize];
-    coil::TimeValue tm(coil::gettimeofday());
+    coil::TimeValue tm(m_clock->gettime());
 
     time_t timer;
     struct tm* date;

Modified: trunk/OpenRTM-aist/src/lib/rtm/SystemLogger.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/SystemLogger.h	2012-02-07 02:09:55 UTC (rev 2310)
+++ trunk/OpenRTM-aist/src/lib/rtm/SystemLogger.h	2012-02-07 02:48:25 UTC (rev 2311)
@@ -23,12 +23,12 @@
 
 // COIL
 #include <coil/Time.h>
+#include <coil/ClockManager.h>
 #include <coil/Logger.h>
 #include <coil/Mutex.h>
 #include <coil/Guard.h>
 #include <coil/stringutil.h>
 
-
 namespace RTC
 {
   typedef ::coil::LogStreamBuffer LogStreamBuf;
@@ -257,10 +257,50 @@
      * @endif
      */
     void setDateFormat(const char* format);
-    
+
     /*!
      * @if jp
      *
+     * @brief ログ記録時に使用するクロックを指定する
+     *
+     * ログ記録時に時刻を取得するためのクロックの種類を指定することができる。
+     * - system: システムクロック。デフォルト
+     * - logical: 論理時間クロック。
+     * - adjusted: 調整済みクロック。
+     *
+     * 論理時間クロックについては
+     * <pre>
+     * coil::ClockManager::instance().getClock("logical").settime()
+     * </pre>
+     * で時刻を設定する必要がある。
+     *
+     * @param clocktype 上述のクロックタイプ
+     *
+     * @else
+     *
+     * @brief Specifying clock type to be used for logging
+     *
+     * This function sets a clock type getting time when it is used
+     * for logging. Available clock types are,
+     * - system: System clock. Default option.
+     * - logical: Logical time clock.
+     * - adjusted: Adjusted clock.
+     *
+     * To use logical time clock, call and set time by the following
+     * function in somewhere.
+     * <pre>
+     * coil::ClockManager::instance().getClock("logical").settime()
+     * </pre>
+     *
+     * @param clocktype A clock type above mentioned
+     *
+     * @endif
+     */
+    void setClockType(std::string clocktype);
+
+    /*!
+     * @if jp
+     *
      * @brief ヘッダの日時の後に付加する文字列を設定する。
      *
      * ヘッダの日時の後に付加する接頭語文字列を設定する。
@@ -339,6 +379,7 @@
   private:
     std::string m_name;
     std::string m_dateFormat;
+    coil::IClock* m_clock;
     static const char* m_levelString[];
     int m_msEnable;
     int m_usEnable;



openrtm-commit メーリングリストの案内