50 "mstart",
"sstart",
"sequence",
"thread",
"timestamp",
"minitimestamp",
"direction",
"level",
"location",
51 "append",
"buffer",
"compress",
"pipe",
"broadcast",
"nolf",
"inbound",
"outbound",
"xml"
68 #if (FIX8_MPMC_SYSTEM == FIX8_MPMC_FF)
69 if (!_msg_queue.try_pop(msg_ptr))
78 if (!_msg_queue.try_pop(msg))
90 if (msg_ptr->
_str.empty())
92 #if (FIX8_MPMC_SYSTEM == FIX8_MPMC_FF)
99 process_logline(msg_ptr);
101 #if (FIX8_MPMC_SYSTEM == FIX8_MPMC_FF)
102 _msg_queue.release(msg_ptr);
114 for (
auto pp : _positions)
117 if (pp < start_controls)
switch (pp)
122 fostr << setw(11) << right << setfill(
'0') << (tvs.
secs() * 1000 + tvs.
msecs());
126 fostr << setw(8) << right << setfill(
'0') << (msg_ptr->
_when - _started).secs();
129 fostr << setw(7) << right << setfill(
'0');
130 if (_flags & direction)
131 fostr << (msg_ptr->
_val ? ++_sequence : ++_osequence);
133 fostr << ++_sequence;
136 fostr << get_thread_code(msg_ptr->
_tid);
143 fostr << (msg_ptr->
_val ?
" in" :
"out");
146 fostr << msg_ptr->
_when;
152 fostr << _level_names[msg_ptr->
_level];
158 if (!fostr.str().empty())
160 if (_delim.size() > 1)
161 ostr << _delim[0] << fostr.str() << _delim[1];
163 ostr << fostr.str() << _delim;
170 string result(ostr.str());
171 if (_delim.size() > 1)
174 result += msg_ptr->
_str;
178 result += msg_ptr->
_str;
179 _buffer.push_back(result);
184 if (_delim.size() > 1)
185 get_stream() << ostr.str() << _delim[0] << msg_ptr->
_str << _delim[1];
187 get_stream() << ostr.str() << msg_ptr->
_str;
189 get_stream().flush();
191 get_stream() << endl;
199 for (
const auto& pp : _buffer)
200 get_stream() << pp << endl;
208 #if (FIX8_THREAD_SYSTEM == FIX8_THREAD_PTHREAD)
211 for (ThreadCodes::iterator itr(_thread_codes.begin()); itr != _thread_codes.end();)
213 #if defined _MSC_VER || defined __APPLE__
215 if (pthread_kill(itr->first, 0) == ESRCH)
219 if (pthread_getcpuclockid(itr->first, &clock_id) == ESRCH)
222 _rev_thread_codes.erase(itr->second);
223 _thread_codes.erase(itr++);
236 ThreadCodes::const_iterator itr(_thread_codes.find(tid));
237 if (itr != _thread_codes.end())
240 for (
char acode(
'A'); acode < 127; ++acode)
242 RevThreadCodes::const_iterator itr(_rev_thread_codes.find(acode));
243 if (itr == _rev_thread_codes.end())
245 _thread_codes.insert({tid, acode});
246 _rev_thread_codes.insert({acode, tid});
256 const std::string delim,
const LogPositions positions,
const unsigned rotnum)
257 :
Logger(flags, levels, delim, positions), _rotnum(rotnum)
275 if (!dirpart.empty() && !
exist(dirpart))
278 #ifdef HAVE_COMPRESSION
285 rlst.push_back(thislFile);
293 rlst.push_back(ostr.str());
296 for (
unsigned ii(
_rotnum); ii; --ii)
297 rename (rlst[ii - 1].c_str(), rlst[ii].c_str());
300 const ios_base::openmode mode (
_flags &
append ? ios_base::out | ios_base::app : ios_base::out);
301 #ifdef HAVE_COMPRESSION
303 _ofs =
new ogzstream(thislFile.c_str(), mode);
306 _ofs =
new ofstream(thislFile.c_str(), mode);
317 :
Logger(flags, levels, delim, positions)
319 const string pathname(fname.substr(1));
322 throw f8Exception(
"pipe command must be prefixed with '|'");
325 FILE *pcmd(_popen(pathname.c_str(),
"w"));
327 FILE *pcmd(popen(pathname.c_str(),
"w"));
331 glout_info <<
"PipeLogger: " << pathname <<
": failed to execute";
343 :
Logger(flags, levels, delim, positions), _init_ok(true)
349 BCLogger::BCLogger(
const string& ip,
const unsigned port,
const LogFlags flags,
const Levels levels,
350 const std::string delim,
const LogPositions positions)
351 :
Logger(flags, levels, delim, positions), _init_ok()
353 Poco::Net::IPAddress ipaddr;
354 if (Poco::Net::IPAddress::tryParse(ip, ipaddr)
355 && (ipaddr.isGlobalMC() || ipaddr.isMulticast() || ipaddr.isBroadcast()
356 || ipaddr.isLinkLocalMC() || ipaddr.isUnicast() || ipaddr.isWellKnownMC()
357 || ipaddr.isSiteLocalMC() || ipaddr.isOrgLocalMC()))
359 Poco::Net::SocketAddress saddr(ipaddr, port);
360 Poco::Net::DatagramSocket *dgs(
new Poco::Net::DatagramSocket);
361 if (ipaddr.isBroadcast())
362 dgs->setBroadcast(
true);
376 ostr << spacer <<
"<logline ";
380 ostr <<
"mstart=\'" << (tvs.
secs() * 1000 + tvs.
msecs()) <<
"\' ";
383 ostr <<
"sstart=\'" << (msg_ptr->
_when -
_started).secs() <<
"\' ";
389 ostr <<
"location=\'" << msg_ptr->
_fileline <<
"\' ";
391 ostr <<
"direction=\'" << (msg_ptr->
_val ?
" in" :
"out") <<
"\' ";
393 ostr <<
"timestamp=\'" << msg_ptr->
_when <<
"\' ";
399 ostr <<
"text=\'" << msg_ptr->
_str <<
"\'/>";
F8API const std::string & GetTimeAsStringMini(std::string &result, const Tickval *tv)
f8_thread delegated async logging class
static const Tickval _started
The time the entire logging system was start.
F8API char get_thread_code(thread_id_t tid)
const string & filepart(const string &source, string &where)
F8API void create_path(const std::string &path)
const size_t max_global_filename_length(1024)
static const std::vector< std::string > _bit_names
string representation of logflags
std::vector< int > LogPositions
virtual F8API void process_logline(LogElement *le)
static const int max_rotation
static const std::vector< std::string > _level_names
string representation of levels
virtual F8API bool rotate(bool force=false)
F8API void purge_thread_codes()
Remove dead threads from the thread code cache.
PipeLogger(const std::string &command, const LogFlags flags, const Levels levels, const std::string delim=" ", LogPositions positions=LogPositions())
virtual std::ostream & get_stream() const
int hypersleep< h_microseconds >(unsigned amt)
virtual F8API void process_logline(LogElement *le)
void split_path(const std::string &source, std::string &filepart, std::string &dirpart)
integral_type has(const T sbit) const
F8API char glob_log0[max_global_filename_length]
std::thread::id thread_id_t
BCLogger(Poco::Net::DatagramSocket *sock, const LogFlags flags, const Levels levels, const std::string delim=" ", LogPositions positions=LogPositions())
virtual F8API void flush()
Flush the buffer.
bool exist(const std::string &fname)
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)
Could not open a logfile.