Log.h
Go to the documentation of this file.
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_LOG_H
#define FIX_LOG_H
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
#include "Message.h"
#include "Mutex.h"
#include "SessionSettings.h"
#include <map>
#include <vector>
namespace FIX
{
class Log;
class LogFactory
{
public:
virtual ~LogFactory() {}
virtual Log* create() = 0;
virtual Log* create( const SessionID& ) = 0;
virtual void destroy( Log* ) = 0;
};
class ScreenLogFactory : public LogFactory
{
public:
ScreenLogFactory( const SessionSettings& settings )
: m_useSettings( true ), m_settings( settings ) {};
ScreenLogFactory( bool incoming, bool outgoing, bool event )
: m_incoming( incoming ), m_outgoing( outgoing ), m_event( event ), m_useSettings( false ) {}
Log* create();
Log* create( const SessionID& );
void destroy( Log* log );
private:
void init( const Dictionary& settings, bool& incoming, bool& outgoing, bool& event );
bool m_incoming;
bool m_outgoing;
bool m_event;
bool m_useSettings;
SessionSettings m_settings;
};
class Log
{
public:
virtual ~Log() {}
virtual void clear() = 0;
virtual void backup() = 0;
virtual void onIncoming( const std::string& ) = 0;
virtual void onOutgoing( const std::string& ) = 0;
virtual void onEvent( const std::string& ) = 0;
};
class NullLog : public Log
{
public:
void clear() {}
void backup() {}
void onIncoming( const std::string& ) {}
void onOutgoing( const std::string& ) {}
void onEvent( const std::string& ) {}
};
class ScreenLog : public Log
{
public:
ScreenLog( bool incoming, bool outgoing, bool event )
: m_prefix( "GLOBAL" ),
m_incoming( incoming ), m_outgoing( outgoing ), m_event( event ) {}
ScreenLog( const SessionID& sessionID,
bool incoming, bool outgoing, bool event )
: m_prefix( sessionID.toString() ),
m_incoming( incoming ), m_outgoing( outgoing ), m_event( event ) {}
void clear() {}
void backup() {}
void onIncoming( const std::string& value )
{
if ( !m_incoming ) return ;
Locker l( s_mutex );
m_time.setCurrent();
std::cout << "<" << UtcTimeStampConvertor::convert(m_time, 9)
<< ", " << m_prefix
<< ", " << "incoming>" << std::endl
<< " (" << value << ")" << std::endl;
}
void onOutgoing( const std::string& value )
{
if ( !m_outgoing ) return ;
Locker l( s_mutex );
m_time.setCurrent();
std::cout << "<" << UtcTimeStampConvertor::convert(m_time, 9)
<< ", " << m_prefix
<< ", " << "outgoing>" << std::endl
<< " (" << value << ")" << std::endl;
}
void onEvent( const std::string& value )
{
if ( !m_event ) return ;
Locker l( s_mutex );
m_time.setCurrent();
std::cout << "<" << UtcTimeStampConvertor::convert(m_time, 9)
<< ", " << m_prefix
<< ", " << "event>" << std::endl
<< " (" << value << ")" << std::endl;
}
private:
std::string m_prefix;
UtcTimeStamp m_time;
bool m_incoming;
bool m_outgoing;
bool m_event;
static Mutex s_mutex;
};
}
#endif //FIX_LOG_H
Message.h
Mutex.h
SessionSettings.h
FIX::Dictionary
For storage and retrieval of key/value pairs.
Definition Dictionary.h:37
FIX::Locker
Locks/Unlocks a mutex using RAII.
Definition Mutex.h:96
FIX::LogFactory
This interface must be implemented to create a Log.
Definition Log.h:43
FIX::LogFactory::destroy
virtual void destroy(Log *)=0
FIX::LogFactory::~LogFactory
virtual ~LogFactory()
Definition Log.h:45
FIX::LogFactory::create
virtual Log * create()=0
FIX::LogFactory::create
virtual Log * create(const SessionID &)=0
FIX::Log
This interface must be implemented to log messages and events.
Definition Log.h:82
FIX::Log::backup
virtual void backup()=0
FIX::Log::onIncoming
virtual void onIncoming(const std::string &)=0
FIX::Log::onOutgoing
virtual void onOutgoing(const std::string &)=0
FIX::Log::~Log
virtual ~Log()
Definition Log.h:84
FIX::Log::clear
virtual void clear()=0
FIX::Log::onEvent
virtual void onEvent(const std::string &)=0
FIX::Mutex
Portable implementation of a mutex.
Definition Mutex.h:31
FIX::NullLog
Null implementation of Log.
Definition Log.h:101
FIX::NullLog::onIncoming
void onIncoming(const std::string &)
Definition Log.h:105
FIX::NullLog::backup
void backup()
Definition Log.h:104
FIX::NullLog::onEvent
void onEvent(const std::string &)
Definition Log.h:107
FIX::NullLog::onOutgoing
void onOutgoing(const std::string &)
Definition Log.h:106
FIX::NullLog::clear
void clear()
Definition Log.h:103
FIX::ScreenLogFactory
Creates a screen based implementation of Log.
Definition Log.h:57
FIX::ScreenLogFactory::init
void init(const Dictionary &settings, bool &incoming, bool &outgoing, bool &event)
Definition Log.cpp:50
FIX::ScreenLogFactory::m_incoming
bool m_incoming
Definition Log.h:71
FIX::ScreenLogFactory::ScreenLogFactory
ScreenLogFactory(const SessionSettings &settings)
Definition Log.h:59
FIX::ScreenLogFactory::ScreenLogFactory
ScreenLogFactory(bool incoming, bool outgoing, bool event)
Definition Log.h:61
FIX::ScreenLogFactory::m_useSettings
bool m_useSettings
Definition Log.h:74
FIX::ScreenLogFactory::create
Log * create()
Definition Log.cpp:32
FIX::ScreenLogFactory::m_event
bool m_event
Definition Log.h:73
FIX::ScreenLogFactory::m_settings
SessionSettings m_settings
Definition Log.h:75
FIX::ScreenLogFactory::destroy
void destroy(Log *log)
Definition Log.cpp:73
FIX::ScreenLogFactory::m_outgoing
bool m_outgoing
Definition Log.h:72
FIX::ScreenLog
Screen based implementation of Log.
Definition Log.h:116
FIX::ScreenLog::onEvent
void onEvent(const std::string &value)
Definition Log.h:152
FIX::ScreenLog::s_mutex
static Mutex s_mutex
Definition Log.h:169
FIX::ScreenLog::clear
void clear()
Definition Log.h:127
FIX::ScreenLog::m_event
bool m_event
Definition Log.h:168
FIX::ScreenLog::ScreenLog
ScreenLog(bool incoming, bool outgoing, bool event)
Definition Log.h:118
FIX::ScreenLog::m_incoming
bool m_incoming
Definition Log.h:166
FIX::ScreenLog::onOutgoing
void onOutgoing(const std::string &value)
Definition Log.h:141
FIX::ScreenLog::ScreenLog
ScreenLog(const SessionID &sessionID, bool incoming, bool outgoing, bool event)
Definition Log.h:122
FIX::ScreenLog::m_prefix
std::string m_prefix
Definition Log.h:164
FIX::ScreenLog::m_outgoing
bool m_outgoing
Definition Log.h:167
FIX::ScreenLog::onIncoming
void onIncoming(const std::string &value)
Definition Log.h:130
FIX::ScreenLog::m_time
UtcTimeStamp m_time
Definition Log.h:165
FIX::ScreenLog::backup
void backup()
Definition Log.h:128
FIX::SessionID
Unique session id consists of BeginString, SenderCompID and TargetCompID.
Definition SessionID.h:31
FIX::SessionSettings
Container for setting dictionaries mapped to sessions.
Definition SessionSettings.h:221
FIX::UtcTimeStamp
Date and Time represented in UTC.
Definition FieldTypes.h:583
FIX::UtcTimeStamp::setCurrent
void setCurrent()
Definition FieldTypes.h:626
FIX
Definition Acceptor.cpp:35
FIX::UtcTimeStampConvertor::convert
static std::string convert(const UtcTimeStamp &value, int precision=0)
Definition FieldConvertors.h:434