fix8  version 1.4.0
Open Source C++ FIX Framework
FIX8::XmlFileLogger Class Reference

A file logger. More...

#include <logger.hpp>

Inheritance diagram for FIX8::XmlFileLogger:
FIX8::FileLogger FIX8::Logger

Public Member Functions

F8API XmlFileLogger (const std::string &pathname, const LogFlags flags, const Levels levels, const std::string delim=" ", const LogPositions positions=LogPositions(), const unsigned rotnum=rotation_default)
 
void preamble ()
 Write the xml preamble. If you use rotate, you need to call this AFTER rotating. More...
 
void postamble ()
 Write the xml postamble. If you use rotate, you need to call this BEFORE rotating. More...
 
virtual ~XmlFileLogger ()
 Dtor. More...
 
virtual F8API void process_logline (LogElement *le)
 
- Public Member Functions inherited from FIX8::FileLogger
F8API FileLogger (const std::string &pathname, const LogFlags flags, const Levels levels, const std::string delim=" ", const LogPositions positions=LogPositions(), const unsigned rotnum=rotation_default)
 
virtual ~FileLogger ()
 Dtor. More...
 
virtual F8API bool rotate (bool force=false)
 
- Public Member Functions inherited from FIX8::Logger
 Logger (const LogFlags flags, const Levels levels=Levels(All), const std::string delim=" ", const LogPositions positions=LogPositions())
 
virtual ~Logger ()
 Dtor. More...
 
bool is_loggable (Level level) const
 
void set_levels (Levels levels)
 
void set_flags (LogFlags flags)
 
void set_delimiter (const std::string &delim)
 
void set_positions (const std::vector< int > &positions)
 
virtual std::ostream & get_stream () const
 
bool enqueue (const std::string &what, Level lev=Logger::Info, const char *fl=nullptr, const unsigned val=0)
 
bool send (const std::string &what, Level lev=Logger::Info, const char *fl=nullptr, const unsigned val=0)
 
void stop ()
 Stop the logging thread. More...
 
F8API int operator() ()
 
bool has_flag (const Flags flg) const
 
F8API char get_thread_code (thread_id_t tid)
 
F8API void purge_thread_codes ()
 Remove dead threads from the thread code cache. More...
 
virtual F8API void flush ()
 Flush the buffer. More...
 
f8_thread_cancellation_tokencancellation_token ()
 

Additional Inherited Members

- Public Types inherited from FIX8::Logger
enum  Level {
  Debug, Info, Warn, Error,
  Fatal
}
 
enum  Flags {
  mstart, sstart, sequence, thread,
  timestamp, minitimestamp, direction, level,
  location, start_controls, append =start_controls, buffer,
  compress, pipe, broadcast, nolf,
  inbound, outbound, xml, num_flags
}
 
using LogFlags = ebitset< Flags >
 
using Levels = ebitset< Level >
 
using LogPositions = std::vector< int >
 
- Static Public Member Functions inherited from FIX8::Logger
static const Tickvalget_time_started ()
 
- Static Public Attributes inherited from FIX8::Logger
static const int Errors = bitsum(Warn,Error,Fatal)
 
static const int All = bitsum(Debug,Info,Warn,Error,Fatal)
 
static const int None = 0
 
static const int StdFlags = bitsum(sequence,thread,timestamp,level)
 
static const int rotation_default = 5
 
static const int max_rotation = 1024
 
static const std::vector< std::string > _bit_names
 string representation of logflags More...
 
static const std::vector< std::string > _level_names { "Debug", "Info ", "Warn ", "Error", "Fatal" }
 string representation of levels More...
 
- Protected Types inherited from FIX8::Logger
using ThreadCodes = std::map< thread_id_t, char >
 
using RevThreadCodes = std::map< char, thread_id_t >
 
- Protected Attributes inherited from FIX8::FileLogger
std::string _pathname
 
unsigned _rotnum
 
- Protected Attributes inherited from FIX8::Logger
f8_mutex _mutex
 
f8_spin_lock _log_spl
 
LogFlags _flags
 
Levels _levels
 
std::string _delim
 
std::ostream * _ofs = nullptr
 
size_t _lines = 0
 
f8_thread_cancellation_token _stopping
 
f8_concurrent_queue< LogElement_msg_queue
 
unsigned _sequence = 0
 
unsigned _osequence = 0
 
ThreadCodes _thread_codes
 
RevThreadCodes _rev_thread_codes
 
LogPositions _positions
 
- Static Protected Attributes inherited from FIX8::Logger
static const Tickval _started { true }
 The time the entire logging system was start. More...
 

Detailed Description

A file logger.

Definition at line 385 of file logger.hpp.

Constructor & Destructor Documentation

F8API FIX8::XmlFileLogger::XmlFileLogger ( const std::string &  pathname,
const LogFlags  flags,
const Levels  levels,
const std::string  delim = " ",
const LogPositions  positions = LogPositions(),
const unsigned  rotnum = rotation_default 
)
inline

Ctor.

Parameters
pathnamepathname to log to
flagsebitset flags
levelsebitset levels
delimfield delimiter
positionsfield positions
rotnumnumber of logfile rotations to retain (default=5)

Definition at line 396 of file logger.hpp.

References preamble().

398  : FileLogger(pathname, flags, levels, delim, positions, rotnum)
399  {
400  preamble();
401  }
void preamble()
Write the xml preamble. If you use rotate, you need to call this AFTER rotating.
Definition: logger.hpp:404
F8API FileLogger(const std::string &pathname, const LogFlags flags, const Levels levels, const std::string delim=" ", const LogPositions positions=LogPositions(), const unsigned rotnum=rotation_default)
Definition: logger.cpp:255
virtual FIX8::XmlFileLogger::~XmlFileLogger ( )
inlinevirtual

Dtor.

Definition at line 409 of file logger.hpp.

References postamble().

409 { postamble(); }
void postamble()
Write the xml postamble. If you use rotate, you need to call this BEFORE rotating.
Definition: logger.hpp:406

Member Function Documentation

void FIX8::XmlFileLogger::postamble ( )
inline

Write the xml postamble. If you use rotate, you need to call this BEFORE rotating.

Definition at line 406 of file logger.hpp.

References FIX8::Logger::get_stream().

Referenced by ~XmlFileLogger().

406 { get_stream() << "</fix8>" << std::endl; }
virtual std::ostream & get_stream() const
Definition: logger.hpp:286
void FIX8::XmlFileLogger::preamble ( )
inline

Write the xml preamble. If you use rotate, you need to call this AFTER rotating.

Definition at line 404 of file logger.hpp.

References FIX8::Logger::get_stream().

Referenced by XmlFileLogger().

404 { get_stream() << "<?xml version='1.0' encoding='ISO-8859-1'?>" << std::endl << "<fix8>" << std::endl; }
virtual std::ostream & get_stream() const
Definition: logger.hpp:286
void XmlFileLogger::process_logline ( LogElement le)
virtual

Process this logelement

Parameters
leLogElement

Reimplemented from FIX8::Logger.

Definition at line 371 of file logger.cpp.

References FIX8::Logger::LogElement::_fileline, FIX8::Logger::_flags, FIX8::Logger::LogElement::_level, FIX8::Logger::_level_names, FIX8::Logger::_mutex, FIX8::Logger::_osequence, FIX8::Logger::_sequence, FIX8::Logger::_started, FIX8::Logger::LogElement::_str, FIX8::Logger::LogElement::_tid, FIX8::Logger::LogElement::_val, FIX8::Logger::LogElement::_when, FIX8::Logger::direction, FIX8::Logger::get_stream(), FIX8::Logger::get_thread_code(), FIX8::GetTimeAsStringMini(), FIX8::Logger::level, FIX8::Logger::location, FIX8::Logger::minitimestamp, FIX8::Tickval::msecs(), FIX8::Logger::mstart, FIX8::Tickval::secs(), FIX8::Logger::sequence, spacer, FIX8::Logger::sstart, FIX8::Logger::thread, and FIX8::Logger::timestamp.

372 {
373  f8String spacer(3, ' ');
374  ostringstream ostr;
375 
376  ostr << spacer << "<logline ";
377  if (_flags & mstart)
378  {
379  const Tickval tvs(msg_ptr->_when - _started);
380  ostr << "mstart=\'" << (tvs.secs() * 1000 + tvs.msecs()) << "\' ";
381  }
382  if (_flags & sstart)
383  ostr << "sstart=\'" << (msg_ptr->_when - _started).secs() << "\' ";
384  if (_flags & sequence)
385  ostr << "sequence=\'" << (_flags & direction ? (msg_ptr->_val ? ++_sequence : ++_osequence) : ++_sequence) << "\' ";
386  if (_flags & thread)
387  ostr << "thread=\'" << get_thread_code(msg_ptr->_tid) << "\' ";
388  if (_flags & location && msg_ptr->_fileline)
389  ostr << "location=\'" << msg_ptr->_fileline << "\' ";
390  if (_flags & direction)
391  ostr << "direction=\'" << (msg_ptr->_val ? " in" : "out") << "\' ";
392  if (_flags & timestamp)
393  ostr << "timestamp=\'" << msg_ptr->_when << "\' ";
394  if (_flags & minitimestamp)
395  ostr << "minitimestamp=\'" << GetTimeAsStringMini(&msg_ptr->_when) << "\' ";
396  if (_flags & level)
397  ostr << "level=\'" << _level_names[msg_ptr->_level] << "\' ";
398 
399  ostr << "text=\'" << msg_ptr->_str << "\'/>";
400  f8_scoped_lock guard(_mutex);
401  get_stream() << ostr.str() << endl;
402 }
f8_mutex _mutex
Definition: logger.hpp:179
unsigned _osequence
Definition: logger.hpp:220
F8API const std::string & GetTimeAsStringMini(std::string &result, const Tickval *tv)
static const Tickval _started
The time the entire logging system was start.
Definition: logger.hpp:229
F8API char get_thread_code(thread_id_t tid)
Definition: logger.cpp:232
string spacer
Definition: f8c.cpp:96
static const std::vector< std::string > _level_names
string representation of levels
Definition: logger.hpp:329
unsigned _sequence
Definition: logger.hpp:220
virtual std::ostream & get_stream() const
Definition: logger.hpp:286
LogFlags _flags
Definition: logger.hpp:181
std::string f8String
Definition: f8types.hpp:47

The documentation for this class was generated from the following files: