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

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

◆ FileLog() [1/4]

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

Definition at line 91 of file FileLog.cpp.

92{
93 init( path, path, "GLOBAL" );
94}
void init(std::string path, std::string backupPath, const std::string &prefix)
Definition FileLog.cpp:129

References init().

◆ FileLog() [2/4]

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

Definition at line 96 of file FileLog.cpp.

97{
98 init( path, backupPath, "GLOBAL" );
99}

References init().

◆ FileLog() [3/4]

FIX::FileLog::FileLog ( const std::string &  path,
const SessionID sessionID 
)

Definition at line 101 of file FileLog.cpp.

102{
103 init( path, path, generatePrefix(s) );
104}
std::string generatePrefix(const SessionID &sessionID)
Definition FileLog.cpp:111

References generatePrefix(), and init().

◆ FileLog() [4/4]

FIX::FileLog::FileLog ( const std::string &  path,
const std::string &  backupPath,
const SessionID sessionID 
)

Definition at line 106 of file FileLog.cpp.

107{
108 init( path, backupPath, generatePrefix(s) );
109}

References generatePrefix(), and init().

◆ ~FileLog()

FIX::FileLog::~FileLog ( )
virtual

Definition at line 151 of file FileLog.cpp.

152{
153 m_messages.close();
154 m_event.close();
155}
std::ofstream m_event
Definition FileLog.h:98
std::ofstream m_messages
Definition FileLog.h:97

References m_event, and m_messages.

Member Function Documentation

◆ backup()

void FIX::FileLog::backup ( )
virtual

Implements FIX::Log.

Definition at line 166 of file FileLog.cpp.

167{
168 m_messages.close();
169 m_event.close();
170
171 int i = 0;
172 while( true )
173 {
174 std::stringstream messagesFileName;
175 std::stringstream eventFileName;
176
177 messagesFileName << m_fullBackupPrefix << "messages.backup." << ++i << ".log";
178 eventFileName << m_fullBackupPrefix << "event.backup." << i << ".log";
179 FILE* messagesLogFile = file_fopen( messagesFileName.str().c_str(), "r" );
180 FILE* eventLogFile = file_fopen( eventFileName.str().c_str(), "r" );
181
182 if( messagesLogFile == NULL && eventLogFile == NULL )
183 {
184 file_rename( m_messagesFileName.c_str(), messagesFileName.str().c_str() );
185 file_rename( m_eventFileName.c_str(), eventFileName.str().c_str() );
186 m_messages.open( m_messagesFileName.c_str(), std::ios::out | std::ios::trunc );
187 m_event.open( m_eventFileName.c_str(), std::ios::out | std::ios::trunc );
188 return;
189 }
190
191 if( messagesLogFile != NULL ) file_fclose( messagesLogFile );
192 if( eventLogFile != NULL ) file_fclose( eventLogFile );
193 }
194}
std::string m_eventFileName
Definition FileLog.h:100
std::string m_fullBackupPrefix
Definition FileLog.h:102
std::string m_messagesFileName
Definition FileLog.h:99
int file_rename(const char *oldpath, const char *newpath)
Definition Utility.cpp:546
void file_fclose(FILE *file)
Definition Utility.cpp:520
FILE * file_fopen(const char *path, const char *mode)
Definition Utility.cpp:509

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

◆ clear()

void FIX::FileLog::clear ( )
virtual

Implements FIX::Log.

Definition at line 157 of file FileLog.cpp.

158{
159 m_messages.close();
160 m_event.close();
161
162 m_messages.open( m_messagesFileName.c_str(), std::ios::out | std::ios::trunc );
163 m_event.open( m_eventFileName.c_str(), std::ios::out | std::ios::trunc );
164}

References m_event, m_eventFileName, m_messages, and m_messagesFileName.

◆ generatePrefix()

std::string FIX::FileLog::generatePrefix ( const SessionID sessionID)
private

Definition at line 111 of file FileLog.cpp.

112{
113 const std::string& begin =
114 s.getBeginString().getString();
115 const std::string& sender =
116 s.getSenderCompID().getString();
117 const std::string& target =
118 s.getTargetCompID().getString();
119 const std::string& qualifier =
120 s.getSessionQualifier();
121
122 std::string prefix = begin + "-" + sender + "-" + target;
123 if( qualifier.size() )
124 prefix += "-" + qualifier;
125
126 return prefix;
127}

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

Referenced by FileLog(), and FileLog().

◆ init()

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

Definition at line 129 of file FileLog.cpp.

130{
131 file_mkdir( path.c_str() );
132 file_mkdir( backupPath.c_str() );
133
134 if ( path.empty() ) path = ".";
135 if ( backupPath.empty() ) backupPath = path;
136
138 = file_appendpath(path, prefix + ".");
140 = file_appendpath(backupPath, prefix + ".");
141
142 m_messagesFileName = m_fullPrefix + "messages.current.log";
143 m_eventFileName = m_fullPrefix + "event.current.log";
144
145 m_messages.open( m_messagesFileName.c_str(), std::ios::out | std::ios::app );
146 if ( !m_messages.is_open() ) throw ConfigError( "Could not open messages file: " + m_messagesFileName );
147 m_event.open( m_eventFileName.c_str(), std::ios::out | std::ios::app );
148 if ( !m_event.is_open() ) throw ConfigError( "Could not open event file: " + m_eventFileName );
149}
std::string m_fullPrefix
Definition FileLog.h:101
void file_mkdir(const char *path)
Definition Utility.cpp:489
std::string file_appendpath(const std::string &path, const std::string &file)
Definition Utility.cpp:551

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

Referenced by FileLog(), FileLog(), FileLog(), and FileLog().

◆ onEvent()

void FIX::FileLog::onEvent ( const std::string &  value)
inlinevirtual

Implements FIX::Log.

Definition at line 86 of file FileLog.h.

87 {
88 UtcTimeStamp now;
90 << " : " << value << std::endl;
91 }
static std::string convert(const UtcTimeStamp &value, int precision=0)

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

◆ onIncoming()

void FIX::FileLog::onIncoming ( const std::string &  value)
inlinevirtual

Implements FIX::Log.

Definition at line 82 of file FileLog.h.

83 { m_messages << UtcTimeStampConvertor::convert(UtcTimeStamp(), 9) << " : " << value << std::endl; }

References FIX::UtcTimeStampConvertor::convert(), and m_messages.

◆ onOutgoing()

void FIX::FileLog::onOutgoing ( const std::string &  value)
inlinevirtual

Implements FIX::Log.

Definition at line 84 of file FileLog.h.

85 { m_messages << UtcTimeStampConvertor::convert(UtcTimeStamp(), 9) << " : " << value << std::endl; }

References FIX::UtcTimeStampConvertor::convert(), and m_messages.

Member Data Documentation

◆ m_event

std::ofstream FIX::FileLog::m_event
private

Definition at line 98 of file FileLog.h.

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

◆ m_eventFileName

std::string FIX::FileLog::m_eventFileName
private

Definition at line 100 of file FileLog.h.

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

◆ m_fullBackupPrefix

std::string FIX::FileLog::m_fullBackupPrefix
private

Definition at line 102 of file FileLog.h.

Referenced by backup(), and init().

◆ m_fullPrefix

std::string FIX::FileLog::m_fullPrefix
private

Definition at line 101 of file FileLog.h.

Referenced by init().

◆ m_messages

std::ofstream FIX::FileLog::m_messages
private

Definition at line 97 of file FileLog.h.

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

◆ m_messagesFileName

std::string FIX::FileLog::m_messagesFileName
private

Definition at line 99 of file FileLog.h.

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


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

Generated on Mon Mar 4 2024 21:10:02 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001