[openrtm-commit:02452] r794 - trunk/OpenRTM-aist-Python/OpenRTM_aist

openrtm @ openrtm.org openrtm @ openrtm.org
2017年 2月 17日 (金) 12:56:36 JST


Author: miyamoto
Date: 2017-02-17 12:56:36 +0900 (Fri, 17 Feb 2017)
New Revision: 794

Added:
   trunk/OpenRTM-aist-Python/OpenRTM_aist/LogstreamBase.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/LogstreamFile.py
Modified:
   trunk/OpenRTM-aist-Python/OpenRTM_aist/FactoryInit.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/SystemLogger.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py
Log:
[incompat,newfunc] add LogstreamBase.py and LogstreamFile.py.

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/FactoryInit.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/FactoryInit.py	2017-02-07 06:31:30 UTC (rev 793)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/FactoryInit.py	2017-02-17 03:56:36 UTC (rev 794)
@@ -45,3 +45,4 @@
     OpenRTM_aist.DefaultNumberingPolicyInit()
     OpenRTM_aist.NodeNumberingPolicyInit()
     OpenRTM_aist.NamingServiceNumberingPolicyInit()
+    OpenRTM_aist.LogstreamFileInit()

Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/LogstreamBase.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/LogstreamBase.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/LogstreamBase.py	2017-02-17 03:56:36 UTC (rev 794)
@@ -0,0 +1,187 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+
+##
+# @file LogstreamBase.py
+# @brief Logger stream buffer base class
+# @date $Date: $
+# @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+# Copyright (C) 2017
+#   Nobuhiko Miyamoto
+#   National Institute of
+#      Advanced Industrial Science and Technology (AIST), Japan
+#   All rights reserved.
+# $Id$
+
+
+
+import OpenRTM_aist
+
+
+##
+# @if jp
+# @class LogstreamBase
+#
+# @brief LogstreamBase クラス
+#
+# 
+#
+#
+# @else
+# @class LogstreamBase
+#
+# @brief LogstreamBase class
+#
+#
+# @endif
+#
+class LogstreamBase:
+  """
+  """
+
+  ##
+  # @if jp
+  # @brief コンストラクタ
+  #
+  # コンストラクタ
+  #
+  # @else
+  # @brief Constructor
+  #
+  # Constructor
+  #
+  # @endif
+  #
+  def __init__(self):
+    pass
+
+  ##
+  # @if jp
+  # @brief デストラクタ
+  #
+  # デストラクタ
+  #
+  # @else
+  # @brief Destructor
+  #
+  # Destructor
+  #
+  # @endif
+  #
+  def __del__(self, CorbaConsumer=OpenRTM_aist.CorbaConsumer):
+    pass
+    
+
+
+  ##
+  # @if jp
+  # @brief 設定初期化
+  #
+  # Logstreamクラスの各種設定を行う。実装クラスでは、与えられた
+  # Propertiesから必要な情報を取得して各種設定を行う。
+  #
+  # @param self
+  # @param prop 設定情報
+  # @return
+  #
+  # @else
+  # @brief Initializing configuration
+  #
+  # This operation would be called to configure in initialization.
+  # In the concrete class, configuration should be performed
+  # getting appropriate information from the given Properties data.
+  #
+  # @param self
+  # @param prop Configuration information
+  # @return
+  #
+  # @endif
+  #
+  def init(self, prop):
+    return False
+
+
+  ##
+  # @if jp
+  # @brief 指定文字列をログ出力する
+  #
+  #
+  # @param self
+  # @param msg ログ出力する文字列
+  # @param level ログレベル
+  # @return
+  #
+  # @else
+  # @brief 
+  #
+  #
+  # @param self
+  # @param msg
+  # @param level
+  # @return
+  #
+  # @endif
+  #
+  def log(self, msg, level):
+    return False
+
+
+
+  ##
+  # @if jp
+  # @brief ログレベル設定
+  #
+  #
+  # @param self
+  # @param level ログレベル
+  # @return
+  #
+  # @else
+  # @brief 
+  #
+  #
+  # @param self
+  # @param level
+  # @return
+  #
+  # @endif
+  #
+  def setLogLevel(self, level):
+    pass
+
+
+  ##
+  # @if jp
+  # @brief 終了処理
+  #
+  #
+  # @param self
+  # @return
+  #
+  # @else
+  # @brief 
+  #
+  #
+  # @param self
+  # @return
+  #
+  # @endif
+  #
+  def shutdown(self):
+    return True
+
+
+
+
+logstreamfactory = None
+
+class LogstreamFactory(OpenRTM_aist.Factory):
+  def __init__(self):
+    OpenRTM_aist.Factory.__init__(self)
+  def instance():
+    global logstreamfactory
+    if logstreamfactory is None:
+      logstreamfactory = LogstreamFactory()
+    return logstreamfactory
+  instance = staticmethod(instance)

Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/LogstreamFile.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/LogstreamFile.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/LogstreamFile.py	2017-02-17 03:56:36 UTC (rev 794)
@@ -0,0 +1,305 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+
+##
+# @file LogstreamFile.py
+# @brief File logger stream class
+# @date $Date: $
+# @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+# Copyright (C) 2017
+#   Nobuhiko Miyamoto
+#   National Institute of
+#      Advanced Industrial Science and Technology (AIST), Japan
+#   All rights reserved.
+# $Id$
+
+
+
+import OpenRTM_aist
+import logging
+
+
+
+##
+# @if jp
+# @class LogstreamFile
+#
+# @brief LogstreamFile クラス
+#
+# 
+#
+#
+# @else
+# @class LogstreamFile
+#
+# @brief LogstreamFile class
+#
+#
+# @endif
+#
+class LogstreamFile(OpenRTM_aist.LogstreamBase):
+  """
+  """
+  s_logger = None
+  ##
+  # @if jp
+  # @brief コンストラクタ
+  #
+  # コンストラクタ
+  #
+  # @else
+  # @brief Constructor
+  #
+  # Constructor
+  #
+  # @endif
+  #
+  def __init__(self):
+    OpenRTM_aist.LogstreamBase.__init__(self)
+    self.handlers = []
+
+  ##
+  # @if jp
+  # @brief デストラクタ
+  #
+  # デストラクタ
+  #
+  # @else
+  # @brief Destructor
+  #
+  # Destructor
+  #
+  # @endif
+  #
+  def __del__(self, CorbaConsumer=OpenRTM_aist.CorbaConsumer):
+    pass
+    
+
+
+  ##
+  # @if jp
+  # @brief 設定初期化
+  #
+  # Logstreamクラスの各種設定を行う。実装クラスでは、与えられた
+  # Propertiesから必要な情報を取得して各種設定を行う。
+  #
+  # @param self
+  # @param prop 設定情報
+  # @return
+  #
+  # @else
+  # @brief Initializing configuration
+  #
+  # This operation would be called to configure in initialization.
+  # In the concrete class, configuration should be performed
+  # getting appropriate information from the given Properties data.
+  #
+  # @param self
+  # @param prop Configuration information
+  # @return
+  #
+  # @endif
+  #
+  def init(self, prop):
+    self.logger = logging.getLogger("file")
+    
+    
+    if LogstreamFile.s_logger is None:
+      LogstreamFile.s_logger = self
+      
+      logging.PARANOID  = logging.DEBUG - 3
+      logging.VERBOSE   = logging.DEBUG - 2
+      logging.TRACE     = logging.DEBUG - 1
+      logging.FATAL     = logging.ERROR + 1
+
+      logging.addLevelName(logging.PARANOID,  "PARANOID")
+      logging.addLevelName(logging.VERBOSE,   "VERBOSE")
+      logging.addLevelName(logging.TRACE,     "TRACE")
+      logging.addLevelName(logging.FATAL,     "FATAL")
+      
+    files = prop.getProperty("file_name")
+    files = [s.strip() for s in files.split(",")]
+
+    
+
+    
+
+    for f in files:
+      self.addHandler(f)
+
+    
+        
+    return True
+
+
+  ##
+  # @if jp
+  # @brief ログ出力ハンドラ追加
+  #
+  #
+  # @param self
+  # @param f ログ出力ファイル名、もしくはstdout
+  # @return
+  #
+  # @else
+  # @brief 
+  #
+  #
+  # @param self
+  # @param f 
+  # @return
+  #
+  # @endif
+  #
+  def addHandler(self, f):
+    formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
+    tmp = [f]
+    OpenRTM_aist.eraseHeadBlank(tmp)
+    OpenRTM_aist.eraseTailBlank(tmp)
+    f = tmp[0]
+    handlers = self.logger.handlers
+    for h in handlers:
+      if h.get_name() == f:
+        return False
+
+    tmp = [f]
+    fname = OpenRTM_aist.StringUtil.normalize(tmp)
+      
+    if fname == "stdout":
+      ch = logging.StreamHandler()
+      ch.setLevel(logging.NOTSET)
+      ch.setFormatter(formatter)
+      ch.set_name(f)
+      self.logger.addHandler(ch)
+      self.handlers.append(ch)
+      return True
+
+    else:
+      fhdlr = logging.FileHandler(fname)
+      mhdlr = logging.handlers.MemoryHandler(1024,logging.NOTSET, fhdlr)
+      fhdlr.setFormatter(formatter)
+      mhdlr.set_name(f)
+      self.logger.addHandler(mhdlr)
+      self.handlers.append(mhdlr)
+      self.logger.setLevel(logging.NOTSET)
+      return True
+
+  ##
+  # @if jp
+  # @brief 指定文字列をログ出力する
+  #
+  #
+  # @param self
+  # @param msg ログ出力する文字列
+  # @param level ログレベル
+  # @return
+  #
+  # @else
+  # @brief 
+  #
+  #
+  # @param self
+  # @param msg
+  # @param level
+  # @return
+  #
+  # @endif
+  #
+  def log(self, msg, level):
+    if level == OpenRTM_aist.Logger.FATAL:
+      self.logger.log(logging.FATAL,msg)
+    elif level == OpenRTM_aist.Logger.ERROR:
+      self.logger.error(msg)
+    elif level == OpenRTM_aist.Logger.WARN:
+      self.logger.warning(msg)
+    elif level == OpenRTM_aist.Logger.INFO:
+      self.logger.info(msg)
+    elif level == OpenRTM_aist.Logger.DEBUG:
+      self.logger.debug(msg)
+    elif level == OpenRTM_aist.Logger.TRACE:
+      self.logger.log(logging.TRACE,msg)
+    elif level == OpenRTM_aist.Logger.VERBOSE:
+      self.logger.log(logging.VERBOSE,msg)
+    elif level == OpenRTM_aist.Logger.PARANOID:
+      self.logger.log(logging.PARANOID,msg)
+    else:
+      return False
+      
+    return True
+
+
+  ##
+  # @if jp
+  # @brief ログレベル設定
+  #
+  #
+  # @param self
+  # @param level ログレベル
+  # @return
+  #
+  # @else
+  # @brief 
+  #
+  #
+  # @param self
+  # @param level
+  # @return
+  #
+  # @endif
+  #
+  def setLogLevel(self, level):
+    if level == OpenRTM_aist.Logger.INFO:
+      self.logger.setLevel(logging.INFO)
+    elif level == OpenRTM_aist.Logger.FATAL:
+      self.logger.setLevel(logging.FATAL)
+    elif level == OpenRTM_aist.Logger.ERROR:
+      self.logger.setLevel(logging.ERROR)
+    elif level == OpenRTM_aist.Logger.WARN:
+      self.logger.setLevel(logging.WARNING)
+    elif level == OpenRTM_aist.Logger.DEBUG:
+      self.logger.setLevel(logging.DEBUG)
+    elif level == OpenRTM_aist.Logger.SILENT:
+      self.logger.setLevel(logging.NOTSET)
+    elif level == OpenRTM_aist.Logger.TRACE:
+      self.logger.setLevel(logging.TRACE)
+    elif level == OpenRTM_aist.Logger.VERBOSE:
+      self.logger.setLevel(logging.VERBOSE)
+    elif level == OpenRTM_aist.Logger.PARANOID:
+      self.logger.setLevel(logging.PARANOID)
+    else:
+      self.logger.setLevel(logging.INFO)
+
+
+
+  ##
+  # @if jp
+  # @brief 終了処理
+  #
+  #
+  # @param self
+  # @return
+  #
+  # @else
+  # @brief 
+  #
+  #
+  # @param self
+  # @return
+  #
+  # @endif
+  #
+  def shutdown(self):
+    for h in self.handlers:
+      logging.Handler.close(h)
+    
+    LogstreamFile.s_logger = None
+    self.handlers = []
+    return True
+
+
+def LogstreamFileInit():
+  OpenRTM_aist.LogstreamFactory.instance().addFactory("file",
+                                                      OpenRTM_aist.LogstreamFile,
+                                                      OpenRTM_aist.Delete)
+

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py	2017-02-07 06:31:30 UTC (rev 793)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py	2017-02-17 03:56:36 UTC (rev 794)
@@ -204,10 +204,10 @@
 
       manager = Manager()
       manager.initManager(argv)
+      manager.initFactories()
       manager.initLogger()
       manager.initORB()
       manager.initNaming()
-      manager.initFactories()
       manager.initExecContext()
       manager.initComposite()
       manager.initTimer()
@@ -246,10 +246,10 @@
       guard = OpenRTM_aist.ScopedLock(mutex)
       manager = Manager()
       manager.initManager(None)
+      manager.initFactories()
       manager.initLogger()
       manager.initORB()
       manager.initNaming()
-      manager.initFactories()
       manager.initExecContext()
       manager.initComposite()
       manager.initTimer()
@@ -1444,6 +1444,115 @@
 
   ##
   # @if jp
+  # @brief
+  #
+  # 
+  # 
+  # 
+  #
+  # @param self
+  #
+  #
+  # @else
+  # @brief
+  #
+  # 
+  # 
+  # @param self
+  #
+  # 
+  # @endif
+  def initLogstreamFile(self):
+
+    logprop = self._config.getNode("logger")
+    logstream = OpenRTM_aist.LogstreamFactory.instance().createObject("file")
+
+    if logstream is None:
+      return
+    
+
+    if not logstream.init(logprop):
+      logstream = OpenRTM_aist.LogstreamFactory.instance().deleteObject(logstream)
+      return
+    
+    self._rtcout.addLogger(logstream)
+
+  ##
+  # @if jp
+  # @brief
+  #
+  # 
+  # 
+  # 
+  #
+  # @param self
+  #
+  #
+  # @else
+  # @brief
+  #
+  # 
+  # 
+  # @param self
+  #
+  # 
+  # @endif
+  def initLogstreamPlugins(self):
+    lmod_ = [s.strip() for s in self._config.getProperty("logger.plugins").split(",")]
+    for mod_ in lmod_:
+      if len(mod_) == 0: continue
+      basename_ = mod_.split(".")[0]+"Init"
+      try:
+        self._module.load(mod_, basename_)
+      except:
+        self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
+
+  ##
+  # @if jp
+  # @brief
+  #
+  # 
+  # 
+  # 
+  #
+  # @param self
+  #
+  #
+  # @else
+  # @brief
+  #
+  # 
+  # 
+  # @param self
+  #
+  # 
+  # @endif
+  def initLogstreamOthers(self):
+    factory = OpenRTM_aist.LogstreamFactory.instance()
+    pp = self._config.getNode("logger.logstream")
+
+    leaf0 = pp.getLeaf()
+
+    for l in leaf0:
+      lstype = l.getName()
+      logstream = factory.createObject(lstype)
+      if logstream is None:
+        self._rtcout.RTC_WARN("Logstream %s creation failed."%lstype)
+        continue
+      self._rtcout.RTC_WARN("Logstream %s created."%lstype)
+      if not logstream.init(l):
+        self._rtcout.RTC_WARN("Logstream %s init failed."%lstype)
+      
+        factory.deleteObject(logstream)
+        self._rtcout.RTC_WARN("Logstream %s deleted."%lstype)
+        continue
+      
+      self._rtcout.RTC_INFO("Logstream %s added."%lstype)
+      self._rtcout.addLogger(logstream)
+      
+
+  ##
+  # @if jp
   # @brief System logger の初期化
   #
   # System logger の初期化を実行する。
@@ -1458,39 +1567,17 @@
   # @brief System logger initialization
   # @endif
   def initLogger(self):
-
+    self._rtcout = OpenRTM_aist.LogStream()
     if not OpenRTM_aist.toBool(self._config.getProperty("logger.enable"), "YES", "NO", True):
-      self._rtcout = OpenRTM_aist.LogStream()
       return True
+    
 
-    logfile = "./rtc.log"
-
-    logouts = self._config.getProperty("logger.file_name")
-    logouts = [s.strip() for s in logouts.split(",")]
     
-    self._rtcout = None
+    self.initLogstreamFile()
+    self.initLogstreamPlugins()
+    self.initLogstreamOthers()
+    
 
-    for i in range(len(logouts)):
-      tmp = [logouts[i]]
-      OpenRTM_aist.eraseHeadBlank(tmp)
-      OpenRTM_aist.eraseTailBlank(tmp)
-      logouts[i] = tmp[0]
-      if logouts[i].lower() == "stdout":
-        if self._rtcout is None:
-          self._rtcout = OpenRTM_aist.LogStream("manager","STDOUT")
-        else:
-          self._rtcout.addHandler(logouts[i])
-      else:
-        if logouts[i] == "":
-          logfile = "./rtc.log"
-        else:
-          logfile = logouts[i]
-          
-        if self._rtcout is None:
-          self._rtcout = OpenRTM_aist.LogStream("manager","FILE", logfile)
-        else:
-          self._rtcout.addHandler("FILE",logfile)
-
     self._rtcout.setLogLevel(self._config.getProperty("logger.log_level"))
     self._rtcout.setLogLock(OpenRTM_aist.toBool(self._config.getProperty("logger.stream_lock"),
                                                 "enable", "disable", False))
@@ -1935,7 +2022,7 @@
   # @endif
   #
   def initFactories(self):
-    self._rtcout.RTC_TRACE("Manager.initFactories()")
+    #self._rtcout.RTC_TRACE("Manager.initFactories()")
     OpenRTM_aist.FactoryInit()
     return True
 

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/SystemLogger.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/SystemLogger.py	2017-02-07 06:31:30 UTC (rev 793)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/SystemLogger.py	2017-02-17 03:56:36 UTC (rev 794)
@@ -22,9 +22,9 @@
 import logging.handlers
 import OpenRTM_aist
 
-logger = None
 
 
+
 ##
 # @if jp
 #
@@ -67,7 +67,7 @@
   # @else
   #
   # @endif
-  def strToLogLevel(self, lv):
+  def strToLogLevel(lv):
     if lv == "SILENT":
       return Logger.SILENT
     elif lv == "FATAL":
@@ -89,123 +89,14 @@
     else:
       return Logger.INFO
 
+  strToLogLevel = staticmethod(strToLogLevel)
 
 
-  ##
-  # @if jp
-  #
-  # @brief コンストラクタ
-  #
-  # コンストラクタ
-  #
-  # @param self
-  # @param (mode,file_name,address)
-  #
-  # @else
-  #
-  # @brief constructor.
-  #
-  # @endif
-  def __init__(self, *args):
-    self._mutex = threading.RLock()
-    self._fhdlr = None
 
 
-  def init(*args):
-    global logger
-    
-
-    if logger is not None:
-      return logger
-
-
-    logger = Logger()
-    mode = None
-    fileName = None
-
-    if len(args) == 0:
-      return
-    elif len(args) == 2:
-      #name = args[0]
-      mode = args[1]
-    elif len(args) == 3:
-      #name = args[0]
-      mode = args[1]
-      fileName = args[2]
-
-
-    logging.PARANOID  = logging.DEBUG - 3
-    logging.VERBOSE   = logging.DEBUG - 2
-    logging.TRACE     = logging.DEBUG - 1
-    logging.FATAL     = logging.ERROR + 1
-
-    logging.addLevelName(logging.PARANOID,  "PARANOID")
-    logging.addLevelName(logging.VERBOSE,   "VERBOSE")
-    logging.addLevelName(logging.TRACE,     "TRACE")
-    logging.addLevelName(logging.FATAL,     "FATAL")
-
-    """
-    logging.root.setLevel([logging.NOTSET,
-                           logging.PARANOID,
-                           logging.VERBOSE,
-                           logging.TRACE,
-                           logging.DEBUG,
-                           logging.INFO,
-                           logging.WARNING,
-                           logging.ERROR,
-                           logging.FATAL,
-                           logging.CRITICAL])
-    """
-
-    
-    formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
-
-    if mode is None or mode == "FILE":
-      if fileName:
-        logger._fhdlr = logging.FileHandler(fileName)
-      else:
-        logger._fhdlr = logging.FileHandler('rtcsystem.log')
-
-      mhdlr = logging.handlers.MemoryHandler(1024,logging.NOTSET, logger._fhdlr)
-      logger._fhdlr.setFormatter(formatter)
-      logging.getLogger("").addHandler(mhdlr)
-      logging.getLogger("").setLevel(logging.NOTSET)
-      
-    elif mode == "STDOUT":
-      ch = logging.StreamHandler()
-      ch.setLevel(logging.NOTSET)
-      ch.setFormatter(formatter)
-      logging.getLogger("").addHandler(ch)
-
-    return logger
-
-  init = staticmethod(init)
-
-
-
   ##
   # @if jp
   #
-  # @brief デストラクタ
-  #
-  # デストラクタ。ファイルをクローズする。
-  #
-  # @param self
-  #
-  # @else
-  #
-  # @brief destractor.
-  #
-  # @endif
-  def __del__(self):
-    #if self._fhdlr is not None:
-    #  self._fhdlr.close()
-    #  self._fhdler = None
-    pass
-
-  ##
-  # @if jp
-  #
   # @brief printf フォーマット出力
   #
   # printfライクな書式でログ出力する。<br>
@@ -221,41 +112,12 @@
   # @brief Formatted output like printf
   #
   # @endif
-  def printf(self, fmt):
+  def printf(fmt):
     return fmt
 
+  printf = staticmethod(printf)
 
-  def addHandler(self, *args):
-    mode = None
-    fileName = None
 
-    if len(args) == 0:
-      return
-    elif len(args) == 1:
-      mode = args[0]
-    elif len(args) == 2:
-      mode = args[0]
-      fileName = args[1]
-    
-    formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
-
-    if mode is None or mode == "FILE":
-      if fileName:
-        self._fhdlr = logging.FileHandler(fileName)
-      else:
-        self._fhdlr = logging.FileHandler('rtcsystem.log')
-
-      mhdlr = logging.handlers.MemoryHandler(1024,logging.NOTSET, self._fhdlr)
-      self._fhdlr.setFormatter(formatter)
-      logging.getLogger("").addHandler(mhdlr)
-      
-    elif mode.lower() == "stdout":
-      ch = logging.StreamHandler()
-      ch.setLevel(logging.NOTSET)
-      ch.setFormatter(formatter)
-      logging.getLogger("").addHandler(ch)
-
-
   ##
   # @if jp
   #
@@ -319,14 +181,10 @@
     self._loggerObj = None
     name = ""
 
-    if len(args) == 0:
-      return
-    elif len(args) > 0:
-      name = args[0]
 
-    self._loggerObj = Logger.init(*args)
+    self._mutex = threading.RLock()
+    self._loggerObj = []
     self._log_enable = True
-    self.logger = logging.getLogger(name)
     self.guard = None
 
 
@@ -334,14 +192,16 @@
     return
 
   def shutdown(self):
-    logging.shutdown()
+    for log in self._loggerObj:
+      log.shutdown()
+    self._loggerObj = []
     return
 
-  def addHandler(self, *args):
-    if self._loggerObj is not None:
-      self._loggerObj.addHandler(*args)
+  def addLogger(self, loggerObj):
+    self.acquire()
+    self._loggerObj.append(loggerObj)
+    self.release()
 
-
   ##
   # @if jp
   #
@@ -356,26 +216,11 @@
   #
   # @endif
   def setLogLevel(self, level):
-    if level == "INFO":
-      self.logger.setLevel(logging.INFO)
-    elif level == "FATAL":
-      self.logger.setLevel(logging.FATAL)
-    elif level == "ERROR":
-      self.logger.setLevel(logging.ERROR)
-    elif level == "WARN":
-      self.logger.setLevel(logging.WARNING)
-    elif level == "DEBUG":
-      self.logger.setLevel(logging.DEBUG)
-    elif level == "SILENT":
-      self.logger.setLevel(logging.NOTSET)
-    elif level == "TRACE":
-      self.logger.setLevel(logging.TRACE)
-    elif level == "VERBOSE":
-      self.logger.setLevel(logging.VERBOSE)
-    elif level == "PARANOID":
-      self.logger.setLevel(logging.PARANOID)
-    else:
-      self.logger.setLevel(logging.INFO)
+    lvl = Logger.strToLogLevel(level)
+    for log in self._loggerObj:
+      log.setLogLevel(lvl)
+    
+    
 
 
   ##
@@ -443,7 +288,7 @@
   # @endif
   def acquire(self):
     if self._LogLock:
-      self.guard = OpenRTM_aist.ScopedLock(self._loggerObj._mutex)
+      self.guard = OpenRTM_aist.ScopedLock(self._mutex)
 
 
   ##
@@ -492,9 +337,10 @@
         except:
           print "RTC_LOG : argument error"
           return
+      for log in self._loggerObj:
+        log.log(messages, LV)
+      
 
-      self.logger.log(LV,messages)
-
       self.release()
 
 
@@ -529,7 +375,8 @@
           print "RTC_FATAL : argument error"
           return
 
-      self.logger.log(logging.FATAL,messages)
+      for log in self._loggerObj:
+        log.log(messages, Logger.FATAL)
 
       self.release()
 
@@ -565,7 +412,9 @@
           print "RTC_ERROR : argument error"
           return
 
-      self.logger.error(messages)
+      
+      for log in self._loggerObj:
+        log.log(messages, Logger.ERROR)
 
       self.release()
 
@@ -605,7 +454,9 @@
           print "RTC_WARN : argument error"
           return
 
-      self.logger.warning(messages)
+      
+      for log in self._loggerObj:
+        log.log(messages, Logger.WARN)
 
       self.release()
 
@@ -645,7 +496,9 @@
           print "RTC_INFO : argument error"
           return
 
-      self.logger.info(messages)
+      
+      for log in self._loggerObj:
+        log.log(messages, Logger.INFO)
     
       self.release()
 
@@ -685,8 +538,10 @@
           print "RTC_DEBUG : argument error"
           return
         
-      self.logger.debug(messages)
       
+      for log in self._loggerObj:
+        log.log(messages, Logger.DEBUG)
+      
       self.release()
 
 
@@ -726,7 +581,9 @@
           print "RTC_TRACE : argument error"
           return
 
-      self.logger.log(logging.TRACE,messages)
+      
+      for log in self._loggerObj:
+        log.log(messages, Logger.TRACE)
     
       self.release()
 
@@ -767,7 +624,9 @@
           print "RTC_VERBOSE : argument error"
           return
 
-      self.logger.log(logging.VERBOSE,messages)
+      
+      for log in self._loggerObj:
+        log.log(messages, Logger.VERBOSE)
     
       self.release()
 
@@ -809,8 +668,14 @@
           print "RTC_PARANOID : argument error"
           return
 
-      self.logger.log(logging.PARANOID,messages)
+      
+      for log in self._loggerObj:
+        log.log(messages, Logger.PARANOID)
     
       self.release()
 
 
+
+
+
+

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py	2017-02-07 06:31:30 UTC (rev 793)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py	2017-02-17 03:56:36 UTC (rev 794)
@@ -114,4 +114,7 @@
 from NodeNumberingPolicy import *
 from NamingServiceNumberingPolicy import *
 from CPUAffinity import *
+from LogstreamBase import *
+from LogstreamFile import *
 
+



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