Public Member Functions | Private Member Functions | Private Attributes | List of all members
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]

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)
 
- Public Member Functions inherited from FIX::Log
virtual ~Log ()
 

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().

93 {
94  init( path, path, "GLOBAL" );
95 }
bool m_millisecondsInTimeStamp
Definition: FileLog.h:108
void init(std::string path, std::string backupPath, const std::string &prefix)
Definition: FileLog.cpp:133
FIX::FileLog::FileLog ( const std::string &  path,
const std::string &  backupPath 
)

Definition at line 97 of file FileLog.cpp.

References init().

99 {
100  init( path, backupPath, "GLOBAL" );
101 }
bool m_millisecondsInTimeStamp
Definition: FileLog.h:108
void init(std::string path, std::string backupPath, const std::string &prefix)
Definition: FileLog.cpp:133
FIX::FileLog::FileLog ( const std::string &  path,
const SessionID sessionID 
)

Definition at line 103 of file FileLog.cpp.

References generatePrefix(), and init().

105 {
106  init( path, path, generatePrefix(s) );
107 }
bool m_millisecondsInTimeStamp
Definition: FileLog.h:108
void init(std::string path, std::string backupPath, const std::string &prefix)
Definition: FileLog.cpp:133
std::string generatePrefix(const SessionID &sessionID)
Definition: FileLog.cpp:115
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().

111 {
112  init( path, backupPath, generatePrefix(s) );
113 }
bool m_millisecondsInTimeStamp
Definition: FileLog.h:108
void init(std::string path, std::string backupPath, const std::string &prefix)
Definition: FileLog.cpp:133
std::string generatePrefix(const SessionID &sessionID)
Definition: FileLog.cpp:115
FIX::FileLog::~FileLog ( )
virtual

Definition at line 155 of file FileLog.cpp.

References m_event, and m_messages.

156 {
157  m_messages.close();
158  m_event.close();
159 }
std::ofstream m_messages
Definition: FileLog.h:102
std::ofstream m_event
Definition: FileLog.h:103

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.

171 {
172  m_messages.close();
173  m_event.close();
174 
175  int i = 0;
176  while( true )
177  {
178  std::stringstream messagesFileName;
179  std::stringstream eventFileName;
180 
181  messagesFileName << m_fullBackupPrefix << "messages.backup." << ++i << ".log";
182  eventFileName << m_fullBackupPrefix << "event.backup." << i << ".log";
183  FILE* messagesLogFile = file_fopen( messagesFileName.str().c_str(), "r" );
184  FILE* eventLogFile = file_fopen( eventFileName.str().c_str(), "r" );
185 
186  if( messagesLogFile == NULL && eventLogFile == NULL )
187  {
188  file_rename( m_messagesFileName.c_str(), messagesFileName.str().c_str() );
189  file_rename( m_eventFileName.c_str(), eventFileName.str().c_str() );
190  m_messages.open( m_messagesFileName.c_str(), std::ios::out | std::ios::trunc );
191  m_event.open( m_eventFileName.c_str(), std::ios::out | std::ios::trunc );
192  return;
193  }
194 
195  if( messagesLogFile != NULL ) file_fclose( messagesLogFile );
196  if( eventLogFile != NULL ) file_fclose( eventLogFile );
197  }
198 }
std::ofstream m_messages
Definition: FileLog.h:102
std::string m_eventFileName
Definition: FileLog.h:105
void file_fclose(FILE *file)
Definition: Utility.cpp:497
std::ofstream m_event
Definition: FileLog.h:103
std::string m_fullBackupPrefix
Definition: FileLog.h:107
int file_rename(const char *oldpath, const char *newpath)
Definition: Utility.cpp:523
FILE * file_fopen(const char *path, const char *mode)
Definition: Utility.cpp:486
std::string m_messagesFileName
Definition: FileLog.h:104
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.

162 {
163  m_messages.close();
164  m_event.close();
165 
166  m_messages.open( m_messagesFileName.c_str(), std::ios::out | std::ios::trunc );
167  m_event.open( m_eventFileName.c_str(), std::ios::out | std::ios::trunc );
168 }
std::ofstream m_messages
Definition: FileLog.h:102
std::string m_eventFileName
Definition: FileLog.h:105
std::ofstream m_event
Definition: FileLog.h:103
std::string m_messagesFileName
Definition: FileLog.h:104
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().

116 {
117  const std::string& begin =
118  s.getBeginString().getString();
119  const std::string& sender =
120  s.getSenderCompID().getString();
121  const std::string& target =
122  s.getTargetCompID().getString();
123  const std::string& qualifier =
124  s.getSessionQualifier();
125 
126  std::string prefix = begin + "-" + sender + "-" + target;
127  if( qualifier.size() )
128  prefix += "-" + qualifier;
129 
130  return prefix;
131 }
bool FIX::FileLog::getMillisecondsInTimeStamp ( ) const
inline

Definition at line 93 of file FileLog.h.

References m_millisecondsInTimeStamp.

94  { return m_millisecondsInTimeStamp; }
bool m_millisecondsInTimeStamp
Definition: FileLog.h:108
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().

134 {
135  file_mkdir( path.c_str() );
136  file_mkdir( backupPath.c_str() );
137 
138  if ( path.empty() ) path = ".";
139  if ( backupPath.empty() ) backupPath = path;
140 
142  = file_appendpath(path, prefix + ".");
144  = file_appendpath(backupPath, prefix + ".");
145 
146  m_messagesFileName = m_fullPrefix + "messages.current.log";
147  m_eventFileName = m_fullPrefix + "event.current.log";
148 
149  m_messages.open( m_messagesFileName.c_str(), std::ios::out | std::ios::app );
150  if ( !m_messages.is_open() ) throw ConfigError( "Could not open messages file: " + m_messagesFileName );
151  m_event.open( m_eventFileName.c_str(), std::ios::out | std::ios::app );
152  if ( !m_event.is_open() ) throw ConfigError( "Could not open event file: " + m_eventFileName );
153 }
std::string m_fullPrefix
Definition: FileLog.h:106
std::ofstream m_messages
Definition: FileLog.h:102
std::string file_appendpath(const std::string &path, const std::string &file)
Definition: Utility.cpp:528
std::string m_eventFileName
Definition: FileLog.h:105
std::ofstream m_event
Definition: FileLog.h:103
void file_mkdir(const char *path)
Definition: Utility.cpp:466
std::string m_fullBackupPrefix
Definition: FileLog.h:107
std::string m_messagesFileName
Definition: FileLog.h:104
void FIX::FileLog::onEvent ( const std::string &  value)
inlinevirtual

Implements FIX::Log.

Definition at line 86 of file FileLog.h.

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

87  {
88  UtcTimeStamp now;
90  << " : " << value << std::endl;
91  }
static std::string convert(const UtcTimeStamp &value, bool showMilliseconds=false)
std::ofstream m_event
Definition: FileLog.h:103
bool m_millisecondsInTimeStamp
Definition: FileLog.h:108
void FIX::FileLog::onIncoming ( const std::string &  value)
inlinevirtual

Implements FIX::Log.

Definition at line 82 of file FileLog.h.

References FIX::UtcTimeStampConvertor::convert(), m_messages, m_millisecondsInTimeStamp, and FIX::TYPE::UtcTimeStamp.

83  { m_messages << UtcTimeStampConvertor::convert(UtcTimeStamp(), m_millisecondsInTimeStamp) << " : " << value << std::endl; }
static std::string convert(const UtcTimeStamp &value, bool showMilliseconds=false)
std::ofstream m_messages
Definition: FileLog.h:102
bool m_millisecondsInTimeStamp
Definition: FileLog.h:108
void FIX::FileLog::onOutgoing ( const std::string &  value)
inlinevirtual

Implements FIX::Log.

Definition at line 84 of file FileLog.h.

References FIX::UtcTimeStampConvertor::convert(), m_messages, m_millisecondsInTimeStamp, and FIX::TYPE::UtcTimeStamp.

85  { m_messages << UtcTimeStampConvertor::convert(UtcTimeStamp(), m_millisecondsInTimeStamp) << " : " << value << std::endl; }
static std::string convert(const UtcTimeStamp &value, bool showMilliseconds=false)
std::ofstream m_messages
Definition: FileLog.h:102
bool m_millisecondsInTimeStamp
Definition: FileLog.h:108
void FIX::FileLog::setMillisecondsInTimeStamp ( bool  value)
inline

Definition at line 95 of file FileLog.h.

References m_millisecondsInTimeStamp.

96  { m_millisecondsInTimeStamp = value; }
bool m_millisecondsInTimeStamp
Definition: FileLog.h:108

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().

bool FIX::FileLog::m_millisecondsInTimeStamp
private

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

Generated on Sat Mar 29 2014 15:13:34 for QuickFIX by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2001