Back to index

salome-kernel  6.5.0
SALOME_Trace.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 #  SALOME Logger : CORBA server managing trace output
00025 #  File   : SALOME_Trace.py
00026 #  Module : SALOME
00027 #
00028 import sys
00029 import CosNaming
00030 from omniORB import CORBA
00031 import SALOME_Logger
00032 import time
00033 import os
00034 
00035 trace="local"
00036 if (os.environ.has_key("SALOME_trace")):
00037   if (os.environ["SALOME_trace"] == "with_logger"):
00038     trace="logger"
00039 
00040 class SALOME_Trace :
00041     def __init__(self):
00042         self.m_pInterfaceLogger = None
00043         if trace=="logger":
00044             ok = 0
00045             steps = 40
00046             while steps > 0 and ok == 0:
00047 
00048               try:
00049                 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
00050                 theObj = orb.resolve_initial_references("NameService")
00051                 inc = theObj._narrow(CosNaming.NamingContext)
00052                 name = [CosNaming.NameComponent("Logger","")]
00053                 obj = inc.resolve(name);
00054 
00055                 self.m_pInterfaceLogger = obj._narrow(SALOME_Logger.Logger)
00056 
00057                 if not self.m_pInterfaceLogger is None:
00058                   ok = 1
00059 
00060               except CosNaming.NamingContext.NotFound, e :
00061                     if steps == 1: print "Caught exception: Naming Service can't found Logger"
00062               except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
00063                     if steps == 1: print "Caught CORBA::SystemException CommFailure"
00064               except CORBA.SystemException, e:
00065                     if steps == 1: print "Caught CORBA::SystemException."
00066               except CORBA.Exception, e:
00067                     if steps == 1: print "Caught CORBA::Exception."
00068               except Exception, e:
00069                     if steps == 1: print "Caught unknown exception."
00070 
00071               time.sleep(0.25)
00072               steps = steps - 1
00073 
00074     def putMessage ( self, LogMsg ) :
00075         if (CORBA.is_nil(self.m_pInterfaceLogger)):
00076             print  LogMsg;
00077         else:
00078             self.m_pInterfaceLogger.putMessage (LogMsg)