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] Implementation of logging/formatting system using {fmt} #2963

Draft
wants to merge 30 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 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
8f21764
Logging system implemented using {fmt}.
Jun 24, 2024
7d2c7f0
Updated fixed fmt
Jun 24, 2024
2ed8df5
Test workflow: enable submodules
Jun 24, 2024
487c857
Fixed warning of unused fmt_yesno
Jun 24, 2024
70a0217
Fixed problem in fmt, updated
Jun 25, 2024
6c60a8f
Fixed workflows to update submodules
Jun 25, 2024
2176b4b
Updated fmt with a fix
Jun 25, 2024
9143800
Removed Sprint and remaining sfmt facilities
Jun 26, 2024
115ae1b
Updated and fixed
Sep 3, 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
1 change: 1 addition & 0 deletions .github/workflows/abi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- uses: actions/checkout@v3
with:
path: pull_request
submodules: true
- name: configure
run: |
cd pull_request
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/android.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
ndk-version: r23
add-to-path: false
- uses: actions/checkout@v3
with:
submodules: true
- name: build
run: |
cd ./scripts/build-android/
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true

- name: Configure
run: cmake -DENABLE_HEAVY_LOGGING=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-fpermissive -DENABLE_BONDING=1 .
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/cxx11-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
- name: GoogleTest
run: brew install googletest
- uses: actions/checkout@v3
with:
submodules: true
- name: configure
run: |
mkdir _build && cd _build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/cxx11-ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
BUILD_WRAPPER_OUT_DIR: sonar-output # Directory where build-wrapper output will be placed
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Install sonar-scanner and build-wrapper
uses: sonarsource/sonarcloud-github-c-cpp@v2
- name: configure
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/cxx11-win.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: configure
run: |
md _build && cd _build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/iOS.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: configure
run: |
mkdir _build && cd _build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/s390x-focal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
"
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: configure
uses: docker://multiarch/ubuntu-core:s390x-focal
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "submodules/fmt"]
path = submodules/fmt
url = [email protected]:ethouris/fmt.git
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ set_if(NEED_DESTINATION ${CMAKE_VERSION} VERSION_LESS "3.14.0")

include(GNUInstallDirs)

add_subdirectory(submodules/fmt)

# The CMAKE_BUILD_TYPE seems not to be always set, weird.
if (NOT DEFINED ENABLE_DEBUG)

Expand Down Expand Up @@ -1025,6 +1027,7 @@ list(INSERT HEADERS_srt 0 "${CMAKE_CURRENT_BINARY_DIR}/version.h")
include_directories("${CMAKE_CURRENT_BINARY_DIR}")

add_library(srt_virtual OBJECT ${SOURCES_srt} ${SOURCES_srt_extra} ${HEADERS_srt} ${SOURCES_haicrypt} ${SOURCES_common})
add_dependencies(srt_virtual fmt)

if (ENABLE_SHARED)
# Set this to sources as well, as it won't be automatically handled
Expand Down Expand Up @@ -1057,6 +1060,7 @@ if (srt_libspec_shared)
set (CMAKE_POSITION_INDEPENDENT_CODE ON)
set_property(TARGET ${TARGET_srt}_shared PROPERTY OUTPUT_NAME ${TARGET_srt})
set_target_properties (${TARGET_srt}_shared PROPERTIES VERSION ${SRT_VERSION} SOVERSION ${SRT_VERSION_MAJOR}.${SRT_VERSION_MINOR})
target_link_libraries(${TARGET_srt}_shared PRIVATE fmt)
list (APPEND INSTALL_TARGETS ${TARGET_srt}_shared)
if (ENABLE_ENCRYPTION)
target_link_libraries(${TARGET_srt}_shared PRIVATE ${SSL_LIBRARIES})
Expand All @@ -1082,6 +1086,7 @@ endif()

if (srt_libspec_static)
add_library(${TARGET_srt}_static STATIC ${OBJECT_LIB_SUPPORT} ${VIRTUAL_srt})
target_link_libraries(${TARGET_srt}_static PRIVATE fmt)

# For Windows, leave the name to be "srt_static.lib".
# Windows generates two different library files:
Expand Down Expand Up @@ -1115,6 +1120,7 @@ if (srt_libspec_static)
endif()

target_include_directories(srt_virtual PRIVATE ${SSL_INCLUDE_DIRS})
target_include_directories(srt_virtual PRIVATE submodules/fmt/include)

if (MICROSOFT)
if (OPENSSL_USE_STATIC_LIBS)
Expand Down Expand Up @@ -1281,6 +1287,8 @@ macro(srt_add_program_dont_install name)
add_executable(${name} ${ARGN})
target_include_directories(${name} PRIVATE apps)
target_include_directories(${name} PRIVATE common)
target_include_directories(${name} PRIVATE submodules/fmt/include)
#message(STATUS "PROGRAM: ${name} with apps, common, fmt; SOURCES: ${ARGN}")
endmacro()

macro(srt_add_program name)
Expand Down Expand Up @@ -1364,6 +1372,8 @@ if (ENABLE_APPS)
# library should be changed into a static one and made useful
# for users.
add_library(srtsupport_virtual OBJECT ${SOURCES_support})
add_dependencies(srtsupport_virtual fmt)
target_include_directories(srtsupport_virtual PRIVATE submodules/fmt/include)
srt_set_stdcxx(srtsupport_virtual "${USE_CXX_STD_APP}")
set (VIRTUAL_srtsupport $<TARGET_OBJECTS:srtsupport_virtual>)

Expand Down Expand Up @@ -1404,6 +1414,7 @@ if (ENABLE_APPS)

srt_add_testprogram(utility-test)
srt_set_stdcxx(utility-test "${USE_CXX_STD_APP}")
target_link_libraries(utility-test PRIVATE fmt)
if (NOT WIN32)
# This program is symlinked under git-cygwin.
# Avoid misleading syntax error.
Expand Down
12 changes: 7 additions & 5 deletions apps/logsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ 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;
using namespace fmt;

memory_buffer son, soff;

for (auto& s: speclist)
{
Expand All @@ -190,13 +192,13 @@ void ParseLogFASpec(const vector<string>& speclist, string& w_on, string& w_off)
name = s;

if (on)
son << "," << name;
ffwrite(son, ",", name);
else
soff << "," << name;
ffwrite(soff, ",", name);
}

const string& sons = son.str();
const string& soffs = soff.str();
string sons = ffcat(son);
string soffs = ffcat(soff);

w_on = sons.empty() ? string() : sons.substr(1);
w_off = soffs.empty() ? string() : soffs.substr(1);
Expand Down
2 changes: 1 addition & 1 deletion apps/srt-file-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ bool DoUpload(UriParser& ut, string path, string filename,
{
int st = tar->Write(buf.data() + shift, n, 0, out_stats);
Verb() << "Upload: " << n << " --> " << st
<< (!shift ? string() : "+" + Sprint(shift));
<< (!shift ? string() : fmt::ffcat("+", shift));
if (st == SRT_ERROR)
{
cerr << "Upload: SRT error: " << srt_getlasterror_str()
Expand Down
2 changes: 1 addition & 1 deletion apps/transmitmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void SrtCommon::InitParameters(string host, map<string,string> par)
if (transmit_chunk_size > SRT_LIVE_MAX_PLSIZE)
throw std::runtime_error("Chunk size in live mode exceeds 1456 bytes; this is not supported");

par["payloadsize"] = Sprint(transmit_chunk_size);
par["payloadsize"] = fmt::ffcat(transmit_chunk_size);
}

// Assign the others here.
Expand Down
20 changes: 11 additions & 9 deletions apps/uriparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <algorithm>
#include <map>
#include <string>
#include "fmt/format.h"

#include "uriparser.hpp"

Expand Down Expand Up @@ -57,48 +58,49 @@ UriParser::~UriParser(void)

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

std::ostringstream out;
memory_buffer out;

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

if (m_path != "")
{
if (m_path[0] != '/')
out << "/";
out << m_path;
ffwrite(out, "/");
ffwrite(out, m_path);
}

if (!m_mapQuery.empty())
{
out << "?";
ffwrite(out, "?");

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

m_origUri = out.str();
m_origUri = ffcat(out);
return m_origUri;
}

Expand Down
Loading
Loading