FileLog.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 
3 /****************************************************************************
4 ** Copyright (c) 2001-2014
5 **
6 ** This file is part of the QuickFIX FIX Engine
7 **
8 ** This file may be distributed under the terms of the quickfixengine.org
9 ** license as defined by quickfixengine.org and appearing in the file
10 ** LICENSE included in the packaging of this file.
11 **
12 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 **
15 ** See http://www.quickfixengine.org/LICENSE for licensing information.
16 **
17 ** Contact ask@quickfixengine.org if any conditions of this licensing are
18 ** not clear to you.
19 **
20 ****************************************************************************/
21 
22 #ifndef FIX_FILELOG_H
23 #define FIX_FILELOG_H
24 
25 #ifdef _MSC_VER
26 #pragma warning( disable : 4503 4355 4786 4290 )
27 #endif
28 
29 #include "Log.h"
30 #include "SessionSettings.h"
31 #include <fstream>
32 
33 namespace FIX
34 {
40 class FileLogFactory : public LogFactory
41 {
42 public:
43  FileLogFactory( const SessionSettings& settings )
44 : m_settings( settings ), m_globalLog(0), m_globalLogCount(0) {};
45  FileLogFactory( const std::string& path )
46 : m_path( path ), m_backupPath( path ), m_globalLog(0), m_globalLogCount(0) {};
47  FileLogFactory( const std::string& path, const std::string& backupPath )
48 : m_path( path ), m_backupPath( backupPath ), m_globalLog(0), m_globalLogCount(0) {};
49 
50 public:
51  Log* create();
52  Log* create( const SessionID& );
53  void destroy( Log* log );
54 
55 private:
56  std::string m_path;
57  std::string m_backupPath;
61 };
62 
70 class FileLog : public Log
71 {
72 public:
73  FileLog( const std::string& path );
74  FileLog( const std::string& path, const std::string& backupPath );
75  FileLog( const std::string& path, const SessionID& sessionID );
76  FileLog( const std::string& path, const std::string& backupPath, const SessionID& sessionID );
77  virtual ~FileLog();
78 
79  void clear();
80  void backup();
81 
82  void onIncoming( const std::string& value )
83  { m_messages << UtcTimeStampConvertor::convert(UtcTimeStamp(), 9) << " : " << value << std::endl; }
84  void onOutgoing( const std::string& value )
85  { m_messages << UtcTimeStampConvertor::convert(UtcTimeStamp(), 9) << " : " << value << std::endl; }
86  void onEvent( const std::string& value )
87  {
88  UtcTimeStamp now;
89  m_event << UtcTimeStampConvertor::convert( now, 9 )
90  << " : " << value << std::endl;
91  }
92 
93 private:
94  std::string generatePrefix( const SessionID& sessionID );
95  void init( std::string path, std::string backupPath, const std::string& prefix );
96 
97  std::ofstream m_messages;
98  std::ofstream m_event;
99  std::string m_messagesFileName;
100  std::string m_eventFileName;
101  std::string m_fullPrefix;
102  std::string m_fullBackupPrefix;
103 };
104 }
105 
106 #endif //FIX_LOG_H
std::string m_path
Definition: FileLog.h:56
Creates a file based implementation of Log.
Definition: FileLog.h:40
File based implementation of Log.
Definition: FileLog.h:70
FileLogFactory(const std::string &path)
Definition: FileLog.h:45
std::string m_fullPrefix
Definition: FileLog.h:101
std::ofstream m_messages
Definition: FileLog.h:97
void onIncoming(const std::string &value)
Definition: FileLog.h:82
std::string m_backupPath
Definition: FileLog.h:57
void destroy(Log *log)
Definition: FileLog.cpp:74
std::string m_eventFileName
Definition: FileLog.h:100
This interface must be implemented to log messages and events.
Definition: Log.h:81
static std::string convert(const UtcTimeStamp &value, int precision=0)
void onEvent(const std::string &value)
Definition: FileLog.h:86
Definition: Acceptor.cpp:34
std::ofstream m_event
Definition: FileLog.h:98
SessionSettings m_settings
Definition: FileLog.h:58
FileLogFactory(const SessionSettings &settings)
Definition: FileLog.h:43
Container for setting dictionaries mapped to sessions.
std::string m_fullBackupPrefix
Definition: FileLog.h:102
void onOutgoing(const std::string &value)
Definition: FileLog.h:84
FileLogFactory(const std::string &path, const std::string &backupPath)
Definition: FileLog.h:47
This interface must be implemented to create a Log.
Definition: Log.h:42
Date and Time represented in UTC.
Definition: FieldTypes.h:582
std::string m_messagesFileName
Definition: FileLog.h:99
Unique session id consists of BeginString, SenderCompID and TargetCompID.
Definition: SessionID.h:30

Generated on Sun Apr 15 2018 21:44:00 for QuickFIX by doxygen 1.8.13 written by Dimitri van Heesch, © 1997-2001