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;
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
Creates a file based implementation of Log.
Definition: FileLog.h:41
FileLogFactory(const std::string &path, const std::string &backupPath)
Definition: FileLog.h:47
std::string m_path
Definition: FileLog.h:56
FileLogFactory(const std::string &path)
Definition: FileLog.h:45
std::string m_backupPath
Definition: FileLog.h:57
void destroy(Log *log)
Definition: FileLog.cpp:74
FileLogFactory(const SessionSettings &settings)
Definition: FileLog.h:43
SessionSettings m_settings
Definition: FileLog.h:58
File based implementation of Log.
Definition: FileLog.h:71
std::ofstream m_event
Definition: FileLog.h:98
std::string m_fullPrefix
Definition: FileLog.h:101
std::string generatePrefix(const SessionID &sessionID)
Definition: FileLog.cpp:111
std::string m_eventFileName
Definition: FileLog.h:100
void onEvent(const std::string &value)
Definition: FileLog.h:86
std::string m_fullBackupPrefix
Definition: FileLog.h:102
void onIncoming(const std::string &value)
Definition: FileLog.h:82
void onOutgoing(const std::string &value)
Definition: FileLog.h:84
void clear()
Definition: FileLog.cpp:157
void init(std::string path, std::string backupPath, const std::string &prefix)
Definition: FileLog.cpp:129
virtual ~FileLog()
Definition: FileLog.cpp:151
std::ofstream m_messages
Definition: FileLog.h:97
std::string m_messagesFileName
Definition: FileLog.h:99
void backup()
Definition: FileLog.cpp:166
FileLog(const std::string &path)
Definition: FileLog.cpp:91
This interface must be implemented to create a Log.
Definition: Log.h:43
This interface must be implemented to log messages and events.
Definition: Log.h:82
Unique session id consists of BeginString, SenderCompID and TargetCompID.
Definition: SessionID.h:31
Container for setting dictionaries mapped to sessions.
Date and Time represented in UTC.
Definition: FieldTypes.h:583
@ UtcTimeStamp
Definition: FieldTypes.h:923
Definition: Acceptor.cpp:35
static std::string convert(const UtcTimeStamp &value, int precision=0)

Generated on Wed Nov 24 2021 09:55:53 for QuickFIX by doxygen 1.9.1 written by Dimitri van Heesch, © 1997-2001