FileLog.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIX_FILELOG_H
00023 #define FIX_FILELOG_H
00024
00025 #ifdef _MSC_VER
00026 #pragma warning( disable : 4503 4355 4786 4290 )
00027 #endif
00028
00029 #include "Log.h"
00030 #include "SessionSettings.h"
00031 #include <fstream>
00032
00033 namespace FIX
00034 {
00040 class FileLogFactory : public LogFactory
00041 {
00042 public:
00043 FileLogFactory( const SessionSettings& settings )
00044 : m_settings( settings ), m_globalLog(0), m_globalLogCount(0) {};
00045 FileLogFactory( const std::string& path )
00046 : m_path( path ), m_backupPath( path ), m_globalLog(0), m_globalLogCount(0) {};
00047 FileLogFactory( const std::string& path, const std::string& backupPath )
00048 : m_path( path ), m_backupPath( backupPath ), m_globalLog(0), m_globalLogCount(0) {};
00049
00050 public:
00051 Log* create();
00052 Log* create( const SessionID& );
00053 void destroy( Log* log );
00054
00055 private:
00056 std::string m_path;
00057 std::string m_backupPath;
00058 SessionSettings m_settings;
00059 Log* m_globalLog;
00060 int m_globalLogCount;
00061 };
00062
00070 class FileLog : public Log
00071 {
00072 public:
00073 FileLog( const std::string& path );
00074 FileLog( const std::string& path, const SessionID& sessionID );
00075 FileLog( const std::string& path, const std::string& backupPath, const SessionID& sessionID );
00076 virtual ~FileLog();
00077
00078 void clear();
00079 void backup();
00080
00081 void onIncoming( const std::string& value )
00082 { m_messages << UtcTimeStampConvertor::convert(UtcTimeStamp(), m_millisecondsInTimeStamp) << " : " << value << std::endl; }
00083 void onOutgoing( const std::string& value )
00084 { m_messages << UtcTimeStampConvertor::convert(UtcTimeStamp(), m_millisecondsInTimeStamp) << " : " << value << std::endl; }
00085 void onEvent( const std::string& value )
00086 {
00087 UtcTimeStamp now;
00088 m_event << UtcTimeStampConvertor::convert( now, m_millisecondsInTimeStamp )
00089 << " : " << value << std::endl;
00090 }
00091
00092 bool getMillisecondsInTimeStamp() const
00093 { return m_millisecondsInTimeStamp; }
00094 void setMillisecondsInTimeStamp ( bool value )
00095 { m_millisecondsInTimeStamp = value; }
00096
00097 private:
00098 std::string generatePrefix( const SessionID& sessionID );
00099 void init( std::string path, std::string backupPath, const std::string& prefix );
00100
00101 std::ofstream m_messages;
00102 std::ofstream m_event;
00103 std::string m_messagesFileName;
00104 std::string m_eventFileName;
00105 std::string m_fullPrefix;
00106 std::string m_fullBackupPrefix;
00107 bool m_millisecondsInTimeStamp;
00108 };
00109 }
00110
00111 #endif //FIX_LOG_H