Log.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_LOG_H
23 #define FIX_LOG_H
24 
25 #ifdef _MSC_VER
26 #pragma warning( disable : 4503 4355 4786 4290 )
27 #endif
28 
29 #include "Message.h"
30 #include "Mutex.h"
31 #include "SessionSettings.h"
32 #include <map>
33 #include <vector>
34 
35 namespace FIX
36 {
37 class Log;
38 
42 class LogFactory
43 {
44 public:
45  virtual ~LogFactory() {}
46  virtual Log* create() = 0;
47  virtual Log* create( const SessionID& ) = 0;
48  virtual void destroy( Log* ) = 0;
49 };
50 
56 class ScreenLogFactory : public LogFactory
57 {
58 public:
59  ScreenLogFactory( const SessionSettings& settings )
60 : m_useSettings( true ), m_settings( settings ) {};
61  ScreenLogFactory( bool incoming, bool outgoing, bool event )
62 : m_incoming( incoming ), m_outgoing( outgoing ), m_event( event ), m_useSettings( false ) {}
63 
64  Log* create();
65  Log* create( const SessionID& );
66  void destroy( Log* log );
67 
68 private:
69  void init( const Dictionary& settings, bool& incoming, bool& outgoing, bool& event );
70 
71  bool m_incoming;
72  bool m_outgoing;
73  bool m_event;
74  bool m_useSettings;
76 };
77 
81 class Log
82 {
83 public:
84  virtual ~Log() {}
85 
86  virtual void clear() = 0;
87  virtual void backup() = 0;
88  virtual void onIncoming( const std::string& ) = 0;
89  virtual void onOutgoing( const std::string& ) = 0;
90  virtual void onEvent( const std::string& ) = 0;
91 };
100 class NullLog : public Log
101 {
102 public:
103  void clear() {}
104  void backup() {}
105  void onIncoming( const std::string& ) {}
106  void onOutgoing( const std::string& ) {}
107  void onEvent( const std::string& ) {}
108 };
109 
115 class ScreenLog : public Log
116 {
117 public:
118  ScreenLog( bool incoming, bool outgoing, bool event )
119 : m_prefix( "GLOBAL" ),
120  m_incoming( incoming ), m_outgoing( outgoing ), m_event( event ) {}
121 
122  ScreenLog( const SessionID& sessionID,
123  bool incoming, bool outgoing, bool event )
124 : m_prefix( sessionID.toString() ),
125  m_incoming( incoming ), m_outgoing( outgoing ), m_event( event ) {}
126 
127  void clear() {}
128  void backup() {}
129 
130  void onIncoming( const std::string& value )
131  {
132  if ( !m_incoming ) return ;
133  Locker l( s_mutex );
134  m_time.setCurrent();
135  std::cout << "<" << UtcTimeStampConvertor::convert(m_time, 9)
136  << ", " << m_prefix
137  << ", " << "incoming>" << std::endl
138  << " (" << value << ")" << std::endl;
139  }
140 
141  void onOutgoing( const std::string& value )
142  {
143  if ( !m_outgoing ) return ;
146  std::cout << "<" << UtcTimeStampConvertor::convert(m_time, 9)
147  << ", " << m_prefix
148  << ", " << "outgoing>" << std::endl
149  << " (" << value << ")" << std::endl;
150  }
151 
152  void onEvent( const std::string& value )
153  {
154  if ( !m_event ) return ;
155  Locker l( s_mutex );
156  m_time.setCurrent();
157  std::cout << "<" << UtcTimeStampConvertor::convert(m_time, 9)
158  << ", " << m_prefix
159  << ", " << "event>" << std::endl
160  << " (" << value << ")" << std::endl;
161  }
162 
163 private:
164  std::string m_prefix;
166  bool m_incoming;
167  bool m_outgoing;
168  bool m_event;
169  static Mutex s_mutex;
170 };
171 }
172 
173 #endif //FIX_LOG_H
FIX::NullLog::clear
void clear()
Definition: Log.h:120
FIX::Log::~Log
virtual ~Log()
Definition: Log.h:101
FIX::ScreenLogFactory::m_event
bool m_event
Definition: Log.h:90
FIX::ScreenLogFactory::ScreenLogFactory
ScreenLogFactory(const SessionSettings &settings)
Definition: Log.h:76
FIX::ScreenLog::backup
void backup()
Definition: Log.h:145
SessionSettings.h
FIX::ScreenLogFactory::m_settings
SessionSettings m_settings
Definition: Log.h:92
FIX::UtcTimeStamp
Date and Time represented in UTC.
Definition: FieldTypes.h:599
FIX::ScreenLog::m_prefix
std::string m_prefix
Definition: Log.h:181
FIX::Mutex
Portable implementation of a mutex.
Definition: Mutex.h:47
FIX::ScreenLog::m_time
UtcTimeStamp m_time
Definition: Log.h:182
FIX::ScreenLogFactory::m_outgoing
bool m_outgoing
Definition: Log.h:89
FIX::NullLog::onEvent
void onEvent(const std::string &)
Definition: Log.h:124
FIX::SessionID
Unique session id consists of BeginString, SenderCompID and TargetCompID.
Definition: SessionID.h:47
FIX::ScreenLog::onOutgoing
void onOutgoing(const std::string &value)
Definition: Log.h:158
FIX::ScreenLogFactory::destroy
void destroy(Log *log)
Definition: Log.cpp:90
FIX::Log::backup
virtual void backup()=0
FIX::SessionSettings
Container for setting dictionaries mapped to sessions.
Definition: SessionSettings.h:237
Mutex.h
FIX::ScreenLogFactory::m_useSettings
bool m_useSettings
Definition: Log.h:91
FIX::Log::onEvent
virtual void onEvent(const std::string &)=0
FIX::ScreenLog::onEvent
void onEvent(const std::string &value)
Definition: Log.h:169
FIX::NullLog::backup
void backup()
Definition: Log.h:121
FIX::LogFactory::destroy
virtual void destroy(Log *)=0
FIX::UtcTimeStamp::setCurrent
void setCurrent()
Definition: FieldTypes.h:643
FIX::LogFactory::~LogFactory
virtual ~LogFactory()
Definition: Log.h:62
FIX::ScreenLogFactory::create
Log * create()
Definition: Log.cpp:49
FIX::ScreenLog::onIncoming
void onIncoming(const std::string &value)
Definition: Log.h:147
FIX::NullLog::onOutgoing
void onOutgoing(const std::string &)
Definition: Log.h:123
FIX::NullLog::onIncoming
void onIncoming(const std::string &)
Definition: Log.h:122
FIX::UtcTimeStampConvertor::convert
static std::string convert(const UtcTimeStamp &value, int precision=0)
Definition: FieldConvertors.h:451
FIX
Definition: Acceptor.cpp:34
FIX::ScreenLogFactory::m_incoming
bool m_incoming
Definition: Log.h:88
FIX::Log::clear
virtual void clear()=0
FIX::NullLog
Null implementation of Log.
Definition: Log.h:117
FIX::ScreenLog::m_event
bool m_event
Definition: Log.h:185
FIX::ScreenLog::s_mutex
static Mutex s_mutex
Definition: Log.h:186
FIX::Locker
Locks/Unlocks a mutex using RAII.
Definition: Mutex.h:112
FIX::ScreenLog::m_incoming
bool m_incoming
Definition: Log.h:183
FIX::LogFactory::create
virtual Log * create()=0
FIX::ScreenLog::ScreenLog
ScreenLog(bool incoming, bool outgoing, bool event)
Definition: Log.h:135
FIX::ScreenLog::clear
void clear()
Definition: Log.h:144
FIX::Log::onIncoming
virtual void onIncoming(const std::string &)=0
FIX::ScreenLog
Screen based implementation of Log.
Definition: Log.h:132
FIX::Log::onOutgoing
virtual void onOutgoing(const std::string &)=0
FIX::ScreenLogFactory::init
void init(const Dictionary &settings, bool &incoming, bool &outgoing, bool &event)
Definition: Log.cpp:67
FIX::Dictionary
For storage and retrieval of key/value pairs.
Definition: Dictionary.h:53
FIX::Log
This interface must be implemented to log messages and events.
Definition: Log.h:98
Message.h
FIX::ScreenLog::m_outgoing
bool m_outgoing
Definition: Log.h:184

Generated on Wed Apr 29 2020 19:41:30 for QuickFIX by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2001