Re: [Quickfix-users] Timestamp in log entries
Brought to you by:
orenmnero
From: Greg C. <gc...@po...> - 2006-12-21 20:19:06
|
Nearly a year later I've made this change, although it is a global configuration and not session-specific. The configuration matches the FileIncludeTimeStampForMessages and FileIncludeMilliseconds Steve Bate put into QuickFix/J after my initial inquiry. There are modifications to FileLog.h, FileLog.cpp, and SessionSettings.h. What is the preferred method to post these for review? I paste them below in case that is sufficient. If someone with commit priveledge chooses to include these changes, please audit and feel free to revise as this is my first source edit. FWIW, I think local timestamps in logs are very useful. Thanks, Greg FileLog.h ------------------- class FileLog : public Log { public: FileLog( const std::string& path ); FileLog( const std::string& path, const SessionID& sessionID, bool includeTimestamp, bool includeMilliseconds ); virtual ~FileLog(); void clear(); void onIncoming( const std::string& value ) { =09 if (m_includeTimestamp) =09 { =09=09 UtcTimeStamp now; =09=09 m_messages << UtcTimeStampConvertor::convert( now, m_includeMilliseconds ) << " "; =09 } =09 m_messages << value << std::endl << std::flush; } void onOutgoing( const std::string& value ) { =09 if (m_includeTimestamp) =09 { =09=09 UtcTimeStamp now; =09=09 m_messages << UtcTimeStampConvertor::convert( now, m_includeMilliseconds ) << " "; =09 } =09 m_messages << value << std::endl << std::flush; } void onEvent( const std::string& value ) { UtcTimeStamp now; m_event << UtcTimeStampConvertor::convert( now, m_includeMilliseconds ) << " : " << value << std::endl << std::flush; } private: void init( std::string path, const std::string& prefix, bool includeTimestamp, bool includeMilliseconds ); std::ofstream m_messages; std::ofstream m_event; std::string m_messagesFileName; std::string m_eventFileName; bool m_includeTimestamp; bool m_includeMilliseconds; }; } ------------------- FileLog.cpp ----------------- Log* FileLogFactory::create( const SessionID& s ) { QF_STACK_PUSH(FileLogFactory::create) if ( m_path.size() ) return new FileLog( m_path, s, false, false ); std::string path; bool includeTimestamp =3D false; bool includeMilliseconds =3D false; Dictionary settings =3D m_settings.get( s ); path =3D settings.getString( FILE_LOG_PATH ); if (settings.has( FILE_INCLUDE_TIMESTAMP )) {includeTimestamp =3D settings.getBool( FILE_INCLUDE_TIMESTAMP );} if (settings.has( FILE_INCLUDE_MILLISECONDS )) {includeMilliseconds =3D settings.getBool( FILE_INCLUDE_MILLISECONDS );} return new FileLog( path, s, includeTimestamp, includeMilliseconds ); QF_STACK_POP } void FileLogFactory::destroy( Log* pLog ) { QF_STACK_PUSH(FileLogFactory::destroy) if( pLog =3D=3D m_globalLog ) { m_globalLogCount--; if( m_globalLogCount =3D=3D 0 ) { =09 delete pLog; =09 m_globalLogCount =3D 0; }=09 } else { =09delete pLog; } QF_STACK_POP } FileLog::FileLog( const std::string& path ) { init( path, "GLOBAL", false, false ); } FileLog::FileLog( const std::string& path, const SessionID& s , bool includeTimestamp, bool includeMilliseconds) { const std::string& begin =3D s.getBeginString().getString(); const std::string& sender =3D s.getSenderCompID().getString(); const std::string& target =3D s.getTargetCompID().getString(); const std::string& qualifier =3D s.getSessionQualifier(); std::string prefix =3D begin + "-" + sender + "-" + target; if( qualifier.size() ) prefix +=3D "-" + qualifier; init( path, prefix, includeTimestamp, includeMilliseconds ); } void FileLog::init( std::string path, const std::string& prefix, bool includeTimestamp, bool includeMilliseconds) { QF_STACK_PUSH(FileLog::init) =09 file_mkdir( path.c_str() ); if ( path.empty() ) path =3D "."; std::string fullPrefix =3D file_appendpath(path, prefix + "."); m_messagesFileName =3D fullPrefix + "messages.log"; m_eventFileName =3D fullPrefix + "event.log"; m_messages.open( m_messagesFileName.c_str(), std::ios::out | std::ios::ap= p ); if ( !m_messages.is_open() ) throw ConfigError( "Could not open messages file: " + m_messagesFileName ); m_event.open( m_eventFileName.c_str(), std::ios::out | std::ios::app ); if ( !m_event.is_open() ) throw ConfigError( "Could not open event file: " + m_eventFileName ); m_includeTimestamp =3D includeTimestamp; m_includeMilliseconds =3D includeMilliseconds; QF_STACK_POP } ---------------- SessionSettings.h ---------------- const char ODBC_STORE_CONNECTION_STRING[] =3D "OdbcStoreConnectionString"; const char FILE_LOG_PATH[] =3D "FileLogPath"; const char FILE_INCLUDE_MILLISECONDS[] =3D "FileIncludeMilliseconds"; const char FILE_INCLUDE_TIMESTAMP[] =3D "FileIncludeTimestampForMessages"; const char SCREEN_LOG_SHOW_INCOMING[] =3D "ScreenLogShowIncoming"; const char SCREEN_LOG_SHOW_OUTGOING[] =3D "ScreenLogShowOutgoing"; -------------- On 3/22/06, Joerg Thoennes <Joe...@ma...> wrote: > Hi Greg, > > > Unfourtunately, I am using QF in a C# application. I see the options > > you added FileIncludeTimeStampForMessages and FileIncludeMilliseconds. > > I'll add an equivalent of your changes to my code unless someone > > cares to make the same modifications to the primary version. > > If you post patches to the native QF version, which are similiar to QF/J = (ie configurable > in the same way), somebody with commit access will probably have a look a= t them. > > Thanks, J=F6rg > > -- > Joerg Thoennes > http://macd.com > Tel.: +49 (0)241 44597-24 Macdonald Associates GmbH > Fax : +49 (0)241 44597-10 Lothringer Str. 52, D-52070 Aachen > |