Back to index

salome-kernel  6.5.0
SALOME_Logger_Server.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME Logger : CORBA server managing trace output
00024 //  File   : SALOME_Logger_Server.cxx
00025 //  Author : Vasily Rusyaev
00026 //  Module : SALOME
00027 //
00028 #include <iostream>
00029 #include "SALOME_Logger_Server.hxx"
00030 #include <SALOMEconfig.h>
00031 #include <sys/types.h>
00032 #ifndef WIN32
00033 # include <unistd.h>
00034 #endif
00035 
00036 #ifdef WIN32
00037 #include <omnithread/pthread_nt.h>
00038 #endif
00039 
00040 omni_mutex Logger::myLock;
00041 
00043 // Construction/Destruction
00045 
00046 Logger::Logger()
00047 {
00048   m_putIntoFile = false;
00049 }
00050 
00051 Logger::Logger(const char *filename)
00052 {
00053   //  m_outputFile.open( filename, ios::out | ios::trunc , filebuf::openprot);
00054   m_outputFile.open( filename, std::ios::out | std::ios::trunc);
00055   if (m_outputFile.is_open())
00056     m_putIntoFile = true;
00057   else
00058     m_putIntoFile = false;
00059 }
00060 
00061 Logger::~Logger()
00062 {
00063   if (m_putIntoFile)
00064     m_outputFile.close();
00065 }
00066 
00067 void Logger::putMessage(const char* message)
00068 {
00069   myLock.lock();
00070   if (m_putIntoFile)
00071 
00072         m_outputFile << message << std::flush;
00073   else
00074     std::cout << message;
00075   myLock.unlock();
00076 }
00077 
00078 void Logger::ping()
00079 {
00080   //cout<<" Logger::ping() pid "<< getpid()<<endl;
00081 }