fix8
version 1.4.0
Open Source C++ FIX Framework
|
f8_thread delegated async logging class More...
#include <logger.hpp>
Classes | |
struct | LogElement |
Public Types | |
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 > |
Public Member Functions | |
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... | |
virtual bool | rotate (bool force=false) |
F8API int | operator() () |
virtual F8API void | process_logline (LogElement *le) |
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_token & | cancellation_token () |
Static Public Member Functions | |
static const Tickval & | get_time_started () |
Static Public Attributes | |
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 | |
using | ThreadCodes = std::map< thread_id_t, char > |
using | RevThreadCodes = std::map< char, thread_id_t > |
Protected Attributes | |
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 | |
static const Tickval | _started { true } |
The time the entire logging system was start. More... | |
Private Attributes | |
f8_thread< Logger > | _thread |
std::list< std::string > | _buffer |
f8_thread delegated async logging class
Definition at line 153 of file logger.hpp.
using FIX8::Logger::Levels = ebitset<Level> |
Definition at line 175 of file logger.hpp.
using FIX8::Logger::LogFlags = ebitset<Flags> |
Definition at line 174 of file logger.hpp.
using FIX8::Logger::LogPositions = std::vector<int> |
Definition at line 176 of file logger.hpp.
|
protected |
Definition at line 225 of file logger.hpp.
|
protected |
Definition at line 222 of file logger.hpp.
enum FIX8::Logger::Flags |
Enumerator | |
---|---|
mstart | |
sstart | |
sequence | |
thread | |
timestamp | |
minitimestamp | |
direction | |
level | |
location | |
start_controls | |
append | |
buffer | |
compress | |
pipe | |
broadcast | |
nolf | |
inbound | |
outbound | |
xml | |
num_flags |
Definition at line 166 of file logger.hpp.
enum FIX8::Logger::Level |
Enumerator | |
---|---|
Debug | |
Info | |
Warn | |
Error | |
Fatal |
Definition at line 159 of file logger.hpp.
|
inline |
Ctor.
flags | ebitset flags |
levels | ebitset levels |
delim | field delimiter |
positions | field positions |
Definition at line 239 of file logger.hpp.
References mstart, num_flags, and FIX8::f8_thread< T >::start().
|
inlinevirtual |
|
inline |
Get the thread cancellation token
Definition at line 352 of file logger.hpp.
References _stopping.
|
inline |
Log a string with log level. Ignore level and always enqueue.
what | the string to log |
lev | log level (enum) |
fl | pointer to fileline |
val | optional value for the logger to use |
Definition at line 294 of file logger.hpp.
Referenced by FIX8::SingleLogger< fn >::enqueue(), FIX8::Session::enqueue(), send(), and stop().
|
virtual |
Flush the buffer.
Definition at line 196 of file logger.cpp.
Referenced by FIX8::SingleLogger< fn >::flush_log().
|
inlinevirtual |
Get the underlying stream object.
Definition at line 286 of file logger.hpp.
Referenced by FIX8::XmlFileLogger::postamble(), FIX8::XmlFileLogger::preamble(), and FIX8::XmlFileLogger::process_logline().
char Logger::get_thread_code | ( | thread_id_t | tid | ) |
Get the thread code for this thread or allocate a new code if not found.
tid | the thread id of the thread to get a code for |
Definition at line 232 of file logger.cpp.
Referenced by FIX8::XmlFileLogger::process_logline().
|
inlinestatic |
Get te time the logging syste started (actual system startup)
Definition at line 333 of file logger.hpp.
References _started.
|
inline |
Check if the given log flag is set
flg | flag bit to check |
Definition at line 338 of file logger.hpp.
References FIX8::ebitset< T, B >::has().
Referenced by FIX8::Session::process(), and FIX8::Session::send_process().
|
inline |
Check if the given log level is set for this logger
level | level to test |
Definition at line 262 of file logger.hpp.
References level.
Referenced by FIX8::SingleLogger< fn >::is_loggable(), FIX8::Session::is_loggable(), and send().
int Logger::operator() | ( | ) |
The logging thread entry point.
Definition at line 60 of file logger.cpp.
References FIX8::Logger::LogElement::_str, and FIX8::hypersleep< h_microseconds >().
|
virtual |
Process this logelement
le | LogElement |
Reimplemented in FIX8::XmlFileLogger.
Definition at line 110 of file logger.cpp.
References FIX8::Logger::LogElement::_fileline, FIX8::Logger::LogElement::_level, FIX8::Logger::LogElement::_str, FIX8::Logger::LogElement::_tid, FIX8::Logger::LogElement::_val, FIX8::Logger::LogElement::_when, FIX8::GetTimeAsStringMini(), FIX8::Tickval::msecs(), FIX8::f8_scoped_lock_impl< T >::release(), and FIX8::Tickval::secs().
void Logger::purge_thread_codes | ( | ) |
Remove dead threads from the thread code cache.
Definition at line 206 of file logger.cpp.
Referenced by FIX8::Session::start().
|
inlinevirtual |
Perform logfile rotation. Only relevant for file-type loggers.
force | the rotation (even if the file is set to append) |
Reimplemented in FIX8::FileLogger.
Definition at line 315 of file logger.hpp.
|
inline |
Log a string with log level.
what | the string to log |
lev | log level (enum) |
fl | pointer to fileline |
val | optional value for the logger to use |
Definition at line 306 of file logger.hpp.
References enqueue(), and is_loggable().
Referenced by FIX8::SingleLogger< fn >::log(), FIX8::Session::log(), and FIX8::Session::plog().
|
inline |
Set the field delimiter
delim | delimiter value to set |
Definition at line 274 of file logger.hpp.
Referenced by FIX8::SingleLogger< fn >::set_delimiter().
|
inline |
Set the LogFlags
flags | flags to set |
Definition at line 270 of file logger.hpp.
Referenced by FIX8::SingleLogger< fn >::set_flags().
|
inline |
Set the Log Levels
levels | levels to set |
Definition at line 266 of file logger.hpp.
Referenced by FIX8::SingleLogger< fn >::set_levels().
|
inline |
Set the log attribute positions
positions | positions to set |
Definition at line 278 of file logger.hpp.
Referenced by FIX8::SingleLogger< fn >::set_positions().
|
inline |
Stop the logging thread.
Definition at line 310 of file logger.hpp.
References enqueue(), FIX8::_f8_threadcore::join(), and FIX8::f8_thread_cancellation_token::request_stop().
Referenced by FIX8::SingleLogger< fn >::stop(), ~Logger(), and FIX8::Session::~Session().
|
static |
string representation of logflags
Definition at line 326 of file logger.hpp.
Referenced by FIX8::Configuration::create_logger().
|
private |
Definition at line 156 of file logger.hpp.
|
protected |
Definition at line 183 of file logger.hpp.
|
protected |
Definition at line 181 of file logger.hpp.
Referenced by FIX8::BCLogger::BCLogger(), FIX8::PipeLogger::PipeLogger(), FIX8::XmlFileLogger::process_logline(), and FIX8::FileLogger::rotate().
|
static |
string representation of levels
Definition at line 329 of file logger.hpp.
Referenced by FIX8::Configuration::create_logger(), and FIX8::XmlFileLogger::process_logline().
|
protected |
Definition at line 182 of file logger.hpp.
|
protected |
Definition at line 185 of file logger.hpp.
|
protected |
Definition at line 180 of file logger.hpp.
|
protected |
Definition at line 219 of file logger.hpp.
|
protected |
Definition at line 179 of file logger.hpp.
Referenced by FIX8::XmlFileLogger::process_logline(), and FIX8::FileLogger::rotate().
|
protected |
Definition at line 184 of file logger.hpp.
Referenced by FIX8::BCLogger::BCLogger(), FIX8::PipeLogger::PipeLogger(), FIX8::FileLogger::rotate(), and ~Logger().
|
protected |
Definition at line 220 of file logger.hpp.
Referenced by FIX8::XmlFileLogger::process_logline().
|
protected |
Definition at line 231 of file logger.hpp.
|
protected |
Definition at line 226 of file logger.hpp.
|
protected |
Definition at line 220 of file logger.hpp.
Referenced by FIX8::XmlFileLogger::process_logline().
|
staticprotected |
The time the entire logging system was start.
Definition at line 229 of file logger.hpp.
Referenced by get_time_started(), and FIX8::XmlFileLogger::process_logline().
|
protected |
Definition at line 186 of file logger.hpp.
Referenced by cancellation_token().
Definition at line 155 of file logger.hpp.
|
protected |
Definition at line 223 of file logger.hpp.
Definition at line 161 of file logger.hpp.
Referenced by FIX8::Configuration::create_logger(), and FIX8::SingleLogger< fn >::instance().
Definition at line 161 of file logger.hpp.
|
static |
Definition at line 173 of file logger.hpp.
Referenced by FIX8::FilePersister::initialise(), and FIX8::FileLogger::rotate().
|
static |
Definition at line 165 of file logger.hpp.
Referenced by FIX8::Configuration::create_logger().
|
static |
Definition at line 173 of file logger.hpp.
Definition at line 169 of file logger.hpp.
Referenced by FIX8::Configuration::create_logger().