From 8c54bba8bf0032c4df729cd6a0061a9d9e994824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Ma=C5=82ecki?= Date: Thu, 14 Feb 2019 13:01:47 +0100 Subject: [PATCH 1/4] Changed prefix handling in logging into static char arrays. This avoids using std::string during initialization time. --- srtcore/logging.h | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/srtcore/logging.h b/srtcore/logging.h index 614ef7948..bffa5b984 100644 --- a/srtcore/logging.h +++ b/srtcore/logging.h @@ -133,7 +133,8 @@ struct SRT_API LogDispatcher private: int fa; LogLevel::type level; - std::string prefix; + static const size_t MAX_PREFIX_SIZE = 32; + char prefix[MAX_PREFIX_SIZE+1]; LogConfig* src_config; pthread_mutex_t mutex; @@ -141,13 +142,27 @@ struct SRT_API LogDispatcher public: - LogDispatcher(int functional_area, LogLevel::type log_level, const std::string& pfx, LogConfig& config): + LogDispatcher(int functional_area, LogLevel::type log_level, const char* your_pfx, + const char* logger_pfx /*[[nullable]]*/, LogConfig& config): fa(functional_area), level(log_level), - prefix(pfx), - //enabled(false), src_config(&config) { + // XXX stpcpy desired, but not enough portable + // Composing the exact prefix is not critical, so simply + // cut the prefix, if the lenght is exceeded + + // See Logger::Logger; we know this has normally 2 characters, + // except !!FATAL!!, which has 9. Still less than 32. + strcpy(prefix, your_pfx); + + // If the size of the FA name together with severity exceeds the size, + // just skip the former. + if (logger_pfx && strlen(prefix) + strlen(logger_pfx) < MAX_PREFIX_SIZE) + { + strcat(prefix, ":"); + strcat(prefix, logger_pfx); + } pthread_mutex_init(&mutex, 0); } @@ -346,7 +361,6 @@ struct LogDispatcher::Proxy class Logger { - std::string m_prefix; int m_fa; LogConfig& m_config; @@ -358,15 +372,14 @@ class Logger LogDispatcher Error; LogDispatcher Fatal; - Logger(int functional_area, LogConfig& config, std::string globprefix = std::string()): - m_prefix( globprefix == "" ? globprefix : ": " + globprefix), + Logger(int functional_area, LogConfig& config, const char* logger_pfx = NULL): m_fa(functional_area), m_config(config), - Debug ( m_fa, LogLevel::debug, " D" + m_prefix, m_config ), - Note ( m_fa, LogLevel::note, ".N" + m_prefix, m_config ), - Warn ( m_fa, LogLevel::warning, "!W" + m_prefix, m_config ), - Error ( m_fa, LogLevel::error, "*E" + m_prefix, m_config ), - Fatal ( m_fa, LogLevel::fatal, "!!FATAL!!" + m_prefix, m_config ) + Debug ( m_fa, LogLevel::debug, " D", logger_pfx, m_config ), + Note ( m_fa, LogLevel::note, ".N", logger_pfx, m_config ), + Warn ( m_fa, LogLevel::warning, "!W", logger_pfx, m_config ), + Error ( m_fa, LogLevel::error, "*E", logger_pfx, m_config ), + Fatal ( m_fa, LogLevel::fatal, "!!FATAL!!", logger_pfx, m_config ) { } From a4e20bd6efb2dcb5d33d3fa2c462386cd6f3b80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Ma=C5=82ecki?= Date: Fri, 15 Feb 2019 16:54:39 +0100 Subject: [PATCH 2/4] Put all logger objects into the logging namespace to avoid name conflicts --- srtcore/api.cpp | 5 ++--- srtcore/buffer.cpp | 3 +-- srtcore/channel.cpp | 4 +--- srtcore/core.cpp | 37 ++++++++++++++++++++++++++----------- srtcore/core.h | 9 +++++++-- srtcore/crypto.cpp | 2 +- srtcore/crypto.h | 7 ++++++- srtcore/packet.cpp | 6 +++++- srtcore/queue.cpp | 1 + srtcore/smoother.cpp | 1 + 10 files changed, 51 insertions(+), 24 deletions(-) diff --git a/srtcore/api.cpp b/srtcore/api.cpp index 0c025e7f7..8bb5d1184 100644 --- a/srtcore/api.cpp +++ b/srtcore/api.cpp @@ -68,10 +68,9 @@ modified by #endif using namespace std; +using namespace logging; +extern LogConfig srt_logger_config; -extern logging::LogConfig srt_logger_config; - -extern logging::Logger mglog; CUDTSocket::CUDTSocket(): m_Status(SRTS_INIT), diff --git a/srtcore/buffer.cpp b/srtcore/buffer.cpp index b09e55b48..070390985 100644 --- a/srtcore/buffer.cpp +++ b/srtcore/buffer.cpp @@ -58,8 +58,7 @@ modified by #include "logging.h" using namespace std; - -extern logging::Logger mglog, dlog, tslog; +using namespace logging; CSndBuffer::CSndBuffer(int size, int mss): m_BufLock(), diff --git a/srtcore/channel.cpp b/srtcore/channel.cpp index c42986406..c2ac730be 100644 --- a/srtcore/channel.cpp +++ b/srtcore/channel.cpp @@ -91,9 +91,7 @@ modified by #endif using namespace std; - - -extern logging::Logger mglog; +using namespace logging; CChannel::CChannel(): m_iIPversion(AF_INET), diff --git a/srtcore/core.cpp b/srtcore/core.cpp index b4bb3a9b0..dd34cfcfd 100755 --- a/srtcore/core.cpp +++ b/srtcore/core.cpp @@ -80,13 +80,16 @@ modified by using namespace std; +namespace logging +{ + struct AllFaOn { logging::LogConfig::fa_bitset_t allfa; AllFaOn() { - allfa.set(SRT_LOGFA_BSTATS, true); +// allfa.set(SRT_LOGFA_BSTATS, true); allfa.set(SRT_LOGFA_CONTROL, true); allfa.set(SRT_LOGFA_DATA, true); allfa.set(SRT_LOGFA_TSBPD, true); @@ -97,14 +100,26 @@ struct AllFaOn } } logger_fa_all; -SRT_API logging::LogConfig srt_logger_config (logger_fa_all.allfa); +} + +// We need it outside the namespace to preserve the global name. +// It's a part of "hidden API" (used by applications) +SRT_API logging::LogConfig srt_logger_config (logging::logger_fa_all.allfa); + +namespace logging +{ + +Logger glog(SRT_LOGFA_GENERAL, srt_logger_config, "SRT.g"); +// Unused. If not found useful, maybe reuse for another FA. +//Logger blog(SRT_LOGFA_BSTATS, srt_logger_config, "SRT.b"); +Logger mglog(SRT_LOGFA_CONTROL, srt_logger_config, "SRT.c"); +Logger dlog(SRT_LOGFA_DATA, srt_logger_config, "SRT.d"); +Logger tslog(SRT_LOGFA_TSBPD, srt_logger_config, "SRT.t"); +Logger rxlog(SRT_LOGFA_REXMIT, srt_logger_config, "SRT.r"); + +} -logging::Logger glog(SRT_LOGFA_GENERAL, srt_logger_config, "SRT.g"); -logging::Logger blog(SRT_LOGFA_BSTATS, srt_logger_config, "SRT.b"); -logging::Logger mglog(SRT_LOGFA_CONTROL, srt_logger_config, "SRT.c"); -logging::Logger dlog(SRT_LOGFA_DATA, srt_logger_config, "SRT.d"); -logging::Logger tslog(SRT_LOGFA_TSBPD, srt_logger_config, "SRT.t"); -logging::Logger rxlog(SRT_LOGFA_REXMIT, srt_logger_config, "SRT.r"); +using namespace logging; CUDTUnited CUDT::s_UDTUnited; @@ -4231,7 +4246,7 @@ void* CUDT::tsbpd(void* param) timediff = int64_t(tsbpdtime) - int64_t(CTimer::getTime()); #if ENABLE_HEAVY_LOGGING HLOGC(tslog.Debug, log << self->CONID() << "tsbpd: DROPSEQ: up to seq=" << CSeqNo::decseq(skiptoseqno) - << " (" << seqlen << " packets) playable at " << logging::FormatTime(tsbpdtime) << " delayed " + << " (" << seqlen << " packets) playable at " << FormatTime(tsbpdtime) << " delayed " << (timediff/1000) << "." << (timediff%1000) << " ms"); #endif LOGC(dlog.Debug, log << "RCV-DROPPED packet delay=" << (timediff/1000) << "ms"); @@ -4284,7 +4299,7 @@ void* CUDT::tsbpd(void* param) self->m_bTsbPdAckWakeup = false; THREAD_PAUSED(); HLOGC(tslog.Debug, log << self->CONID() << "tsbpd: FUTURE PACKET seq=" << current_pkt_seq - << " T=" << logging::FormatTime(tsbpdtime) << " - waiting " << (timediff/1000.0) << "ms"); + << " T=" << FormatTime(tsbpdtime) << " - waiting " << (timediff/1000.0) << "ms"); CTimer::condTimedWaitUS(&self->m_RcvTsbPdCond, &self->m_RecvLock, timediff); THREAD_RESUMED(); } @@ -8387,7 +8402,7 @@ void CUDT::checkTimers() // This is a very heavy log, unblock only for temporary debugging! #if 0 - HLOGC(mglog.Debug, log << CONID() << "checkTimers: nextacktime=" << logging::FormatTime(m_ullNextACKTime_tk) + HLOGC(mglog.Debug, log << CONID() << "checkTimers: nextacktime=" << FormatTime(m_ullNextACKTime_tk) << " AckInterval=" << m_iACKInterval << " pkt-count=" << m_iPktCount << " liteack-count=" << m_iLightACKCount); #endif diff --git a/srtcore/core.h b/srtcore/core.h index 4fc8d5fb6..455486683 100644 --- a/srtcore/core.h +++ b/srtcore/core.h @@ -73,14 +73,19 @@ modified by #include -extern logging::Logger +namespace logging +{ + +extern Logger glog, - blog, +// blog, mglog, dlog, tslog, rxlog; +} + // XXX Utility function - to be moved to utilities.h? template diff --git a/srtcore/crypto.cpp b/srtcore/crypto.cpp index 2ba8e7f36..5066358a2 100644 --- a/srtcore/crypto.cpp +++ b/srtcore/crypto.cpp @@ -25,7 +25,7 @@ written by #include "logging.h" #include "core.h" -extern logging::Logger mglog, dlog; +using namespace logging; #define SRT_MAX_KMRETRY 10 diff --git a/srtcore/crypto.h b/srtcore/crypto.h index f79d54ae2..9dd24a4d5 100644 --- a/srtcore/crypto.h +++ b/srtcore/crypto.h @@ -32,7 +32,10 @@ written by std::string KmStateStr(SRT_KM_STATE state); -extern logging::Logger mglog; +namespace logging +{ +extern Logger mglog; +} #endif @@ -152,6 +155,8 @@ class CCryptoControl /// during transmission (otherwise it's during the handshake) void getKmMsg_markSent(size_t ki, bool runtime) { + using logging::mglog; + m_SndKmLastTime = CTimer::getTime(); if (runtime) { diff --git a/srtcore/packet.cpp b/srtcore/packet.cpp index bcf18e62d..93f482a3a 100644 --- a/srtcore/packet.cpp +++ b/srtcore/packet.cpp @@ -164,7 +164,11 @@ modified by #include "packet.h" #include "logging.h" -extern logging::Logger mglog; +namespace logging +{ + extern Logger mglog; +} +using namespace logging; // Set up the aliases in the constructure CPacket::CPacket(): diff --git a/srtcore/queue.cpp b/srtcore/queue.cpp index e256deeb7..994efca9a 100644 --- a/srtcore/queue.cpp +++ b/srtcore/queue.cpp @@ -64,6 +64,7 @@ modified by #include "queue.h" using namespace std; +using namespace logging; CUnitQueue::CUnitQueue(): m_pQEntry(NULL), diff --git a/srtcore/smoother.cpp b/srtcore/smoother.cpp index 724d7905f..4111dfb92 100644 --- a/srtcore/smoother.cpp +++ b/srtcore/smoother.cpp @@ -34,6 +34,7 @@ #include "logging.h" using namespace std; +using namespace logging; SmootherBase::SmootherBase(CUDT* parent) { From ac593fea5273d08c923d0bd16490e75f9ed7bbfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Ma=C5=82ecki?= Date: Fri, 15 Feb 2019 19:20:21 +0100 Subject: [PATCH 3/4] Changed namespace logging into srt_logging --- apps/logsupport.cpp | 8 ++++---- apps/logsupport.hpp | 4 ++-- apps/srt-file-transmit.cpp | 4 ++-- apps/srt-live-transmit.cpp | 4 ++-- apps/srt-multiplex.cpp | 6 +++--- srtcore/api.cpp | 10 +++++----- srtcore/buffer.cpp | 4 ++-- srtcore/channel.cpp | 2 +- srtcore/common.cpp | 16 +++++++++++----- srtcore/core.cpp | 10 +++++----- srtcore/core.h | 2 +- srtcore/crypto.cpp | 2 +- srtcore/crypto.h | 4 ++-- srtcore/logging.h | 4 ++-- srtcore/logging_api.h | 2 +- srtcore/packet.cpp | 4 ++-- srtcore/queue.cpp | 2 +- srtcore/smoother.cpp | 2 +- srtcore/srt_c_api.cpp | 6 +++--- srtcore/udt.h | 12 ++++++------ testing/srt-test-file.cpp | 4 ++-- testing/srt-test-live.cpp | 10 +++++++--- testing/srt-test-relay.cpp | 4 ++-- 23 files changed, 68 insertions(+), 58 deletions(-) diff --git a/apps/logsupport.cpp b/apps/logsupport.cpp index e9c354bb9..cd3a4bd4f 100644 --- a/apps/logsupport.cpp +++ b/apps/logsupport.cpp @@ -44,9 +44,9 @@ map srt_level_names -logging::LogLevel::type SrtParseLogLevel(string level) +srt_logging::LogLevel::type SrtParseLogLevel(string level) { - using namespace logging; + using namespace srt_logging; if ( level.empty() ) return LogLevel::fatal; @@ -74,9 +74,9 @@ logging::LogLevel::type SrtParseLogLevel(string level) return LogLevel::type(i->second); } -set SrtParseLogFA(string fa) +set SrtParseLogFA(string fa) { - using namespace logging; + using namespace srt_logging; set fas; diff --git a/apps/logsupport.hpp b/apps/logsupport.hpp index 2ef7bcfea..2bc3cb5ea 100644 --- a/apps/logsupport.hpp +++ b/apps/logsupport.hpp @@ -14,8 +14,8 @@ #include "../srtcore/srt.h" #include "../srtcore/logging_api.h" -logging::LogLevel::type SrtParseLogLevel(std::string level); -std::set SrtParseLogFA(std::string fa); +srt_logging::LogLevel::type SrtParseLogLevel(std::string level); +std::set SrtParseLogFA(std::string fa); SRT_API extern std::map srt_level_names; diff --git a/apps/srt-file-transmit.cpp b/apps/srt-file-transmit.cpp index 239860676..1084384f0 100644 --- a/apps/srt-file-transmit.cpp +++ b/apps/srt-file-transmit.cpp @@ -45,7 +45,7 @@ written by bool Upload(UriParser& srt, UriParser& file); bool Download(UriParser& srt, UriParser& file); -const logging::LogFA SRT_LOGFA_APP = 10; +const srt_logging::LogFA SRT_LOGFA_APP = 10; static size_t g_buffer_size = 1456; static bool g_skip_flushing = false; @@ -95,7 +95,7 @@ int main( int argc, char** argv ) } string loglevel = Option(params, "error", o_loglevel); - logging::LogLevel::type lev = SrtParseLogLevel(loglevel); + srt_logging::LogLevel::type lev = SrtParseLogLevel(loglevel); UDT::setloglevel(lev); UDT::addlogfa(SRT_LOGFA_APP); diff --git a/apps/srt-live-transmit.cpp b/apps/srt-live-transmit.cpp index 0f7d04039..55993b088 100644 --- a/apps/srt-live-transmit.cpp +++ b/apps/srt-live-transmit.cpp @@ -235,8 +235,8 @@ int main( int argc, char** argv ) std::ofstream logfile_stream; // leave unused if not set srt_setloglevel(SrtParseLogLevel(loglevel)); - set fas = SrtParseLogFA(logfa); - for (set::iterator i = fas.begin(); i != fas.end(); ++i) + set fas = SrtParseLogFA(logfa); + for (set::iterator i = fas.begin(); i != fas.end(); ++i) srt_addlogfa(*i); char NAME[] = "SRTLIB"; diff --git a/apps/srt-multiplex.cpp b/apps/srt-multiplex.cpp index 7725f3ec4..1da34dd6c 100644 --- a/apps/srt-multiplex.cpp +++ b/apps/srt-multiplex.cpp @@ -47,8 +47,8 @@ using namespace std; // So far, this function must be used and up to this length of payload. const size_t DEFAULT_CHUNK = 1316; -const logging::LogFA SRT_LOGFA_APP = 10; -logging::Logger applog(SRT_LOGFA_APP, srt_logger_config, "srt-mplex"); +const srt_logging::LogFA SRT_LOGFA_APP = 10; +srt_logging::Logger applog(SRT_LOGFA_APP, srt_logger_config, "srt-mplex"); volatile bool siplex_int_state = false; void OnINT_SetIntState(int) @@ -545,7 +545,7 @@ int main( int argc, char** argv ) } string loglevel = Option(params, "error", "ll", "loglevel"); - logging::LogLevel::type lev = SrtParseLogLevel(loglevel); + srt_logging::LogLevel::type lev = SrtParseLogLevel(loglevel); UDT::setloglevel(lev); UDT::addlogfa(SRT_LOGFA_APP); diff --git a/srtcore/api.cpp b/srtcore/api.cpp index 8bb5d1184..57f916491 100644 --- a/srtcore/api.cpp +++ b/srtcore/api.cpp @@ -68,7 +68,7 @@ modified by #endif using namespace std; -using namespace logging; +using namespace srt_logging; extern LogConfig srt_logger_config; @@ -3077,25 +3077,25 @@ SRT_SOCKSTATUS getsockstate(SRTSOCKET u) return CUDT::getsockstate(u); } -void setloglevel(logging::LogLevel::type ll) +void setloglevel(LogLevel::type ll) { CGuard gg(srt_logger_config.mutex); srt_logger_config.max_level = ll; } -void addlogfa(logging::LogFA fa) +void addlogfa(LogFA fa) { CGuard gg(srt_logger_config.mutex); srt_logger_config.enabled_fa.set(fa, true); } -void dellogfa(logging::LogFA fa) +void dellogfa(LogFA fa) { CGuard gg(srt_logger_config.mutex); srt_logger_config.enabled_fa.set(fa, false); } -void resetlogfa(set fas) +void resetlogfa(set fas) { CGuard gg(srt_logger_config.mutex); for (int i = 0; i <= SRT_LOGFA_LASTNONE; ++i) diff --git a/srtcore/buffer.cpp b/srtcore/buffer.cpp index 070390985..f5c928773 100644 --- a/srtcore/buffer.cpp +++ b/srtcore/buffer.cpp @@ -58,7 +58,7 @@ modified by #include "logging.h" using namespace std; -using namespace logging; +using namespace srt_logging; CSndBuffer::CSndBuffer(int size, int mss): m_BufLock(), @@ -1628,7 +1628,7 @@ int CRcvBuffer::readMsg(char* data, int len, ref_t r_msgctl) int64_t nowdiff = prev_now ? (nowtime - prev_now) : 0; uint64_t srctimediff = prev_srctime ? (srctime - prev_srctime) : 0; - HLOGC(dlog.Debug, log << CONID() << "readMsg: DELIVERED seq=" << seq << " T=" << logging::FormatTime(srctime) << " in " << (timediff/1000.0) << "ms - " + HLOGC(dlog.Debug, log << CONID() << "readMsg: DELIVERED seq=" << seq << " T=" << FormatTime(srctime) << " in " << (timediff/1000.0) << "ms - " "TIME-PREVIOUS: PKT: " << (srctimediff/1000.0) << " LOCAL: " << (nowdiff/1000.0)); prev_now = nowtime; diff --git a/srtcore/channel.cpp b/srtcore/channel.cpp index c2ac730be..fe1b6cfb8 100644 --- a/srtcore/channel.cpp +++ b/srtcore/channel.cpp @@ -91,7 +91,7 @@ modified by #endif using namespace std; -using namespace logging; +using namespace srt_logging; CChannel::CChannel(): m_iIPversion(AF_INET), diff --git a/srtcore/common.cpp b/srtcore/common.cpp index 9991aefd4..21d8758f0 100644 --- a/srtcore/common.cpp +++ b/srtcore/common.cpp @@ -839,7 +839,10 @@ std::string TransmissionEventStr(ETransmissionEvent ev) return vals[ev]; } -std::string logging::FormatTime(uint64_t time) +namespace srt_logging +{ + +std::string FormatTime(uint64_t time) { using namespace std; @@ -862,7 +865,7 @@ std::string logging::FormatTime(uint64_t time) // Some logging imps #if ENABLE_LOGGING -logging::LogDispatcher::Proxy::Proxy(LogDispatcher& guy) : that(guy), that_enabled(that.CheckEnabled()) +LogDispatcher::Proxy::Proxy(LogDispatcher& guy) : that(guy), that_enabled(that.CheckEnabled()) { if (that_enabled) { @@ -874,12 +877,12 @@ logging::LogDispatcher::Proxy::Proxy(LogDispatcher& guy) : that(guy), that_enabl } } -logging::LogDispatcher::Proxy logging::LogDispatcher::operator()() +LogDispatcher::Proxy LogDispatcher::operator()() { return Proxy(*this); } -void logging::LogDispatcher::CreateLogLinePrefix(std::ostringstream& serr) +void LogDispatcher::CreateLogLinePrefix(std::ostringstream& serr) { using namespace std; @@ -925,7 +928,7 @@ void logging::LogDispatcher::CreateLogLinePrefix(std::ostringstream& serr) } } -std::string logging::LogDispatcher::Proxy::ExtractName(std::string pretty_function) +std::string LogDispatcher::Proxy::ExtractName(std::string pretty_function) { if ( pretty_function == "" ) return ""; @@ -987,4 +990,7 @@ std::string logging::LogDispatcher::Proxy::ExtractName(std::string pretty_functi return pretty_function.substr(pos+2); } + +} // (end namespace srt_logging) + #endif diff --git a/srtcore/core.cpp b/srtcore/core.cpp index dd34cfcfd..5c8a90df7 100755 --- a/srtcore/core.cpp +++ b/srtcore/core.cpp @@ -80,12 +80,12 @@ modified by using namespace std; -namespace logging +namespace srt_logging { struct AllFaOn { - logging::LogConfig::fa_bitset_t allfa; + LogConfig::fa_bitset_t allfa; AllFaOn() { @@ -104,9 +104,9 @@ struct AllFaOn // We need it outside the namespace to preserve the global name. // It's a part of "hidden API" (used by applications) -SRT_API logging::LogConfig srt_logger_config (logging::logger_fa_all.allfa); +SRT_API srt_logging::LogConfig srt_logger_config (srt_logging::logger_fa_all.allfa); -namespace logging +namespace srt_logging { Logger glog(SRT_LOGFA_GENERAL, srt_logger_config, "SRT.g"); @@ -119,7 +119,7 @@ Logger rxlog(SRT_LOGFA_REXMIT, srt_logger_config, "SRT.r"); } -using namespace logging; +using namespace srt_logging; CUDTUnited CUDT::s_UDTUnited; diff --git a/srtcore/core.h b/srtcore/core.h index 455486683..04d06815c 100644 --- a/srtcore/core.h +++ b/srtcore/core.h @@ -73,7 +73,7 @@ modified by #include -namespace logging +namespace srt_logging { extern Logger diff --git a/srtcore/crypto.cpp b/srtcore/crypto.cpp index 5066358a2..3cba86074 100644 --- a/srtcore/crypto.cpp +++ b/srtcore/crypto.cpp @@ -25,7 +25,7 @@ written by #include "logging.h" #include "core.h" -using namespace logging; +using namespace srt_logging; #define SRT_MAX_KMRETRY 10 diff --git a/srtcore/crypto.h b/srtcore/crypto.h index 9dd24a4d5..ea6a008db 100644 --- a/srtcore/crypto.h +++ b/srtcore/crypto.h @@ -32,7 +32,7 @@ written by std::string KmStateStr(SRT_KM_STATE state); -namespace logging +namespace srt_logging { extern Logger mglog; } @@ -155,7 +155,7 @@ class CCryptoControl /// during transmission (otherwise it's during the handshake) void getKmMsg_markSent(size_t ki, bool runtime) { - using logging::mglog; + using srt_logging::mglog; m_SndKmLastTime = CTimer::getTime(); if (runtime) diff --git a/srtcore/logging.h b/srtcore/logging.h index bffa5b984..f1d01a8ed 100644 --- a/srtcore/logging.h +++ b/srtcore/logging.h @@ -54,7 +54,7 @@ written by // LOGC uses an iostream-like syntax, using the special 'log' symbol. // This symbol isn't visible outside the log macro parameters. // Usage: LOGC(mglog.Debug, log << param1 << param2 << param3); -#define LOGC(logdes, args) if (logdes.CheckEnabled()) { logging::LogDispatcher::Proxy log(logdes); log.setloc(__FILE__, __LINE__, __FUNCTION__); args; } +#define LOGC(logdes, args) if (logdes.CheckEnabled()) { srt_logging::LogDispatcher::Proxy log(logdes); log.setloc(__FILE__, __LINE__, __FUNCTION__); args; } // LOGF uses printf-like style formatting. // Usage: LOGF(mglog.Debug, "%s: %d", param1.c_str(), int(param2)); @@ -90,7 +90,7 @@ written by #endif -namespace logging +namespace srt_logging { struct LogConfig diff --git a/srtcore/logging_api.h b/srtcore/logging_api.h index 9d4f8b2d6..71c94b19c 100644 --- a/srtcore/logging_api.h +++ b/srtcore/logging_api.h @@ -50,7 +50,7 @@ written by typedef void SRT_LOG_HANDLER_FN(void* opaque, int level, const char* file, int line, const char* area, const char* message); #ifdef __cplusplus -namespace logging +namespace srt_logging { diff --git a/srtcore/packet.cpp b/srtcore/packet.cpp index 93f482a3a..6720a1453 100644 --- a/srtcore/packet.cpp +++ b/srtcore/packet.cpp @@ -164,11 +164,11 @@ modified by #include "packet.h" #include "logging.h" -namespace logging +namespace srt_logging { extern Logger mglog; } -using namespace logging; +using namespace srt_logging; // Set up the aliases in the constructure CPacket::CPacket(): diff --git a/srtcore/queue.cpp b/srtcore/queue.cpp index 994efca9a..0baa8e909 100644 --- a/srtcore/queue.cpp +++ b/srtcore/queue.cpp @@ -64,7 +64,7 @@ modified by #include "queue.h" using namespace std; -using namespace logging; +using namespace srt_logging; CUnitQueue::CUnitQueue(): m_pQEntry(NULL), diff --git a/srtcore/smoother.cpp b/srtcore/smoother.cpp index 4111dfb92..8ccf291c7 100644 --- a/srtcore/smoother.cpp +++ b/srtcore/smoother.cpp @@ -34,7 +34,7 @@ #include "logging.h" using namespace std; -using namespace logging; +using namespace srt_logging; SmootherBase::SmootherBase(CUDT* parent) { diff --git a/srtcore/srt_c_api.cpp b/srtcore/srt_c_api.cpp index db613d31d..3a710dc22 100644 --- a/srtcore/srt_c_api.cpp +++ b/srtcore/srt_c_api.cpp @@ -284,17 +284,17 @@ int srt_epoll_release(int eid) { return CUDT::epoll_release(eid); } void srt_setloglevel(int ll) { - UDT::setloglevel(logging::LogLevel::type(ll)); + UDT::setloglevel(srt_logging::LogLevel::type(ll)); } void srt_addlogfa(int fa) { - UDT::addlogfa(logging::LogFA(fa)); + UDT::addlogfa(srt_logging::LogFA(fa)); } void srt_dellogfa(int fa) { - UDT::dellogfa(logging::LogFA(fa)); + UDT::dellogfa(srt_logging::LogFA(fa)); } void srt_resetlogfa(const int* fara, size_t fara_size) diff --git a/srtcore/udt.h b/srtcore/udt.h index 3db779dbe..36a47fc17 100644 --- a/srtcore/udt.h +++ b/srtcore/udt.h @@ -387,10 +387,10 @@ UDT_API int bstats(UDTSOCKET u, TRACEBSTATS* perf, bool clear = true); UDT_API SRT_SOCKSTATUS getsockstate(UDTSOCKET u); // This is a C++ SRT API extension. This is not a part of legacy UDT API. -UDT_API void setloglevel(logging::LogLevel::type ll); -UDT_API void addlogfa(logging::LogFA fa); -UDT_API void dellogfa(logging::LogFA fa); -UDT_API void resetlogfa(std::set fas); +UDT_API void setloglevel(srt_logging::LogLevel::type ll); +UDT_API void addlogfa(srt_logging::LogFA fa); +UDT_API void dellogfa(srt_logging::LogFA fa); +UDT_API void resetlogfa(std::set fas); UDT_API void resetlogfa(const int* fara, size_t fara_size); UDT_API void setlogstream(std::ostream& stream); UDT_API void setloghandler(void* opaque, SRT_LOG_HANDLER_FN* handler); @@ -406,8 +406,8 @@ UDT_API std::string getstreamid(UDTSOCKET u); // are free to create their own logger configuration objects for their // own logger FA objects, or create their own. The object of this type // is required to initialize the logger FA object. -namespace logging { struct LogConfig; } -UDT_API extern logging::LogConfig srt_logger_config; +namespace srt_logging { struct LogConfig; } +UDT_API extern srt_logging::LogConfig srt_logger_config; #endif /* __cplusplus */ diff --git a/testing/srt-test-file.cpp b/testing/srt-test-file.cpp index 9d282cf7a..34354792f 100644 --- a/testing/srt-test-file.cpp +++ b/testing/srt-test-file.cpp @@ -43,7 +43,7 @@ written by bool Upload(UriParser& srt, UriParser& file); bool Download(UriParser& srt, UriParser& file); -const logging::LogFA SRT_LOGFA_APP = 10; +const srt_logging::LogFA SRT_LOGFA_APP = 10; static size_t g_buffer_size = 1456; static bool g_skip_flushing = false; @@ -83,7 +83,7 @@ int main( int argc, char** argv ) } string loglevel = Option(params, "error", o_loglevel); - logging::LogLevel::type lev = SrtParseLogLevel(loglevel); + srt_logging::LogLevel::type lev = SrtParseLogLevel(loglevel); UDT::setloglevel(lev); UDT::addlogfa(SRT_LOGFA_APP); diff --git a/testing/srt-test-live.cpp b/testing/srt-test-live.cpp index ab11b96f4..4a357bffc 100644 --- a/testing/srt-test-live.cpp +++ b/testing/srt-test-live.cpp @@ -196,6 +196,11 @@ struct BandwidthGuard extern "C" void TestLogHandler(void* opaque, int level, const char* file, int line, const char* area, const char* message); +namespace srt_logging +{ + extern Logger glog; +} + int main( int argc, char** argv ) { // This is mainly required on Windows to initialize the network system, @@ -315,8 +320,8 @@ int main( int argc, char** argv ) std::ofstream logfile_stream; // leave unused if not set srt_setloglevel(SrtParseLogLevel(loglevel)); - set fas = SrtParseLogFA(logfa); - for (set::iterator i = fas.begin(); i != fas.end(); ++i) + set fas = SrtParseLogFA(logfa); + for (set::iterator i = fas.begin(); i != fas.end(); ++i) srt_addlogfa(*i); char NAME[] = "SRTLIB"; @@ -444,7 +449,6 @@ int main( int argc, char** argv ) alarm(remain - final_delay); } - extern logging::Logger glog; try { for (;;) diff --git a/testing/srt-test-relay.cpp b/testing/srt-test-relay.cpp index 6d46d00fb..021c587a8 100644 --- a/testing/srt-test-relay.cpp +++ b/testing/srt-test-relay.cpp @@ -41,7 +41,7 @@ written by bool Upload(UriParser& srt, UriParser& file); bool Download(UriParser& srt, UriParser& file); -const logging::LogFA SRT_LOGFA_APP = 10; +const srt_logging::LogFA SRT_LOGFA_APP = 10; using namespace std; @@ -327,7 +327,7 @@ int main( int argc, char** argv ) } string loglevel = Option(params, "error", o_loglevel); - logging::LogLevel::type lev = SrtParseLogLevel(loglevel); + srt_logging::LogLevel::type lev = SrtParseLogLevel(loglevel); UDT::setloglevel(lev); UDT::addlogfa(SRT_LOGFA_APP); From f805b4292d2d7ff3f9904bbc3e002fc7e01a3891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Ma=C5=82ecki?= Date: Fri, 15 Feb 2019 19:58:11 +0100 Subject: [PATCH 4/4] Next portion of review changes --- srtcore/logging.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srtcore/logging.h b/srtcore/logging.h index f1d01a8ed..4c0c2bdf6 100644 --- a/srtcore/logging.h +++ b/srtcore/logging.h @@ -150,7 +150,7 @@ struct SRT_API LogDispatcher { // XXX stpcpy desired, but not enough portable // Composing the exact prefix is not critical, so simply - // cut the prefix, if the lenght is exceeded + // cut the prefix, if the length is exceeded // See Logger::Logger; we know this has normally 2 characters, // except !!FATAL!!, which has 9. Still less than 32. @@ -158,7 +158,7 @@ struct SRT_API LogDispatcher // If the size of the FA name together with severity exceeds the size, // just skip the former. - if (logger_pfx && strlen(prefix) + strlen(logger_pfx) < MAX_PREFIX_SIZE) + if (logger_pfx && strlen(prefix) + strlen(logger_pfx) + 1 < MAX_PREFIX_SIZE) { strcat(prefix, ":"); strcat(prefix, logger_pfx);