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 
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 
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;
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 ), m_millisecondsInTimeStamp( true ) {}
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 ), m_millisecondsInTimeStamp( true ) {}
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();
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 ;
144  Locker l( s_mutex );
145  m_time.setCurrent();
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();
158  << ", " << m_prefix
159  << ", " << "event>" << std::endl
160  << " (" << value << ")" << std::endl;
161  }
162 
164  { return m_millisecondsInTimeStamp; }
165  void setMillisecondsInTimeStamp ( bool value )
166  { m_millisecondsInTimeStamp = value; }
167 
168 private:
169  std::string m_prefix;
173  bool m_event;
174  static Mutex s_mutex;
176 };
177 }
178 
179 #endif //FIX_LOG_H
void setMillisecondsInTimeStamp(bool value)
Definition: Log.h:165
Screen based implementation of Log.
Definition: Log.h:115
bool m_event
Definition: Log.h:173
static Mutex s_mutex
Definition: Log.h:174
bool m_useSettings
Definition: Log.h:74
static std::string convert(const UtcTimeStamp &value, bool showMilliseconds=false)
virtual Log * create()=0
ScreenLog(bool incoming, bool outgoing, bool event)
Definition: Log.h:118
bool m_incoming
Definition: Log.h:171
Creates a screen based implementation of Log.
Definition: Log.h:56
void onIncoming(const std::string &)
Definition: Log.h:105
virtual ~Log()
Definition: Log.h:84
virtual void onOutgoing(const std::string &)=0
void destroy(Log *log)
Definition: Log.cpp:73
bool m_millisecondsInTimeStamp
Definition: Log.h:175
ScreenLog(const SessionID &sessionID, bool incoming, bool outgoing, bool event)
Definition: Log.h:122
virtual void destroy(Log *)=0
virtual void backup()=0
Null implementation of Log.
Definition: Log.h:100
void onEvent(const std::string &)
Definition: Log.h:107
void clear()
Definition: Log.h:127
void onOutgoing(const std::string &)
Definition: Log.h:106
This interface must be implemented to log messages and events.
Definition: Log.h:81
void init(const Dictionary &settings, bool &incoming, bool &outgoing, bool &event)
Definition: Log.cpp:50
void onOutgoing(const std::string &value)
Definition: Log.h:141
virtual void onEvent(const std::string &)=0
Locks/Unlocks a mutex using RAII.
Definition: Mutex.h:95
Container for setting dictionaries mapped to sessions.
virtual ~LogFactory()
Definition: Log.h:45
UtcTimeStamp m_time
Definition: Log.h:170
virtual void clear()=0
This interface must be implemented to create a Log.
Definition: Log.h:42
Log * create()
Definition: Log.cpp:32
void onIncoming(const std::string &value)
Definition: Log.h:130
void clear()
Definition: Log.h:103
Portable implementation of a mutex.
Definition: Mutex.h:30
virtual void onIncoming(const std::string &)=0
Date and Time represented in UTC.
Definition: FieldTypes.h:399
For storage and retrieval of key/value pairs.
Definition: Dictionary.h:36
bool getMillisecondsInTimeStamp() const
Definition: Log.h:163
void backup()
Definition: Log.h:128
ScreenLogFactory(const SessionSettings &settings)
Definition: Log.h:59
Unique session id consists of BeginString, SenderCompID and TargetCompID.
Definition: SessionID.h:30
ScreenLogFactory(bool incoming, bool outgoing, bool event)
Definition: Log.h:61
SessionSettings m_settings
Definition: Log.h:75
std::string m_prefix
Definition: Log.h:169
void backup()
Definition: Log.h:104
bool m_outgoing
Definition: Log.h:172
void onEvent(const std::string &value)
Definition: Log.h:152

Generated on Sat Mar 29 2014 15:13:32 for QuickFIX by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2001