Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 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
59435c2
Merge branch 'master' into dev-add-custom-fmt-for-logging
Dec 6, 2024
8e74ad5
Initial rework of the logging system
Dec 9, 2024
571b6f3
Adjusted to the new configuration API
Dec 9, 2024
c91d9de
[DEV] Extracted logging system to a separate subproject
Feb 18, 2025
d025710
Merge branch 'master' into dev-extract-logging-system
Feb 18, 2025
f3eb220
Adjustment changes for C++98. Further changes in remaining files used…
Feb 20, 2025
892f0c3
Added missing generated files. Some naming fixes and cosmetic changes
Feb 24, 2025
16f7f6c
Attempting to fix some build errors
Feb 24, 2025
fe73ebb
Removed 'far' as identified (keyword in MSVC)
Feb 24, 2025
00d4ab5
Fixed external thread id provider for threadname
Feb 24, 2025
f6746bf
Fixed problems reported on MSVC
ethouris Feb 24, 2025
cea8217
Forcedully set default C++ std value for libs
Feb 24, 2025
8e58e94
Fixed the use of always defined ENABLE_LOGGING.
Feb 25, 2025
cbcc80e
Changed sync configuration to extra include file
Feb 25, 2025
e05369c
Fixed the use of hvu_sync.h in hvu_threadname.h
Feb 25, 2025
d1e968c
Applied some parallel fixes from other PR
Feb 25, 2025
facc4ad
Merge branch 'master' into dev-add-custom-fmt-for-logging
Feb 25, 2025
99ca9b4
Updated and fixed
Feb 26, 2025
05d82be
Updated from 2964
Feb 26, 2025
b956d8d
Added lacking file. Fixed wrong dependency on stdint
Feb 28, 2025
4f4111e
Merge branch 'dev-add-custom-fmt-for-logging' into dev-extract-loggin…
Feb 28, 2025
3d3f7d5
Updated and fixed.
Feb 28, 2025
c028797
Merge branch 'master' into dev-extract-logging-system
Mar 10, 2025
d793b63
Some cosmetic fixes
Mar 10, 2025
721cc09
Some cosmetic changes
Mar 10, 2025
46bbd53
Added time format facility. Added documentation. Minor fixes.
Mar 20, 2025
e5be462
Updated and fixed
Mar 21, 2025
3f48500
Added changes for put_time
Mar 21, 2025
cfa02b5
Updated to latest dev
Aug 8, 2025
3e4ab20
Renamed ofmtstream to ofmtbufstream. Added ofmtrefstream. Some cosmetics
Aug 8, 2025
ab3edd4
Applied last changes from 2964
Aug 11, 2025
4f3f90c
Merged dev-add-custom-fmt-for-logging 2964 with fixes
Aug 11, 2025
f36830b
Updated to dev and fixed
Aug 14, 2025
df805b2
Added a single-argument overload for fmt for simple use of iomanips
Aug 14, 2025
ea02931
Merged changes for ofmt from the base
Aug 14, 2025
1d9036a
Updated and fixed
Aug 14, 2025
51c2e30
Changed the tm/put_time application for ofmt
Aug 14, 2025
1481baa
Changed the tm/put_time application for ofmt
Aug 14, 2025
bdbc76f
Cosmetics
Aug 21, 2025
8e33a80
Updated to latest dev and fixed
Aug 22, 2025
d09f6e4
Updated and fixed
Aug 25, 2025
92c7a8b
Merge branch 'dev' into dev-extract-logging-system
Aug 25, 2025
1d93cd0
Merge branch 'dev' into dev-extract-logging-system
Aug 25, 2025
b5ee579
Documentation fixes
Aug 25, 2025
70b952d
Updated and fixed
Aug 26, 2025
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
31 changes: 12 additions & 19 deletions apps/logsupport.cpp → ATTIC/logsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@
#include "logsupport.hpp"
#include "../srtcore/srt.h"
#include "../srtcore/utilities.h"
#include "../srtcore/ofmt.h"
#include "ofmt.h"
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: this and some other files were moved to ATTIC so that they can stay as reference just in case, but they can be just as well removed. Changes visible here are only intermediate attempts and abandoned.


using namespace std;
using namespace srt;

namespace hvu
{

// This is based on codes taken from <sys/syslog.h>
// This is POSIX standard, so it's not going to change.
// Haivision standard only adds one more severity below
// DEBUG named DEBUG_TRACE to satisfy all possible needs.

map<string, int> srt_level_names
map<string, int> level_names
{
{ "alert", LOG_ALERT },
{ "crit", LOG_CRIT },
Expand All @@ -48,17 +51,17 @@ map<string, int> srt_level_names



srt_logging::LogLevel::type SrtParseLogLevel(string level)
hvu::logging::LogLevel::type ParseLogLevel(string level)
{
using namespace srt_logging;
using namespace hvu::logging;

if ( level.empty() )
return LogLevel::fatal;

if ( isdigit(level[0]) )
{
long lev = strtol(level.c_str(), 0, 10);
if ( lev >= SRT_LOG_LEVEL_MIN && lev <= SRT_LOG_LEVEL_MAX )
if ( lev >= HVU_LOG_LEVEL_MIN && lev <= HVU_LOG_LEVEL_MAX )
return LogLevel::type(lev);

cerr << "ERROR: Invalid loglevel number: " << level << " - fallback to FATAL\n";
Expand Down Expand Up @@ -93,24 +96,13 @@ struct ToLowerFormat
}
};

void LogFANames::Install(string upname, int value)
{
string id;
transform(upname.begin(), upname.end(), back_inserter(id), ToLowerFormat());
namemap[id] = value;
}

// See logsupport_appdefs.cpp for log FA definitions
LogFANames srt_transmit_logfa_names;

const map<string, int> SrtLogFAList()
set<hvu::logging::LogFA> ParseLogFA(string fa, set<string>* punknown)
{
return srt_transmit_logfa_names.namemap;
}

set<srt_logging::LogFA> SrtParseLogFA(string fa, set<string>* punknown)
{
using namespace srt_logging;
using namespace hvu::logging;

set<LogFA> fas;

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

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

for (auto& s: speclist)
{
Expand Down Expand Up @@ -204,4 +196,5 @@ void ParseLogFASpec(const vector<string>& speclist, string& w_on, string& w_off)
w_off = soffs.empty() ? string() : soffs.substr(1);
}

}

19 changes: 7 additions & 12 deletions apps/logsupport.hpp → ATTIC/logsupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,16 @@
#include <string>
#include <map>
#include <vector>
#include "../srtcore/srt.h"
#include "../srtcore/logging_api.h"
#include "logging_api.h"

srt_logging::LogLevel::type SrtParseLogLevel(std::string level);
std::set<srt_logging::LogFA> SrtParseLogFA(std::string fa, std::set<std::string>* punknown = nullptr);
namespace hvu
{

hvu::logging::LogLevel::type ParseLogLevel(std::string level);
std::set<hvu::logging::LogFA> ParseLogFA(std::string fa, std::set<std::string>* punknown = nullptr);
void ParseLogFASpec(const std::vector<std::string>& speclist, std::string& w_on, std::string& w_off);
const std::map<std::string, int> SrtLogFAList();

SRT_API extern std::map<std::string, int> srt_level_names;

struct LogFANames
{
std::map<std::string, int> namemap;
void Install(std::string upname, int value);
LogFANames();
};
}

#endif
File renamed without changes.
24 changes: 23 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ set (SRT_SRC_SRTCORE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/srtcore)
set (SRT_SRC_COMMON_DIR ${CMAKE_CURRENT_SOURCE_DIR}/common)
set (SRT_SRC_TOOLS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools)
set (SRT_SRC_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
set (SRT_SRC_LOG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/logging)

if(WIN32)
message(STATUS "DETECTED SYSTEM: WINDOWS; WIN32=1; PTW32_STATIC_LIB=1")
Expand Down Expand Up @@ -840,7 +841,7 @@ endif()

# This is obligatory include directory for all targets. This is only
# for private headers. Installable headers should be exclusively used DIRECTLY.
include_directories(${SRT_SRC_COMMON_DIR} ${SRT_SRC_SRTCORE_DIR} ${SRT_SRC_HAICRYPT_DIR})
include_directories(${SRT_SRC_COMMON_DIR} ${SRT_SRC_SRTCORE_DIR} ${SRT_SRC_HAICRYPT_DIR} ${SRT_SRC_LOG_DIR})

if (ENABLE_LOGGING)
list(APPEND SRT_EXTRA_CFLAGS "-DENABLE_LOGGING=1")
Expand Down Expand Up @@ -1239,6 +1240,27 @@ if (ENABLE_ENCRYPTION AND "${USE_ENCLIB}" STREQUAL "botan")
add_dependencies(srt_virtual botan)
endif()

# If empty, set to the default value because this value needs
# to be checked
if (USE_CXX_STD_LIB STREQUAL "")
set (USE_CXX_STD_LIB ${CMAKE_CXX_STANDARD_DEFAULT})
endif()

if ("${USE_CXX_STD_LIB}" EQUAL 98)

message(STATUS "USING STANDARD: ${USE_CXX_STD_LIB} - ADDING LOGGER sync lib")

# Use SRT sync definitions for logging - for everything, regardless which standard apps use.
# We use options that can be only handled by gcc and clang,
# but on Windows we don't support non-C++11 compiling anymore.
add_definitions(-DHVU_EXT_INCLUDE_SYNC="../srtcore/srt_sync_cxx98.h")
else()

message(STATUS "USING STANDARD: ${USE_CXX_STD_LIB} - KEEPING LOGGER sync lib as std C++")

endif()


if (srt_libspec_shared)
if (MICROSOFT)
target_link_libraries(${TARGET_srt}_shared PUBLIC Ws2_32.lib)
Expand Down
4 changes: 2 additions & 2 deletions apps/apputil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "common.h"
#include "apputil.hpp"
#include "netinet_any.h"
#include "srt_compat.h"
#include "hvu_compat.h"
#include "ofmt.h"

using namespace std;
Expand Down Expand Up @@ -148,7 +148,7 @@ string Join(const vector<string>& in, string sep)
if (in.empty())
return "";

srt::ofmtbufstream os;
hvu::ofmtbufstream os;

os << in[0];
for (auto i = in.begin()+1; i != in.end(); ++i)
Expand Down
12 changes: 6 additions & 6 deletions apps/srt-file-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ written by
#include <sys/stat.h>
#include <srt.h>
#include <common.h>
#include <logger_fas.h>

#include "apputil.hpp"
#include "uriparser.hpp"
#include "logsupport.hpp"
#include "socketoptions.hpp"
#include "transmitmedia.hpp"
#include "verbose.hpp"
Expand All @@ -58,8 +58,8 @@ struct FileTransmitConfig
unsigned long chunk_size;
bool skip_flushing;
bool quiet = false;
srt_logging::LogLevel::type loglevel = srt_logging::LogLevel::error;
set<srt_logging::LogFA> logfas;
hvu::logging::LogLevel::type loglevel = hvu::logging::LogLevel::error;
set<int> logfas;
string logfile;
int bw_report = 0;
int stats_report = 0;
Expand Down Expand Up @@ -207,8 +207,8 @@ int parse_args(FileTransmitConfig &cfg, int argc, char** argv)
}

cfg.full_stats = Option<OutBool>(params, false, o_statsfull);
cfg.loglevel = SrtParseLogLevel(Option<OutString>(params, "error", o_loglevel));
cfg.logfas = SrtParseLogFA(Option<OutString>(params, "", o_logfa));
cfg.loglevel = hvu::logging::parse_level(Option<OutString>(params, "error", o_loglevel));
cfg.logfas = hvu::logging::parse_fa(srt::logging::logger_config(), Option<OutString>(params, "", o_logfa));
cfg.logfile = Option<OutString>(params, "", o_logfile);
cfg.quiet = Option<OutBool>(params, false, o_quiet);

Expand Down Expand Up @@ -698,7 +698,7 @@ int main(int argc, char** argv)
// Set SRT log levels and functional areas
//
srt_setloglevel(cfg.loglevel);
for (set<srt_logging::LogFA>::iterator i = cfg.logfas.begin(); i != cfg.logfas.end(); ++i)
for (set<int>::iterator i = cfg.logfas.begin(); i != cfg.logfas.end(); ++i)
srt_addlogfa(*i);

//
Expand Down
70 changes: 30 additions & 40 deletions apps/srt-live-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@
#include <thread>
#include <list>

#include "srt_compat.h"
#include <hvu_compat.h>

#include "apputil.hpp" // CreateAddr
#include "uriparser.hpp" // UriParser
#include "socketoptions.hpp"
#include "logsupport.hpp"
#include "transmitmedia.hpp"
#include "verbose.hpp"

// NOTE: This is without "haisrt/" because it uses an internal path
// to the library. Application using the "installed" library should
// use <srt/srt.h>
#include <srt.h>
#include <logging.h>
#include <logger_fas.h> // because contains the declaration of logger_config

using namespace std;

Expand Down Expand Up @@ -130,8 +130,8 @@ struct LiveTransmitConfig
int timeout_mode = 0;
int chunk_size = -1;
bool quiet = false;
srt_logging::LogLevel::type loglevel = srt_logging::LogLevel::error;
set<srt_logging::LogFA> logfas;
hvu::logging::LogLevel::type loglevel = hvu::logging::LogLevel::error;
set<int> logfas;
bool log_internal;
string logfile;
int bw_report = 0;
Expand Down Expand Up @@ -247,18 +247,18 @@ int parse_args(LiveTransmitConfig &cfg, int argc, char** argv)
cerr << "List of functional areas:\n";

map<int, string> revmap;
for (auto entry: SrtLogFAList())
revmap[entry.second] = entry.first;
for (size_t i = 0; i < srt::logging::logger_config().size(); ++i)
revmap[i] = srt::logging::logger_config().name(i);

// Each group on a new line
int en10 = 0;
int en6 = 0;
for (auto entry: revmap)
{
cerr << " " << entry.second;
if (entry.first/10 != en10)
if (entry.first/6 != en6)
{
cerr << endl;
en10 = entry.first/10;
en6 = entry.first/6;
}
}
cerr << endl;
Expand Down Expand Up @@ -338,8 +338,8 @@ int parse_args(LiveTransmitConfig &cfg, int argc, char** argv)
}

cfg.full_stats = OptionPresent(params, o_statsfull);
cfg.loglevel = SrtParseLogLevel(Option<OutString>(params, "warn", o_loglevel));
cfg.logfas = SrtParseLogFA(Option<OutString>(params, "", o_logfa));
cfg.loglevel = hvu::logging::parse_level(Option<OutString>(params, "warn", o_loglevel));
cfg.logfas = hvu::logging::parse_fa(srt::logging::logger_config(), Option<OutString>(params, "", o_logfa));
cfg.log_internal = OptionPresent(params, o_log_internal);
cfg.logfile = Option<OutString>(params, o_logfile);
cfg.quiet = OptionPresent(params, o_quiet);
Expand Down Expand Up @@ -398,9 +398,7 @@ int main(int argc, char** argv)
srt_setloglevel(cfg.loglevel);
if (!cfg.logfas.empty())
{
srt_resetlogfa(nullptr, 0);
for (set<srt_logging::LogFA>::iterator i = cfg.logfas.begin(); i != cfg.logfas.end(); ++i)
srt_addlogfa(*i);
srt::resetlogfa(cfg.logfas);
}

//
Expand All @@ -411,10 +409,10 @@ int main(int argc, char** argv)
if (cfg.log_internal)
{
srt_setlogflags(0
| SRT_LOGF_DISABLE_TIME
| SRT_LOGF_DISABLE_SEVERITY
| SRT_LOGF_DISABLE_THREADNAME
| SRT_LOGF_DISABLE_EOL
| HVU_LOGF_DISABLE_TIME
| HVU_LOGF_DISABLE_SEVERITY
| HVU_LOGF_DISABLE_THREADNAME
| HVU_LOGF_DISABLE_EOL
);
srt_setloghandler(NAME, TestLogHandler);
}
Expand Down Expand Up @@ -881,29 +879,21 @@ int main(int argc, char** argv)

void TestLogHandler(void* opaque, int level, const char* file, int line, const char* area, const char* message)
{
char prefix[100] = "";
if ( opaque ) {
#ifdef _MSC_VER
strncpy_s(prefix, sizeof(prefix), (char*)opaque, _TRUNCATE);
#else
strncpy(prefix, (char*)opaque, sizeof(prefix) - 1);
prefix[sizeof(prefix) - 1] = '\0';
#endif
std::string prefix;
if (opaque)
{
const char* instr = (const char*)opaque;
size_t len = strlen(instr);
if (len > 10)
len = 10;
prefix = ":" + string(instr, len);
}

time_t now;
time(&now);
char buf[1024];
struct tm local = SysLocalTime(now);
size_t pos = strftime(buf, 1024, "[%c ", &local);

#ifdef _MSC_VER
// That's something weird that happens on Microsoft Visual Studio 2013
// Trying to keep portability, while every version of MSVS is a different plaform.
// On MSVS 2015 there's already a standard-compliant snprintf, whereas _snprintf
// is available on backward compatibility and it doesn't work exactly the same way.
#define snprintf _snprintf
#endif
snprintf(buf+pos, 1024-pos, "%s:%d(%s)]{%d} %s", file, line, area, level, message);
struct tm local = hvu::SysLocalTime(now);

cerr << buf << endl;
cerr << "[" << std::put_time(&local, "%c") << " " << file << ":" << line
<< "(" << area << ")]{" << level << "} " << prefix << message
<< endl;
}
Loading
Loading