Public Member Functions | Private Member Functions | Private Attributes
FIX::FileLog Class Reference

File based implementation of Log. More...

#include <FileLog.h>

Inheritance diagram for FIX::FileLog:
Inheritance graph
[legend]
Collaboration diagram for FIX::FileLog:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 FileLog (const std::string &path)
 FileLog (const std::string &path, const std::string &backupPath)
 FileLog (const std::string &path, const SessionID &sessionID)
 FileLog (const std::string &path, const std::string &backupPath, const SessionID &sessionID)
virtual ~FileLog ()
void clear ()
void backup ()
void onIncoming (const std::string &value)
void onOutgoing (const std::string &value)
void onEvent (const std::string &value)
bool getMillisecondsInTimeStamp () const
void setMillisecondsInTimeStamp (bool value)

Private Member Functions

std::string generatePrefix (const SessionID &sessionID)
void init (std::string path, std::string backupPath, const std::string &prefix)

Private Attributes

std::ofstream m_messages
std::ofstream m_event
std::string m_messagesFileName
std::string m_eventFileName
std::string m_fullPrefix
std::string m_fullBackupPrefix
bool m_millisecondsInTimeStamp

Detailed Description

File based implementation of Log.

Two files are created by this implementation. One for messages, and one for events.

Definition at line 70 of file FileLog.h.


Constructor & Destructor Documentation

FIX::FileLog::FileLog ( const std::string &  path)

Definition at line 91 of file FileLog.cpp.

References init().

: m_millisecondsInTimeStamp( true )
{
  init( path, path, "GLOBAL" );
}
FIX::FileLog::FileLog ( const std::string &  path,
const std::string &  backupPath 
)

Definition at line 97 of file FileLog.cpp.

References init().

: m_millisecondsInTimeStamp( true )
{
  init( path, backupPath, "GLOBAL" );
}
FIX::FileLog::FileLog ( const std::string &  path,
const SessionID sessionID 
)

Definition at line 103 of file FileLog.cpp.

References generatePrefix(), and init().

: m_millisecondsInTimeStamp( true )
{
  init( path, path, generatePrefix(s) );
}
FIX::FileLog::FileLog ( const std::string &  path,
const std::string &  backupPath,
const SessionID sessionID 
)

Definition at line 109 of file FileLog.cpp.

References generatePrefix(), and init().

: m_millisecondsInTimeStamp( true )
{
  init( path, backupPath, generatePrefix(s) );
}
FIX::FileLog::~FileLog ( ) [virtual]

Definition at line 155 of file FileLog.cpp.

References m_event, and m_messages.

{
  m_messages.close();
  m_event.close();
}

Member Function Documentation

void FIX::FileLog::backup ( ) [virtual]

Implements FIX::Log.

Definition at line 170 of file FileLog.cpp.

References FIX::file_fclose(), FIX::file_fopen(), FIX::file_rename(), m_event, m_eventFileName, m_fullBackupPrefix, m_messages, and m_messagesFileName.

{
  m_messages.close();
  m_event.close();

  int i = 0;
  while( true )
  {
    std::stringstream messagesFileName;
    std::stringstream eventFileName;
 
    messagesFileName << m_fullBackupPrefix << "messages.backup." << ++i << ".log";
    eventFileName << m_fullBackupPrefix << "event.backup." << i << ".log";
    FILE* messagesLogFile = file_fopen( messagesFileName.str().c_str(), "r" );
    FILE* eventLogFile = file_fopen( eventFileName.str().c_str(), "r" );

    if( messagesLogFile == NULL && eventLogFile == NULL )
    {
      file_rename( m_messagesFileName.c_str(), messagesFileName.str().c_str() );
      file_rename( m_eventFileName.c_str(), eventFileName.str().c_str() );
      m_messages.open( m_messagesFileName.c_str(), std::ios::out | std::ios::trunc );
      m_event.open( m_eventFileName.c_str(), std::ios::out | std::ios::trunc );
      return;
    }
    
    if( messagesLogFile != NULL ) file_fclose( messagesLogFile );
    if( eventLogFile != NULL ) file_fclose( eventLogFile );
  }
}
void FIX::FileLog::clear ( ) [virtual]

Implements FIX::Log.

Definition at line 161 of file FileLog.cpp.

References m_event, m_eventFileName, m_messages, and m_messagesFileName.

{
  m_messages.close();
  m_event.close();

  m_messages.open( m_messagesFileName.c_str(), std::ios::out | std::ios::trunc );
  m_event.open( m_eventFileName.c_str(), std::ios::out | std::ios::trunc );
}
std::string FIX::FileLog::generatePrefix ( const SessionID sessionID) [private]

Definition at line 115 of file FileLog.cpp.

References FIX::SessionID::getBeginString(), FIX::SessionID::getSenderCompID(), FIX::SessionID::getSessionQualifier(), and FIX::SessionID::getTargetCompID().

Referenced by FileLog().

{
  const std::string& begin =
    s.getBeginString().getString();
  const std::string& sender =
    s.getSenderCompID().getString();
  const std::string& target =
    s.getTargetCompID().getString();
  const std::string& qualifier =
    s.getSessionQualifier();

  std::string prefix = begin + "-" + sender + "-" + target;
  if( qualifier.size() )
    prefix += "-" + qualifier;

  return prefix;
}

Definition at line 93 of file FileLog.h.

References m_millisecondsInTimeStamp.

void FIX::FileLog::init ( std::string  path,
std::string  backupPath,
const std::string &  prefix 
) [private]

Definition at line 133 of file FileLog.cpp.

References FIX::file_appendpath(), FIX::file_mkdir(), m_event, m_eventFileName, m_fullBackupPrefix, m_fullPrefix, m_messages, and m_messagesFileName.

Referenced by FileLog().

{  
  file_mkdir( path.c_str() );
  file_mkdir( backupPath.c_str() );

  if ( path.empty() ) path = ".";
  if ( backupPath.empty() ) backupPath = path;

  m_fullPrefix
    = file_appendpath(path, prefix + ".");
  m_fullBackupPrefix
    = file_appendpath(backupPath, prefix + ".");

  m_messagesFileName = m_fullPrefix + "messages.current.log";
  m_eventFileName = m_fullPrefix + "event.current.log";

  m_messages.open( m_messagesFileName.c_str(), std::ios::out | std::ios::app );
  if ( !m_messages.is_open() ) throw ConfigError( "Could not open messages file: " + m_messagesFileName );
  m_event.open( m_eventFileName.c_str(), std::ios::out | std::ios::app );
  if ( !m_event.is_open() ) throw ConfigError( "Could not open event file: " + m_eventFileName );
}
void FIX::FileLog::onEvent ( const std::string &  value) [inline, virtual]

Implements FIX::Log.

Definition at line 86 of file FileLog.h.

References FIX::UtcTimeStampConvertor::convert(), m_event, and m_millisecondsInTimeStamp.

  {
    UtcTimeStamp now;
    m_event << UtcTimeStampConvertor::convert( now, m_millisecondsInTimeStamp )
            << " : " << value << std::endl;
  }
void FIX::FileLog::onIncoming ( const std::string &  value) [inline, virtual]
void FIX::FileLog::onOutgoing ( const std::string &  value) [inline, virtual]
void FIX::FileLog::setMillisecondsInTimeStamp ( bool  value) [inline]

Definition at line 95 of file FileLog.h.

References m_millisecondsInTimeStamp.


Member Data Documentation

std::ofstream FIX::FileLog::m_event [private]

Definition at line 103 of file FileLog.h.

Referenced by backup(), clear(), init(), onEvent(), and ~FileLog().

std::string FIX::FileLog::m_eventFileName [private]

Definition at line 105 of file FileLog.h.

Referenced by backup(), clear(), and init().

std::string FIX::FileLog::m_fullBackupPrefix [private]

Definition at line 107 of file FileLog.h.

Referenced by backup(), and init().

std::string FIX::FileLog::m_fullPrefix [private]

Definition at line 106 of file FileLog.h.

Referenced by init().

std::ofstream FIX::FileLog::m_messages [private]

Definition at line 102 of file FileLog.h.

Referenced by backup(), clear(), init(), onIncoming(), onOutgoing(), and ~FileLog().

std::string FIX::FileLog::m_messagesFileName [private]

Definition at line 104 of file FileLog.h.

Referenced by backup(), clear(), and init().


The documentation for this class was generated from the following files:

Generated on Mon Jun 23 2014 23:49:39 for QuickFIX by doxygen 1.7.6.1 written by Dimitri van Heesch, © 1997-2001