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
35namespace FIX
36{
37class Log;
38
43{
44public:
45 virtual ~LogFactory() {}
46 virtual Log* create() = 0;
47 virtual Log* create( const SessionID& ) = 0;
48 virtual void destroy( Log* ) = 0;
49};
50
57{
58public:
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
68private:
69 void init( const Dictionary& settings, bool& incoming, bool& outgoing, bool& event );
70
73 bool m_event;
76};
77
81class Log
82{
83public:
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};
100class NullLog : public Log
101{
102public:
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
115class ScreenLog : public Log
116{
117public:
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 );
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 ;
144 Locker l( s_mutex );
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 );
157 std::cout << "<" << UtcTimeStampConvertor::convert(m_time, 9)
158 << ", " << m_prefix
159 << ", " << "event>" << std::endl
160 << " (" << value << ")" << std::endl;
161 }
162
163private:
164 std::string m_prefix;
170};
171}
172
173#endif //FIX_LOG_H
For storage and retrieval of key/value pairs.
Definition Dictionary.h:37
Locks/Unlocks a mutex using RAII.
Definition Mutex.h:96
This interface must be implemented to create a Log.
Definition Log.h:43
virtual void destroy(Log *)=0
virtual ~LogFactory()
Definition Log.h:45
virtual Log * create()=0
virtual Log * create(const SessionID &)=0
This interface must be implemented to log messages and events.
Definition Log.h:82
virtual void backup()=0
virtual void onIncoming(const std::string &)=0
virtual void onOutgoing(const std::string &)=0
virtual ~Log()
Definition Log.h:84
virtual void clear()=0
virtual void onEvent(const std::string &)=0
Portable implementation of a mutex.
Definition Mutex.h:31
Null implementation of Log.
Definition Log.h:101
void onIncoming(const std::string &)
Definition Log.h:105
void backup()
Definition Log.h:104
void onEvent(const std::string &)
Definition Log.h:107
void onOutgoing(const std::string &)
Definition Log.h:106
void clear()
Definition Log.h:103
Creates a screen based implementation of Log.
Definition Log.h:57
void init(const Dictionary &settings, bool &incoming, bool &outgoing, bool &event)
Definition Log.cpp:50
ScreenLogFactory(const SessionSettings &settings)
Definition Log.h:59
ScreenLogFactory(bool incoming, bool outgoing, bool event)
Definition Log.h:61
SessionSettings m_settings
Definition Log.h:75
void destroy(Log *log)
Definition Log.cpp:73
Screen based implementation of Log.
Definition Log.h:116
void onEvent(const std::string &value)
Definition Log.h:152
static Mutex s_mutex
Definition Log.h:169
void clear()
Definition Log.h:127
bool m_event
Definition Log.h:168
ScreenLog(bool incoming, bool outgoing, bool event)
Definition Log.h:118
bool m_incoming
Definition Log.h:166
void onOutgoing(const std::string &value)
Definition Log.h:141
ScreenLog(const SessionID &sessionID, bool incoming, bool outgoing, bool event)
Definition Log.h:122
std::string m_prefix
Definition Log.h:164
bool m_outgoing
Definition Log.h:167
void onIncoming(const std::string &value)
Definition Log.h:130
UtcTimeStamp m_time
Definition Log.h:165
void backup()
Definition Log.h:128
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
static std::string convert(const UtcTimeStamp &value, int precision=0)

Generated on Mon Mar 4 2024 21:10:02 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001