FIX::FileLog Class Reference

File based implementation of Log. More...

`#include <FileLog.h>`

Inheritance diagram for FIX::FileLog:
[legend]
Collaboration diagram for FIX::FileLog:
[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.

{
init( path, path, "GLOBAL" );
}
FIX::FileLog::init
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.

{
init( path, backupPath, "GLOBAL" );
}

References init().

## FileLog() [3/4]

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

Definition at line 101 of file FileLog.cpp.

{
init( path, path, generatePrefix(s) );
}
FIX::FileLog::generatePrefix
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.

{
init( path, backupPath, generatePrefix(s) );
}

References generatePrefix(), and init().

## ~FileLog()

FIX::FileLog::~FileLog | ( |  | ) |

virtual

Definition at line 151 of file FileLog.cpp.

{
m_messages.close();
m_event.close();
}
FIX::FileLog::m_event
std::ofstream m_event
Definition FileLog.h:98
FIX::FileLog::m_messages
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.

{
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 );
}
}
FIX::FileLog::m_eventFileName
std::string m_eventFileName
Definition FileLog.h:100
FIX::FileLog::m_fullBackupPrefix
std::string m_fullBackupPrefix
Definition FileLog.h:102
FIX::FileLog::m_messagesFileName
std::string m_messagesFileName
Definition FileLog.h:99
FIX::file_rename
int file_rename(const char *oldpath, const char *newpath)
Definition Utility.cpp:546
FIX::file_fclose
void file_fclose(FILE *file)
Definition Utility.cpp:520
FIX::file_fopen
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.

{
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 );
}

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.

{
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;
}

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.

{
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 );
}
FIX::FileLog::m_fullPrefix
std::string m_fullPrefix
Definition FileLog.h:101
FIX::file_mkdir
void file_mkdir(const char *path)
Definition Utility.cpp:489
FIX::file_appendpath
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 | ) |

inline virtual

Implements FIX::Log.

Definition at line 86 of file FileLog.h.

{
UtcTimeStamp now;
m_event << UtcTimeStampConvertor::convert( now, 9 )
<< " : " << value << std::endl;
}
FIX::TYPE::UtcTimeStamp
@ UtcTimeStamp
Definition FieldTypes.h:923
FIX::UtcTimeStampConvertor::convert
static std::string convert(const UtcTimeStamp &value, int precision=0)
Definition FieldConvertors.h:434

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

## onIncoming()

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

inline virtual

Implements FIX::Log.

Definition at line 82 of file FileLog.h.

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

inline virtual

Implements FIX::Log.

Definition at line 84 of file FileLog.h.

{ 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:

- FileLog.h
- FileLog.cpp