37 #ifndef FIX8_LOGGER_HPP_
38 #define FIX8_LOGGER_HPP_
42 #include <Poco/Net/IPAddress.h>
43 #include <Poco/Net/DatagramSocket.h>
57 if (c != traits_type::eof())
60 if (write(fd, &z, 1) != 1)
61 return traits_type::eof();
66 virtual std::streamsize
xsputn(
const char *s, std::streamsize num)
68 return write (fd, s, num);
88 :
std::ostream(&buf_), fptr_(fptr), buf_(fileno(fptr)) {}
114 if (c != traits_type::eof())
117 _sock->sendBytes(&z, 1);
122 virtual std::streamsize
xsputn(
const char *s, std::streamsize num)
124 _sock->sendBytes(s, num);
129 bcoutbuf(Poco::Net::DatagramSocket *sock) : _sock(sock) {}
142 bcostream(Poco::Net::DatagramSocket *sock) :
std::ostream(&buf_), buf_(sock) {}
167 start_controls,
append=
start_controls,
buffer,
compress,
pipe,
broadcast,
nolf,
inbound,
outbound,
xml,
num_flags };
198 : _tid(tid), _str(str), _level(level), _fileline(fl),
_val(val) {}
200 : _tid(tid), _str(str), _level(
Info), _fileline(),
_val(val) {}
202 LogElement(
const LogElement& from) : _tid(from._tid), _str(from._str), _level(from._level), _fileline(from._fileline),
240 : _thread(
std::ref(*this)), _flags(flags), _levels(levels), _delim(delim), _positions(positions)
242 if (_positions.empty())
246 _positions.push_back(ii);
281 _positions = positions;
286 virtual std::ostream&
get_stream()
const {
return _ofs ? *_ofs : std::cout; }
297 return _msg_queue.try_push (le) == 0;
315 virtual bool rotate(
bool force=
false) {
return true; }
398 :
FileLogger(pathname, flags, levels, delim, positions, rotnum)
404 void preamble() {
get_stream() <<
"<?xml version='1.0' encoding='ISO-8859-1'?>" << std::endl <<
"<fix8>" << std::endl; }
447 BCLogger(Poco::Net::DatagramSocket *sock,
const LogFlags flags,
const Levels levels,
const std::string delim=
" ",
462 operator void*() {
return _init_ok ?
this : 0; }
481 #
if defined FIX8_BUFFERED_GLOBAL_LOGGING
551 if (c != traits_type::eof())
559 std::streamsize
xsputn(
const char *s, std::streamsize num)
560 { _str.append(s, num);
return num; }
565 const std::string&
get()
const {
return _str; }
576 using logger_function = std::function<bool(const std::string&, Logger::Level, const char *, const unsigned)>;
587 : _logger(func), _lev(lev), _loc(loc), _value(value) {}
601 #define glout_info if (!FIX8::GlobalLogger::is_loggable(FIX8::Logger::Info)); \
602 else FIX8::log_stream(FIX8::logger_function(FIX8::GlobalLogger::enqueue), FIX8::Logger::Info, FILE_LINE)
603 #define glout glout_info
604 #define glout_warn if (!FIX8::GlobalLogger::is_loggable(FIX8::Logger::Warn)); \
605 else FIX8::log_stream(FIX8::logger_function(FIX8::GlobalLogger::enqueue), FIX8::Logger::Warn, FILE_LINE)
606 #define glout_error if (!FIX8::GlobalLogger::is_loggable(FIX8::Logger::Error)); \
607 else FIX8::log_stream(FIX8::logger_function(FIX8::GlobalLogger::enqueue), FIX8::Logger::Error, FILE_LINE)
608 #define glout_fatal if (!FIX8::GlobalLogger::is_loggable(FIX8::Logger::Fatal)); \
609 else FIX8::log_stream(FIX8::logger_function(FIX8::GlobalLogger::enqueue), FIX8::Logger::Fatal, FILE_LINE)
610 #if defined FIX8_DEBUG
611 #define glout_debug if (!FIX8::GlobalLogger::is_loggable(FIX8::Logger::Debug)); \
612 else FIX8::log_stream(FIX8::logger_function(FIX8::GlobalLogger::enqueue), FIX8::Logger::Debug, FILE_LINE)
614 #define glout_debug true ? FIX8::null_insert() : FIX8::null_insert()
617 #endif // FIX8_LOGGER_HPP_
Logger(const LogFlags flags, const Levels levels=Levels(All), const std::string delim=" ", const LogPositions positions=LogPositions())
f8_thread< Logger > _thread
void stop()
Stop the logging thread.
File descriptor output streambuf, inspiration from Josuttis N.M.
A global singleton logger.
static bool enqueue(const std::string &what, Logger::Level lev=Logger::Info, const char *fl=nullptr, unsigned int val=0)
void set_flags(LogFlags flags)
std::map< char, thread_id_t > RevThreadCodes
virtual std::streamsize xsputn(const char *s, std::streamsize num)
f8_thread_cancellation_token & cancellation_token()
static const int rotation_default
std::list< std::string > _buffer
void set_positions(const std::vector< int > &positions)
virtual ~fptrostream()
Dtor.
f8_thread delegated async logging class
static const int StdFlags
std::function< bool(const std::string &, Logger::Level, const char *, const unsigned)> logger_function
bool send(const std::string &what, Level lev=Logger::Info, const char *fl=nullptr, const unsigned val=0)
log_stream(decltype(_logger) func, Logger::Level lev=Logger::Info, const char *loc=nullptr, unsigned value=0)
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)
static void set_positions(Logger::LogPositions positions)
generic pthread_mutex wrapper
static const Tickval _started
The time the entire logging system was start.
F8API char get_thread_code(thread_id_t tid)
Socket output streambuf, inspiration from Josuttis N.M.
void set_delimiter(const std::string &delim)
LogElement(const LogElement &from)
static FileLogger & instance()
RevThreadCodes _rev_thread_codes
Poco::Net::DatagramSocket * _sock
std::streamsize xsputn(const char *s, std::streamsize num)
virtual ~XmlFileLogger()
Dtor.
const size_t max_global_filename_length(1024)
int_type overflow(int_type c)
void preamble()
Write the xml preamble. If you use rotate, you need to call this AFTER rotating.
static bool is_loggable(Logger::Level lev)
static const std::vector< std::string > _bit_names
string representation of logflags
bool has_flag(const Flags flg) const
Thread wrapper. Ctor provides T instance and specifies ptr to member to call or defaults to operator(...
void postamble()
Write the xml postamble. If you use rotate, you need to call this BEFORE rotating.
virtual int_type overflow(int_type c)
Thread cancellation token.
static void set_delimiter(const std::string &delim)
constexpr unsigned bitsum()
empty argument version
static void set_levels(Logger::Levels levels)
std::vector< int > LogPositions
virtual F8API void process_logline(LogElement *le)
const std::string & get() const
virtual int join(int timeoutInMs=0)
static const int max_rotation
static const std::vector< std::string > _level_names
string representation of levels
virtual int_type overflow(int_type c)
virtual F8API bool rotate(bool force=false)
F8API void purge_thread_codes()
Remove dead threads from the thread code cache.
bcoutbuf(Poco::Net::DatagramSocket *sock)
virtual ~bcostream()
Dtor.
generic spin_lock wrapper
tbb::concurrent_bounded_queue< T > f8_concurrent_queue
static const Tickval & get_time_started()
PipeLogger(const std::string &command, const LogFlags flags, const Levels levels, const std::string delim=" ", LogPositions positions=LogPositions())
bool enqueue(const std::string &what, Level lev=Logger::Info, const char *fl=nullptr, const unsigned val=0)
virtual std::ostream & get_stream() const
std::map< thread_id_t, char > ThreadCodes
char * CopyString(const std::string &src, char *target, unsigned limit=0)
virtual F8API void process_logline(LogElement *le)
bcostream(Poco::Net::DatagramSocket *sock)
LogElement(const thread_id_t tid, const std::string &str, Level level, const char *fl=nullptr, const unsigned val=0)
virtual std::streamsize xsputn(const char *s, std::streamsize num)
static void set_global_filename(const std::string &from)
virtual ~FileLogger()
Dtor.
integral_type has(const T sbit) const
F8API char glob_log0[max_global_filename_length]
virtual ~buffered_ostream()
ThreadCodes _thread_codes
f8_concurrent_queue< LogElement > _msg_queue
std::thread::id thread_id_t
bool is_loggable(Level level) const
BCLogger(Poco::Net::DatagramSocket *sock, const LogFlags flags, const Levels levels, const std::string delim=" ", LogPositions positions=LogPositions())
LogElement & operator=(const LogElement &that)
virtual F8API void flush()
Flush the buffer.
LogElement(const thread_id_t tid, const std::string &str, const unsigned val=0)
virtual ~PipeLogger()
Dtor.
static bool log(const std::string &what, Logger::Level lev=Logger::Info, const char *fl=nullptr, unsigned int val=0)
f8_thread_cancellation_token _stopping
virtual bool rotate(bool force=false)
void set_levels(Levels levels)
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)
void request_stop()
Tell the thread to stop.
static void set_flags(Logger::LogFlags flags)