Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Setting up fmt with custom config structure for logging system #2964

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
be1e774
[core] New implementation for the logging/formatting system
ethouris May 24, 2024
308af58
Fixed parts in non-default-enabled code parts
ethouris May 24, 2024
5ae2a03
Updated sfmt.h with reimplementation fixes
ethouris May 25, 2024
089dd51
Fixed heavy logging cases and atomics. Withdrawn changes for enums. U…
ethouris May 25, 2024
e37d37d
Provided a special version for atomic. Withdrawn unnecessary changes
ethouris May 26, 2024
6ce84fe
Changed more formatting usage to sfmt
ethouris May 26, 2024
8126c49
Removed ostringstream from utilities
ethouris May 26, 2024
216c1ed
Removed ostringstream use. Fixed C++03 problem with Ensure declaration
May 27, 2024
d8cebcd
Cleared out warn-errors for logging-off version
May 27, 2024
4e39fd7
Moved Printable out of C++11-dependent section (args... no longer nee…
May 27, 2024
5199746
Added extra version of snprintf for old Windows
ethouris May 27, 2024
4843143
Fixed the use of std::atomic
ethouris May 28, 2024
1a0eca4
Fixed the right atomic type used with logging. Fixed some reported sh…
ethouris May 28, 2024
9643702
Fixed a clang-reported warning (to trigger rebuilding)
ethouris May 28, 2024
f4ecbc1
Updated sfmt.h, fixed sync formatting
Jun 17, 2024
b90f540
Updated and merged
Jun 17, 2024
7660e92
Merge branch 'master' into dev-add-sfmt-for-logging
Jun 18, 2024
0a607c7
Some cosmetic fixes. Fixed the use of std::abs
Jun 18, 2024
d2ec1cf
Fixed usage of <cmath> with std
Jun 19, 2024
193fe39
Fixed correct includes for std::div
Jun 19, 2024
c81d4d6
Renamed sfmt.h and moved to srt namespace
Jun 20, 2024
0920fbf
[core] Setting up fmt with iomanip for logging system
Jun 25, 2024
f4088e4
Removed the use of sfmt obufstream
Jun 25, 2024
e48a6cb
Removed named reference to avoid dangling ref warning
Jun 25, 2024
2ba12a0
Added lacking include for sstream
Jun 25, 2024
f16fed7
Cleaned up previous usage of sfmt facilities
Jun 26, 2024
a49bdd9
Provided C++03 version of fmt
Jun 27, 2024
8b4d44c
Added some fixes as attempt to compile in C++03 (failed)
Jul 11, 2024
eed8c3f
Added separate C++03 compatible fmt API
Jul 18, 2024
4b6c56e
Removed commented-out previous code
Jul 18, 2024
e1617ea
Removed commented-out code
Jul 18, 2024
ac3d5d5
Moved overloaded operator << to inside the class
Jul 18, 2024
d1ae64d
Added C++11 flag that could be handled also on Windows
Jul 19, 2024
7472f05
Attempting to force C++11 in MICROSOFT to compile tools
Jul 19, 2024
4acdf00
Changed the way to require C++11 in apps.
Jul 19, 2024
d8bda01
Blocked unused function reported as warn/error
Jul 19, 2024
d0f472f
Merge branch 'master' into dev-add-custom-fmt-for-logging
Jul 22, 2024
061ec3b
Added UDL for fmt_stringview to simplify raw string format passing
Jul 22, 2024
1a6ce38
Added some more fixes with use of ofmt
Jul 23, 2024
05b5bb7
[maint] Removed VC 2013. Added VC 2022
Jul 25, 2024
a8664d2
Merge branch 'main-ci-remove-old-windows' into dev-add-custom-fmt-for…
Jul 26, 2024
880fa9d
Reworked the fmt API
Jul 26, 2024
fecce73
Updated and fixed
Sep 3, 2024
51350b1
Removed copyright notice blindly copied from another project
Sep 3, 2024
f0bfba8
Added more replacement for stringstream. Removed unused CIPAddress::show
Sep 11, 2024
8f82530
Updated and fixed
Sep 24, 2024
6106607
Merge branch 'master' into dev-add-custom-fmt-for-logging
ethouris Sep 24, 2024
a8dbce8
Merge branch 'master' into dev-add-custom-fmt-for-logging
Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/apputil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
#include <chrono>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <utility>
#include <memory>

#include "srt.h" // Required for SRT_SYNC_CLOCK_* definitions.
#include "apputil.hpp"
#include "netinet_any.h"
#include "srt_compat.h"
#include "ofmt.h"

using namespace std;
using namespace srt;
Expand Down Expand Up @@ -144,10 +144,10 @@ sockaddr_any CreateAddr(const string& name, unsigned short port, int pref_family

string Join(const vector<string>& in, string sep)
{
if ( in.empty() )
if (in.empty())
return "";

ostringstream os;
srt::ofmtstream os;

os << in[0];
for (auto i = in.begin()+1; i != in.end(); ++i)
Expand Down
3 changes: 2 additions & 1 deletion apps/logsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "logsupport.hpp"
#include "../srtcore/srt.h"
#include "../srtcore/utilities.h"
#include "../srtcore/ofmt.h"

using namespace std;

Expand Down Expand Up @@ -173,7 +174,7 @@ set<srt_logging::LogFA> SrtParseLogFA(string fa, set<string>* punknown)

void ParseLogFASpec(const vector<string>& speclist, string& w_on, string& w_off)
{
std::ostringstream son, soff;
srt::ofmtstream son, soff;

for (auto& s: speclist)
{
Expand Down
10 changes: 6 additions & 4 deletions apps/transmitmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@
#include <sys/filio.h>
#endif

#define REQUIRE_CXX11 1

#include "srt_attr_defs.h"
#include "netinet_any.h"
#include "ofmt.h"
#include "apputil.hpp"
#include "socketoptions.hpp"
#include "uriparser.hpp"
#include "transmitmedia.hpp"
#include "srt_compat.h"
#include "verbose.hpp"


using namespace std;
using namespace srt;

Expand Down Expand Up @@ -519,10 +524,7 @@ SrtCommon::~SrtCommon()
SrtSource::SrtSource(string host, int port, const map<string,string>& par)
{
Init(host, port, par, false);

ostringstream os;
os << host << ":" << port;
hostport_copy = os.str();
hostport_copy = srt::fmtcat(host, ":"_V, port);
}

int SrtSource::Read(size_t chunk, MediaPacket& pkt, ostream &out_stats)
Expand Down
18 changes: 10 additions & 8 deletions apps/uriparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,46 @@ UriParser::~UriParser(void)

string UriParser::makeUri()
{
using namespace srt;

// Reassemble parts into the URI
string prefix = "";
if (m_proto != "")
{
prefix = m_proto + "://";
}

std::ostringstream out;
ofmtstream out;

out << prefix << m_host;
out.print(prefix, m_host);
if ((m_port == "" || m_port == "0") && m_expect == EXPECT_FILE)
{
// Do not add port
}
else
{
out << ":" << m_port;
out.print(":"_V, m_port);
}

if (m_path != "")
{
if (m_path[0] != '/')
out << "/";
out << m_path;
out.print("/"_V);
out.print(m_path);
}

if (!m_mapQuery.empty())
{
out << "?";
out.print("?"_V);

query_it i = m_mapQuery.begin();
for (;;)
{
out << i->first << "=" << i->second;
out.print(i->first, "="_V, i->second);
++i;
if (i == m_mapQuery.end())
break;
out << "&";
out.print("&"_V);
}
}

Expand Down
10 changes: 5 additions & 5 deletions srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ string srt::CUDTUnited::CONID(SRTSOCKET sock)
if (sock == 0)
return "";

std::ostringstream os;
ofmtstream os;
os << "@" << sock << ":";
return os.str();
}
Expand Down Expand Up @@ -1403,7 +1403,7 @@ int srt::CUDTUnited::groupConnect(CUDTGroup* pg, SRT_SOCKGROUPCONFIG* targets, i
for (size_t i = 0; i < g.m_config.size(); ++i)
{
HLOGC(aclog.Debug, log << "groupConnect: OPTION @" << sid << " #" << g.m_config[i].so);
error_reason = "group-derived option: #" + Sprint(g.m_config[i].so);
error_reason = Sprint("group-derived option: #", g.m_config[i].so);
ns->core().setOpt(g.m_config[i].so, &g.m_config[i].value[0], (int)g.m_config[i].value.size());
}

Expand Down Expand Up @@ -3325,14 +3325,14 @@ bool srt::CUDTUnited::updateListenerMux(CUDTSocket* s, const CUDTSocket* ls)
CMultiplexer& m = i->second;

#if ENABLE_HEAVY_LOGGING
ostringstream that_muxer;
ofmtstream that_muxer;
that_muxer << "id=" << m.m_iID << " port=" << m.m_iPort
<< " ip=" << (m.m_iIPversion == AF_INET ? "v4" : "v6");
#endif

if (m.m_iPort == port)
{
HLOGC(smlog.Debug, log << "updateListenerMux: reusing muxer: " << that_muxer.str());
HLOGC(smlog.Debug, log << "updateListenerMux: reusing muxer: " << that_muxer);
if (m.m_iIPversion == s->m_PeerAddr.family())
{
mux = &m; // best match
Expand All @@ -3346,7 +3346,7 @@ bool srt::CUDTUnited::updateListenerMux(CUDTSocket* s, const CUDTSocket* ls)
}
else
{
HLOGC(smlog.Debug, log << "updateListenerMux: SKIPPING muxer: " << that_muxer.str());
HLOGC(smlog.Debug, log << "updateListenerMux: SKIPPING muxer: " << that_muxer);
}
}

Expand Down
3 changes: 2 additions & 1 deletion srtcore/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,8 @@ srt::EReadStatus srt::CChannel::recvfrom(sockaddr_any& w_addr, CPacket& w_packet
#endif

HLOGC(krlog.Debug,
log << CONID() << "NET ERROR: packet size=" << recv_size << " msg_flags=0x" << hex << msg_flags
log << CONID() << "NET ERROR: packet size=" << recv_size << " msg_flags=0x"
<< fmt(msg_flags, fmtc().hex())
<< ", detected flags:" << flg.str());
#endif
status = RST_AGAIN;
Expand Down
16 changes: 7 additions & 9 deletions srtcore/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,13 @@ void srt::CIPAddress::pton(sockaddr_any& w_addr, const uint32_t ip[4], const soc
}
else
{
LOGC(inlog.Error, log << "pton: IPE or net error: can't determine IPv4 carryover format: " << std::hex
<< peeraddr16[0] << ":"
<< peeraddr16[1] << ":"
<< peeraddr16[2] << ":"
<< peeraddr16[3] << ":"
<< peeraddr16[4] << ":"
<< peeraddr16[5] << ":"
<< peeraddr16[6] << ":"
<< peeraddr16[7] << std::dec);
ofmtstream peeraddr_form;
fmtc hex04; hex04.hex().fillzero().width(4);
peeraddr_form << fmt(peeraddr16[0], hex04);
for (int i = 1; i < 8; ++i)
peeraddr_form << ":" << fmt(peeraddr16[i], hex04);

LOGC(inlog.Error, log << "pton: IPE or net error: can't determine IPv4 carryover format: " << peeraddr_form);
*target_ipv4_addr = 0;
if (peer.family() != AF_INET)
{
Expand Down
63 changes: 38 additions & 25 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ using namespace srt_logging;
const SRTSOCKET UDT::INVALID_SOCK = srt::CUDT::INVALID_SOCK;
const int UDT::ERROR = srt::CUDT::ERROR;

static inline char fmt_onoff(bool val) { return val ? '+' : '-'; }
// Mark unused because it's only used in HLOGC
SRT_ATR_UNUSED static inline const char* fmt_yesno(bool val) { return val ? "yes" : "no"; }

//#define SRT_CMD_HSREQ 1 /* SRT Handshake Request (sender) */
#define SRT_CMD_HSREQ_MINSZ 8 /* Minumum Compatible (1.x.x) packet size (bytes) */
#define SRT_CMD_HSREQ_SZ 12 /* Current version packet size */
Expand Down Expand Up @@ -1774,8 +1778,11 @@ bool srt::CUDT::createSrtHandshake(
m_RejectReason = SRT_REJ_IPE;
LOGC(cnlog.Error,
log << CONID() << "createSrtHandshake: IPE: need to send KM, but CryptoControl does not exist."
<< " Socket state: connected=" << boolalpha << m_bConnected << ", connecting=" << m_bConnecting
<< ", broken=" << m_bBroken << ", closing=" << m_bClosing << ".");
<< " Socket state: "
<< fmt_onoff(m_bConnected) << "connected, "
<< fmt_onoff(m_bConnecting) << "connecting, "
<< fmt_onoff(m_bBroken) << "broken, "
<< fmt_onoff(m_bClosing) << "closing.");
return false;
}

Expand Down Expand Up @@ -2103,8 +2110,9 @@ int srt::CUDT::processSrtMsg_HSREQ(const uint32_t *srtdata, size_t bytelen, uint
}

LOGC(cnlog.Debug, log << "HSREQ/rcv: cmd=" << SRT_CMD_HSREQ << "(HSREQ) len=" << bytelen
<< hex << " vers=0x" << srtdata[SRT_HS_VERSION] << " opts=0x" << srtdata[SRT_HS_FLAGS]
<< dec << " delay=" << SRT_HS_LATENCY_RCV::unwrap(srtdata[SRT_HS_LATENCY]));
<< " vers=0x" << fmt(srtdata[SRT_HS_VERSION], fmtc().hex())
<< " opts=0x" << fmt(srtdata[SRT_HS_FLAGS], fmtc().hex())
<< " delay=" << SRT_HS_LATENCY_RCV::unwrap(srtdata[SRT_HS_LATENCY]));

m_uPeerSrtVersion = srtdata[SRT_HS_VERSION];
m_uPeerSrtFlags = srtdata[SRT_HS_FLAGS];
Expand Down Expand Up @@ -2338,8 +2346,8 @@ int srt::CUDT::processSrtMsg_HSRSP(const uint32_t *srtdata, size_t bytelen, uint
m_uPeerSrtFlags = srtdata[SRT_HS_FLAGS];

HLOGC(cnlog.Debug, log << "HSRSP/rcv: Version: " << SrtVersionString(m_uPeerSrtVersion)
<< " Flags: SND:" << setw(8) << setfill('0') << hex << m_uPeerSrtFlags
<< setw(0) << " (" << SrtFlagString(m_uPeerSrtFlags) << ")");
<< " Flags: SND:" << fmt(m_uPeerSrtFlags, fmtc().hex().fillzero().width(8))
<< " (" << SrtFlagString(m_uPeerSrtFlags) << ")");
// Basic version check
if (m_uPeerSrtVersion < m_config.uMinimumPeerSrtVersion)
{
Expand Down Expand Up @@ -3141,7 +3149,8 @@ bool srt::CUDT::interpretGroup(const int32_t groupdata[], size_t data_size SRT_A
HLOGC(cnlog.Debug,
log << CONID() << "interpretGroup: STATE: HsSide=" << hs_side_name[m_SrtHsSide]
<< " HS MSG: " << MessageTypeStr(UMSG_EXT, hsreq_type_cmd) << " $" << grpid << " type=" << gtp
<< " weight=" << link_weight << " flags=0x" << std::hex << link_flags);
<< " weight=" << link_weight
<< " flags=0x" << fmt(link_flags, fmtc().hex()));
#endif

// XXX Here are two separate possibilities:
Expand Down Expand Up @@ -4102,8 +4111,12 @@ EConnectStatus srt::CUDT::craftKmResponse(uint32_t* aw_kmdata, size_t& w_kmdatas
m_RejectReason = SRT_REJ_IPE;
LOGC(cnlog.Error,
log << CONID() << "IPE: craftKmResponse needs to send KM, but CryptoControl does not exist."
<< " Socket state: connected=" << boolalpha << m_bConnected << ", connecting=" << m_bConnecting
<< ", broken=" << m_bBroken << ", opened " << m_bOpened << ", closing=" << m_bClosing << ".");
<< " Socket state: "
<< fmt_onoff(m_bConnected) << "connected, "
<< fmt_onoff(m_bConnecting) << "connecting, "
<< fmt_onoff(m_bBroken) << "broken, "
<< fmt_onoff(m_bOpened) << "opened, "
<< fmt_onoff(m_bClosing) << "closing.");
return CONN_REJECT;
}
// This is a periodic handshake update, so you need to extract the KM data from the
Expand Down Expand Up @@ -4650,8 +4663,9 @@ EConnectStatus srt::CUDT::processConnectResponse(const CPacket& response, CUDTEx
if (m_ConnRes.m_iReqType == URQ_INDUCTION)
{
HLOGC(cnlog.Debug,
log << CONID() << "processConnectResponse: REQ-TIME LOW; got INDUCTION HS response (cookie:" << hex
<< m_ConnRes.m_iCookie << " version:" << dec << m_ConnRes.m_iVersion
log << CONID() << "processConnectResponse: REQ-TIME LOW; got INDUCTION HS response (cookie:"
<< fmt(m_ConnRes.m_iCookie, fmtc().hex())
<< " version:" << m_ConnRes.m_iVersion
<< "), sending CONCLUSION HS with this cookie");

m_ConnReq.m_iCookie = m_ConnRes.m_iCookie;
Expand Down Expand Up @@ -4758,7 +4772,7 @@ EConnectStatus srt::CUDT::postConnect(const CPacket* pResponse, bool rendezvous,
// in rendezvous it's completed before calling this function.
if (!rendezvous)
{
HLOGC(cnlog.Debug, log << CONID() << boolalpha << "postConnect: packet:" << bool(pResponse) << " rendezvous:" << rendezvous);
HLOGC(cnlog.Debug, log << CONID() << "postConnect: packet:" << fmt_yesno(pResponse) << " rendezvous:" << fmt_yesno(rendezvous));
// The "local storage depleted" case shouldn't happen here, but
// this is a theoretical path that needs prevention.
bool ok = pResponse;
Expand Down Expand Up @@ -5461,14 +5475,14 @@ void * srt::CUDT::tsbpd(void* param)
HLOGC(tslog.Debug,
log << self->CONID() << "tsbpd: DROPSEQ: up to seqno %" << CSeqNo::decseq(info.seqno) << " ("
<< iDropCnt << " packets) playable at " << FormatTime(info.tsbpd_time) << " delayed "
<< (timediff_us / 1000) << "." << std::setw(3) << std::setfill('0') << (timediff_us % 1000) << " ms");
<< (timediff_us / 1000) << "." << fmt(timediff_us % 1000, fmtc().fixed().fillzero().width(3)) << " ms");
#endif
string why;
if (self->frequentLogAllowed(FREQLOGFA_RCV_DROPPED, tnow, (why)))
{
LOGC(brlog.Warn, log << self->CONID() << "RCV-DROPPED " << iDropCnt << " packet(s). Packet seqno %" << info.seqno
<< " delayed for " << (timediff_us / 1000) << "." << std::setw(3) << std::setfill('0')
<< (timediff_us % 1000) << " ms " << why);
<< " delayed for " << (timediff_us / 1000) << "."
<< fmt(timediff_us % 1000, fmtc().fixed().fillzero().width(3)) << " ms " << why);
}
#if SRT_ENABLE_FREQUENT_LOG_TRACE
else
Expand Down Expand Up @@ -7772,7 +7786,7 @@ bool srt::CUDT::updateCC(ETransmissionEvent evt, const EventVariant arg)
HLOGC(rslog.Debug,
log << CONID() << "updateCC: updated values from congctl: interval=" << FormatDuration<DUNIT_US>(m_tdSendInterval)
<< " (cfg:" << m_CongCtl->pktSndPeriod_us() << "us) cgwindow="
<< std::setprecision(3) << cgwindow);
<< fmt(cgwindow, fmtc().precision(7)));
#endif
}

Expand Down Expand Up @@ -8434,7 +8448,7 @@ void srt::CUDT::processCtrlAck(const CPacket &ctrlpkt, const steady_clock::time_
// included, but it also triggers for any other kind of invalid value.
// This check MUST BE DONE before making any operation on this number.
LOGC(inlog.Error, log << CONID() << "ACK: IPE/EPE: received invalid ACK value: " << ackdata_seqno
<< " " << std::hex << ackdata_seqno << " (IGNORED)");
<< " " << fmt(ackdata_seqno, fmtc().hex()) << " (IGNORED)");
return;
}

Expand Down Expand Up @@ -9306,7 +9320,7 @@ void srt::CUDT::updateAfterSrtHandshake(int hsv)
{
ScopedLock glock (uglobal().m_GlobControlLock);
grpspec = m_parent->m_GroupOf
? " group=$" + Sprint(m_parent->m_GroupOf->id())
? Sprint(" group=$", m_parent->m_GroupOf->id())
: string();
}
#else
Expand Down Expand Up @@ -10040,12 +10054,11 @@ int srt::CUDT::checkLazySpawnTsbPdThread()

HLOGP(qrlog.Debug, "Spawning Socket TSBPD thread");
#if ENABLE_HEAVY_LOGGING
std::ostringstream tns1, tns2;
ofmtstream buf;
// Take the last 2 ciphers from the socket ID.
tns1 << setfill('0') << setw(2) << m_SocketID;
std::string s = tns1.str();
tns2 << "SRT:TsbPd:@" << s.substr(s.size()-2, 2);
const string thname = tns2.str();
string s = fmts(m_SocketID, fmtc().fillzero().width(2));
buf << "SRT:TsbPd:@" << s.substr(s.size()-2, 2);
const string thname = buf.str();
#else
const string thname = "SRT:TsbPd";
#endif
Expand Down Expand Up @@ -11093,7 +11106,7 @@ int srt::CUDT::processConnectRequest(const sockaddr_any& addr, CPacket& packet)

int32_t cookie_val = bake(addr);

HLOGC(cnlog.Debug, log << CONID() << "processConnectRequest: new cookie: " << hex << cookie_val);
HLOGC(cnlog.Debug, log << CONID() << "processConnectRequest: new cookie: " << fmt(cookie_val, fmtc().hex()));

// Remember the incoming destination address here and use it as a source
// address when responding. It's not possible to record this address yet
Expand Down Expand Up @@ -11173,7 +11186,7 @@ int srt::CUDT::processConnectRequest(const sockaddr_any& addr, CPacket& packet)
if (hs.m_iCookie != cookie_val)
{
m_RejectReason = SRT_REJ_RDVCOOKIE;
HLOGC(cnlog.Debug, log << CONID() << "processConnectRequest: ...wrong cookie " << hex << cookie_val << ". Ignoring.");
HLOGC(cnlog.Debug, log << CONID() << "processConnectRequest: ...wrong cookie " << fmt(cookie_val, fmtc().hex()) << ". Ignoring.");
return m_RejectReason;
}

Expand Down
Loading
Loading