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(), m_millisecondsInTimeStamp) << " : " << value << std::endl; }
84  void onOutgoing( const std::string& value )
85  { m_messages << UtcTimeStampConvertor::convert(UtcTimeStamp(), m_millisecondsInTimeStamp) << " : " << value << std::endl; }
86  void onEvent( const std::string& value )
87  {
88  UtcTimeStamp now;
89  m_event << UtcTimeStampConvertor::convert( now, m_millisecondsInTimeStamp )
90  << " : " << value << std::endl;
91  }
92 
94  { return m_millisecondsInTimeStamp; }
95  void setMillisecondsInTimeStamp ( bool value )
96  { m_millisecondsInTimeStamp = value; }
97 
98 private:
99  std::string generatePrefix( const SessionID& sessionID );
100  void init( std::string path, std::string backupPath, const std::string& prefix );
101 
102  std::ofstream m_messages;
103  std::ofstream m_event;
104  std::string m_messagesFileName;
105  std::string m_eventFileName;
106  std::string m_fullPrefix;
107  std::string m_fullBackupPrefix;
109 };
110 }
111 
112 #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:106
static std::string convert(const UtcTimeStamp &value, bool showMilliseconds=false)
std::ofstream m_messages
Definition: FileLog.h:102
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:105
This interface must be implemented to log messages and events.
Definition: Log.h:81
void onEvent(const std::string &value)
Definition: FileLog.h:86
Definition: Acceptor.cpp:34
std::ofstream m_event
Definition: FileLog.h:103
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:107
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
bool m_millisecondsInTimeStamp
Definition: FileLog.h:108
Date and Time represented in UTC.
Definition: FieldTypes.h:399
std::string m_messagesFileName
Definition: FileLog.h:104
Unique session id consists of BeginString, SenderCompID and TargetCompID.
Definition: SessionID.h:30
bool getMillisecondsInTimeStamp() const
Definition: FileLog.h:93
void setMillisecondsInTimeStamp(bool value)
Definition: FileLog.h:95

Generated on Thu Sep 5 2019 11:07:58 for QuickFIX by doxygen 1.8.13 written by Dimitri van Heesch, © 1997-2001