2 //=============================================================================
3 // File : SALOME_Logger.cxx
4 // Created : nov 18 10:28:17 2002
5 // Author : Vasily Rusyaev
6 // Project : SALOME/PRO
7 //=============================================================================
9 // SALOME_Trace.cxx: implementation of the SALOME_Logger class.
11 //////////////////////////////////////////////////////////////////////
13 #include "SALOME_Trace.hxx"
20 //////////////////////////////////////////////////////////////////////
21 // Construction/Destruction
22 //////////////////////////////////////////////////////////////////////
24 SALOME_Trace::SALOME_Trace()
26 //get reference on object reference from NS
27 //and initialize m_pInterfaceLogger
30 char* argv[1] = {"application"};
33 //NB. You can't use SALOME_NamingService class because it uses MESSAGE macro
34 //Otherwise, you will get segmentation fault.
37 CORBA::ORB_var orb = CORBA::ORB_init(argc,argv) ;
38 //Get initial naming context
39 CORBA::Object_var theObj = orb->resolve_initial_references("NameService");
40 //Narrow to NamingContext
41 CosNaming::NamingContext_var inc = CosNaming::NamingContext::_narrow(theObj);
45 name[0].id = CORBA::string_dup("Logger");
47 CORBA::Object_var obj;
48 obj = inc->resolve(name);
50 m_pInterfaceLogger = SALOME_Logger::Logger::_narrow(obj) ;
53 catch (const CosNaming::NamingContext::NotFound&)
55 // cout << "Caught exception: Naming Service can't found Logger";
57 catch (CORBA::COMM_FAILURE&)
59 // cout << "Caught CORBA::SystemException CommFailure.";
61 catch (CORBA::SystemException&)
63 // cout << "Caught CORBA::SystemException.";
65 catch (CORBA::Exception&)
67 // cout << "Caught CORBA::Exception.";
71 // cout << "Caught unknown exception.";
73 //cerr << "-----SALOME_Trace::SALOME_Trace----"<<endl;
76 SALOME_Trace::~SALOME_Trace()
80 SALOME_Trace& SALOME_Trace::Instance()
82 static SALOME_Trace instance;
86 void SALOME_Trace::putMessage(ostream& msg)
88 //write resulting string into Logger CORBA server
89 //concatenate string from passing parameters for transfering into Logger CORBA server
91 //cerr << "-+- " << msg << " ";
93 // CORBA::String_var LogMsg = CORBA::string_dup( str() );
94 //Allow automatic deletion of ostrstream content
96 CORBA::String_var LogMsg = CORBA::string_dup( adt );
97 rdbuf()->freeze(false);
98 //rdbuf()->sync(); // problem with gcc3.2
101 if (CORBA::is_nil(m_pInterfaceLogger))
104 m_pInterfaceLogger-> putMessage (LogMsg) ;