Skip to content

Commit

Permalink
[core] High level logger FA definitions (#1440)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethouris committed Aug 20, 2020
1 parent b631276 commit 98e86d1
Show file tree
Hide file tree
Showing 19 changed files with 575 additions and 90 deletions.
57 changes: 42 additions & 15 deletions apps/logsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <cctype>
#include "logsupport.hpp"
#include "../srtcore/srt.h"
#include "../srtcore/utilities.h"

using namespace std;

Expand Down Expand Up @@ -74,6 +75,36 @@ srt_logging::LogLevel::type SrtParseLogLevel(string level)
return LogLevel::type(i->second);
}

struct ToLowerFormat
{
char operator()(char in)
{
if (islower(in))
return in;
if (isupper(in))
return tolower(in);
if (in == '_')
return '-';

throw std::invalid_argument("Wrong FA name - please check the definition in scripts/generate-logging-defs.tcl file");
}
};

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()
{
return srt_transmit_logfa_names.namemap;
}

set<srt_logging::LogFA> SrtParseLogFA(string fa, set<string>* punknown)
{
using namespace srt_logging;
Expand All @@ -84,18 +115,17 @@ set<srt_logging::LogFA> SrtParseLogFA(string fa, set<string>* punknown)
if ( fa == "" )
return fas;

static string names [] = { "general", "bstats", "control", "data", "tsbpd", "rexmit", "haicrypt", "cc" };
size_t names_s = sizeof (names)/sizeof (names[0]);
auto& names = srt_transmit_logfa_names.namemap;

if ( fa == "all" )
{
// Skip "general", it's always on
fas.insert(SRT_LOGFA_BSTATS);
fas.insert(SRT_LOGFA_CONTROL);
fas.insert(SRT_LOGFA_DATA);
fas.insert(SRT_LOGFA_TSBPD);
fas.insert(SRT_LOGFA_REXMIT);
fas.insert(SRT_LOGFA_CONGEST);
for (auto entry: names)
{
// Skip "general", it's always on
if (entry.first == "general")
continue;
fas.insert(entry.second);
}
return fas;
}

Expand Down Expand Up @@ -124,8 +154,8 @@ set<srt_logging::LogFA> SrtParseLogFA(string fa, set<string>* punknown)
for (size_t i = 0; i < xfas.size(); ++i)
{
fa = xfas[i];
string* names_p = find(names, names + names_s, fa);
if ( names_p == names + names_s )
int* pfa = map_getp(names, fa);
if (!pfa)
{
if (punknown)
punknown->insert(fa); // If requested, add it back silently
Expand All @@ -134,10 +164,7 @@ set<srt_logging::LogFA> SrtParseLogFA(string fa, set<string>* punknown)
continue;
}

size_t nfa = names_p - names;

if ( nfa != 0 )
fas.insert(nfa);
fas.insert(*pfa);
}

return fas;
Expand Down
9 changes: 9 additions & 0 deletions apps/logsupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@
#ifndef INC_SRT_LOGSUPPORT_HPP
#define INC_SRT_LOGSUPPORT_HPP

#include <string>
#include <map>
#include "../srtcore/srt.h"
#include "../srtcore/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);
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
23 changes: 23 additions & 0 deletions apps/logsupport_appdefs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
WARNING: Generated from ../scripts/generate-logging-defs.tcl
DO NOT MODIFY.
Copyright applies as per the generator script.
*/


#include "logsupport.hpp"

LogFANames::LogFANames()
{
Install("GENERAL", SRT_LOGFA_GENERAL);

Install("CONTROL", SRT_LOGFA_CONTROL);
Install("DATA", SRT_LOGFA_DATA);
Install("TSBPD", SRT_LOGFA_TSBPD);
Install("REXMIT", SRT_LOGFA_REXMIT);

Install("CONGEST", SRT_LOGFA_CONGEST);
Install("HAICRYPT", SRT_LOGFA_HAICRYPT);
}
44 changes: 41 additions & 3 deletions apps/srt-live-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ int parse_args(LiveTransmitConfig &cfg, int argc, char** argv)
{ o_logfile, OptionScheme::ARG_ONE },
{ o_quiet, OptionScheme::ARG_NONE },
{ o_verbose, OptionScheme::ARG_NONE },
{ o_help, OptionScheme::ARG_NONE },
{ o_help, OptionScheme::ARG_VAR },
{ o_version, OptionScheme::ARG_NONE }
};

Expand All @@ -229,6 +229,44 @@ int parse_args(LiveTransmitConfig &cfg, int argc, char** argv)

if (print_help)
{
string helpspec = Option<OutString>(params, o_help);

if (helpspec == "logging")
{
cerr << "Logging options:\n";
cerr << " -ll <LEVEL> - specify minimum log level\n";
cerr << " -lfa <area...> - specify functional areas\n";
cerr << "Where:\n\n";
cerr << " <LEVEL>: fatal error note warning debug\n\n";
cerr << "This turns on logs that are at the given log name and all on the left.\n";
cerr << "(Names from syslog, like alert, crit, emerg, err, info, panic, are also\n";
cerr << "recognized, but they are aligned to those that lie close in hierarchy.)\n\n";
cerr << " <area...> is a space-sep list of areas to turn on or ~areas to turn off.\n\n";
cerr << "The list may include 'all' to turn all on or off, beside those selected.\n";
cerr << "Example: `-lfa ~all cc` - turns off all FA, except cc\n";
cerr << "Areas: general bstats control data tsbpd rexmit haicrypt cc\n";
cerr << "Default: all are on except haicrypt. NOTE: 'general' can't be off.\n\n";
cerr << "List of functional areas:\n";

map<int, string> revmap;
for (auto entry: SrtLogFAList())
revmap[entry.second] = entry.first;

int en10 = 0;
for (auto entry: revmap)
{
cerr << " " << entry.second;
if (entry.first/10 != en10)
{
cerr << endl;
en10 = entry.first/10;
}
}
cerr << endl;

return 1;
}

cout << "SRT sample application to transmit live streaming.\n";
cerr << "Built with SRT Library version: " << SRT_VERSION << endl;
const uint32_t srtver = srt_getversion();
Expand All @@ -252,13 +290,13 @@ int parse_args(LiveTransmitConfig &cfg, int argc, char** argv)
PrintOptionHelp(o_statspf, "<format=default>", "stats printing format {json, csv, default}");
PrintOptionHelp(o_statsfull, "", "full counters in stats-report (prints total statistics)");
PrintOptionHelp(o_loglevel, "<level=error>", "log level {fatal,error,info,note,warning}");
PrintOptionHelp(o_logfa, "<fas=general,...>", "log functional area {all,general,bstats,control,data,tsbpd,rexmit}");
PrintOptionHelp(o_logfa, "<fas>", "log functional area (see '-h logging' for more info)");
//PrintOptionHelp(o_log_internal, "", "use internal logger");
PrintOptionHelp(o_logfile, "<filename="">", "write logs to file");
PrintOptionHelp(o_quiet, "", "quiet mode (default off)");
PrintOptionHelp(o_verbose, "", "verbose mode (default off)");
cerr << "\n";
cerr << "\t-h,-help - show this help\n";
cerr << "\t-h,-help - show this help (use '-h logging' for logging system)\n";
cerr << "\t-version - print SRT library version\n";
cerr << "\n";
cerr << "\t<input-uri> - URI specifying a medium to read from\n";
Expand Down
1 change: 1 addition & 0 deletions apps/support.maf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
SOURCES
apputil.cpp
logsupport.cpp
logsupport_appdefs.cpp
socketoptions.cpp
transmitmedia.cpp
uriparser.cpp
Expand Down
Loading

0 comments on commit 98e86d1

Please sign in to comment.