1 // SALOME Logger : CORBA server managing trace output
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SALOME_Logger.cxx
8 // Author : Vasily Rusyaev
12 #include "SALOME_Trace.hxx"
19 //////////////////////////////////////////////////////////////////////
20 // Construction/Destruction
21 //////////////////////////////////////////////////////////////////////
23 SALOME_Trace::SALOME_Trace()
25 //get reference on object reference from NS
26 //and initialize m_pInterfaceLogger
29 char* argv[1] = {"application"};
32 //NB. You can't use SALOME_NamingService class because it uses MESSAGE macro
33 //Otherwise, you will get segmentation fault.
36 CORBA::ORB_var orb = CORBA::ORB_init(argc,argv) ;
37 //Get initial naming context
38 CORBA::Object_var theObj = orb->resolve_initial_references("NameService");
39 //Narrow to NamingContext
40 CosNaming::NamingContext_var inc = CosNaming::NamingContext::_narrow(theObj);
44 name[0].id = CORBA::string_dup("Logger");
46 CORBA::Object_var obj;
47 obj = inc->resolve(name);
49 m_pInterfaceLogger = SALOME_Logger::Logger::_narrow(obj) ;
52 catch (const CosNaming::NamingContext::NotFound&)
54 // cout << "Caught exception: Naming Service can't found Logger";
56 catch (CORBA::COMM_FAILURE&)
58 // cout << "Caught CORBA::SystemException CommFailure.";
60 catch (CORBA::SystemException&)
62 // cout << "Caught CORBA::SystemException.";
64 catch (CORBA::Exception&)
66 // cout << "Caught CORBA::Exception.";
70 // cout << "Caught unknown exception.";
72 //cerr << "-----SALOME_Trace::SALOME_Trace----"<<endl;
75 SALOME_Trace::~SALOME_Trace()
79 SALOME_Trace& SALOME_Trace::Instance()
81 static SALOME_Trace instance;
85 void SALOME_Trace::putMessage(ostream& msg)
87 //write resulting string into Logger CORBA server
88 //concatenate string from passing parameters for transfering into Logger CORBA server
90 //cerr << "-+- " << msg << " ";
92 // CORBA::String_var LogMsg = CORBA::string_dup( str() );
93 //Allow automatic deletion of ostrstream content
95 CORBA::String_var LogMsg = CORBA::string_dup( adt );
96 rdbuf()->freeze(false);
97 //rdbuf()->sync(); // problem with gcc3.2
100 if (CORBA::is_nil(m_pInterfaceLogger))
103 m_pInterfaceLogger-> putMessage (LogMsg) ;