Salome HOME
updated copyright message
[modules/kernel.git] / src / Logger / SALOME_Logger_Server.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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, or (at your option) any later version.
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
23 //  SALOME Logger : CORBA server managing trace output
24 //  File   : SALOME_Logger_Server.cxx
25 //  Author : Vasily Rusyaev
26 //  Module : SALOME
27 //
28 #include <iostream>
29 #include "SALOME_Logger_Server.hxx"
30 #include "SALOME_KernelServices.hxx"
31 #include <SALOMEconfig.h>
32 #include <sys/types.h>
33 #ifndef WIN32
34 # include <unistd.h>
35 #endif
36
37 omni_mutex Logger::myLock;
38
39 SALOME_Logger::Logger_ptr KERNEL::getLoggerServantSA()
40 {
41   CORBA::ORB_ptr orb = KERNEL::getORB();
42   CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
43   PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
44   Logger *servant = new Logger;
45   SALOME_Logger::Logger_ptr logger = servant->_this();
46   servant->_remove_ref();
47   return logger;
48 }
49
50 /////////////////////////////////////////////////////////////////////
51 // Construction/Destruction
52 //////////////////////////////////////////////////////////////////////
53
54 Logger::Logger()
55 {
56   m_putIntoFile = false;
57 }
58
59 Logger::Logger(const char *filename)
60 {
61   //  m_outputFile.open( filename, ios::out | ios::trunc , filebuf::openprot);
62   m_outputFile.open( filename, std::ios::out | std::ios::trunc);
63   if (m_outputFile.is_open())
64     m_putIntoFile = true;
65   else
66     m_putIntoFile = false;
67 }
68
69 Logger::~Logger()
70 {
71   if (m_putIntoFile)
72     m_outputFile.close();
73 }
74
75 void Logger::putMessage(const char* message)
76 {
77   myLock.lock();
78   if (m_putIntoFile)
79
80         m_outputFile << message << std::flush;
81   else
82     std::cout << message;
83   myLock.unlock();
84 }
85
86 void Logger::ping()
87 {
88   //cout<<" Logger::ping() pid "<< getpid()<<endl;
89 }