]> SALOME platform Git repositories - modules/kernel.git/blob - src/Logger/SALOME_Trace.py
Salome HOME
CCAR: move DSC trace function from Calcium directory to DSC_Basic directory
[modules/kernel.git] / src / Logger / SALOME_Trace.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 #  SALOME Logger : CORBA server managing trace output
23 #  File   : SALOME_Trace.py
24 #  Module : SALOME
25 #
26 import sys
27 import CosNaming
28 from omniORB import CORBA
29 import SALOME_Logger
30 import time
31 import os
32
33 trace="local"
34 if (os.environ.has_key("SALOME_trace")):
35   if (os.environ["SALOME_trace"] == "with_logger"):
36     trace="logger"
37
38 class SALOME_Trace :
39     def __init__(self):
40         self.m_pInterfaceLogger = None
41         if trace=="logger":
42             ok = 0
43             steps = 40
44             while steps > 0 and ok == 0:
45
46               try:
47                 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
48                 theObj = orb.resolve_initial_references("NameService")
49                 inc = theObj._narrow(CosNaming.NamingContext)
50                 name = [CosNaming.NameComponent("Logger","")]
51                 obj = inc.resolve(name);
52
53                 self.m_pInterfaceLogger = obj._narrow(SALOME_Logger.Logger)
54
55                 if not self.m_pInterfaceLogger is None:
56                   ok = 1
57
58               except CosNaming.NamingContext.NotFound, e :
59                     if steps == 1: print "Caught exception: Naming Service can't found Logger"
60               except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
61                     if steps == 1: print "Caught CORBA::SystemException CommFailure"
62               except CORBA.SystemException, e:
63                     if steps == 1: print "Caught CORBA::SystemException."
64               except CORBA.Exception, e:
65                     if steps == 1: print "Caught CORBA::Exception."
66               except Exception, e:
67                     if steps == 1: print "Caught unknown exception."
68
69               time.sleep(0.25)
70               steps = steps - 1
71           
72           
73     def putMessage ( self, LogMsg ) :
74         
75         if (CORBA.is_nil(self.m_pInterfaceLogger)):
76             print  LogMsg;
77         else:
78             self.m_pInterfaceLogger.putMessage (LogMsg) 
79