Index  Source Files  Annotated Class List  Alphabetical Class List  Class Hierarchy  Graphical Class Hierarchy   
 

/home/orenmnero/autobuild/quickfix/src/C++/FileLog.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (c) quickfixengine.org  All rights reserved.
00003 **
00004 ** This file is part of the QuickFIX FIX Engine
00005 **
00006 ** This file may be distributed under the terms of the quickfixengine.org
00007 ** license as defined by quickfixengine.org and appearing in the file
00008 ** LICENSE included in the packaging of this file.
00009 **
00010 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00011 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00012 **
00013 ** See http://www.quickfixengine.org/LICENSE for licensing information.
00014 **
00015 ** Contact ask@quickfixengine.org if any conditions of this licensing are
00016 ** not clear to you.
00017 **
00018 ****************************************************************************/
00019 
00020 #ifdef _MSC_VER
00021 #include "stdafx.h"
00022 #else
00023 #include "config.h"
00024 #endif
00025 #include "CallStack.h"
00026 
00027 #include "FileLog.h"
00028 
00029 namespace FIX
00030 {
00031 Log* FileLogFactory::create()
00032 { QF_STACK_PUSH(FileLogFactory::create)
00033 
00034   m_globalLogCount++;
00035   if( m_globalLogCount > 1 ) return m_globalLog;
00036 
00037   try
00038   {
00039     if ( m_path.size() ) return new FileLog( m_path );
00040     std::string path;
00041     Dictionary settings = m_settings.get();
00042     path = settings.getString( FILE_LOG_PATH );
00043     return m_globalLog = new FileLog( path );
00044   }
00045   catch( ConfigError& )
00046   {
00047         m_globalLogCount--;
00048         throw;  
00049   }
00050 
00051   QF_STACK_POP
00052 }
00053 
00054 Log* FileLogFactory::create( const SessionID& s )
00055 { QF_STACK_PUSH(FileLogFactory::create)
00056 
00057   if ( m_path.size() ) return new FileLog( m_path, s );
00058   std::string path;
00059   Dictionary settings = m_settings.get( s );
00060   path = settings.getString( FILE_LOG_PATH );
00061   return new FileLog( path, s );
00062 
00063   QF_STACK_POP
00064 }
00065 
00066 void FileLogFactory::destroy( Log* pLog )
00067 { QF_STACK_PUSH(FileLogFactory::destroy)
00068  
00069   if( pLog == m_globalLog )
00070   {
00071     m_globalLogCount--;
00072     if( m_globalLogCount == 0 )
00073     {
00074           delete pLog;
00075           m_globalLogCount = 0;
00076     }   
00077   }
00078   else
00079   {
00080         delete pLog;
00081   }
00082 
00083   QF_STACK_POP
00084 }
00085 
00086 FileLog::FileLog( const std::string& path )
00087 {
00088   init( path, "GLOBAL" );
00089 }
00090 
00091 FileLog::FileLog( const std::string& path, const SessionID& s )
00092 {
00093   const std::string& begin =
00094     s.getBeginString().getString();
00095   const std::string& sender =
00096     s.getSenderCompID().getString();
00097   const std::string& target =
00098     s.getTargetCompID().getString();
00099   const std::string& qualifier =
00100     s.getSessionQualifier();
00101 
00102   std::string prefix = begin + "-" + sender + "-" + target;
00103   if( qualifier.size() )
00104     prefix += "-" + qualifier;
00105 
00106   init( path, prefix );
00107 }
00108 
00109 void FileLog::init( std::string path, const std::string& prefix )
00110 { QF_STACK_PUSH(FileLog::init)
00111         
00112   file_mkdir( path.c_str() );
00113 
00114   if ( path.empty() ) path = ".";
00115 
00116   std::string fullPrefix
00117     = file_appendpath(path, prefix + ".");
00118 
00119   m_messagesFileName = fullPrefix + "messages.log";
00120   m_eventFileName = fullPrefix + "event.log";
00121 
00122   m_messages.open( m_messagesFileName.c_str(), std::ios::out | std::ios::app );
00123   if ( !m_messages.is_open() ) throw ConfigError( "Could not open messages file" );
00124   m_event.open( m_eventFileName.c_str(), std::ios::out | std::ios::app );
00125   if ( !m_event.is_open() ) throw ConfigError( "Could not open event file" );
00126 
00127   QF_STACK_POP
00128 }
00129 
00130 FileLog::~FileLog()
00131 {
00132   m_messages.close();
00133   m_event.close();
00134 }
00135 
00136 void FileLog::clear()
00137 {
00138   m_messages.close();
00139   m_event.close();
00140 
00141   m_messages.open( m_messagesFileName.c_str(), std::ios::out | std::ios::trunc );
00142   m_event.open( m_eventFileName.c_str(), std::ios::out | std::ios::trunc );
00143 }
00144 
00145 } //namespace FIX

Generated on Mon Jul 24 19:36:28 2006 for QuickFIX by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2001