1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

For #1592, support ff_log_level and default to warning

This commit is contained in:
winlin 2020-02-05 12:32:15 +08:00
parent 2fa151726b
commit c50c51889a
7 changed files with 46 additions and 11 deletions

View file

@ -19,11 +19,16 @@ pid ./objs/srs.pid;
# performance about 10%. # performance about 10%.
# default: 60000 # default: 60000
chunk_size 60000; chunk_size 60000;
# the logs dir. # the log dir for FFMPEG.
# if enabled ffmpeg, each transcoding stream will create a log file. # if enabled ffmpeg, each transcoding stream will create a log file.
# /dev/null to disable the log. # /dev/null to disable the log.
# default: ./objs # default: ./objs
ff_log_dir ./objs; ff_log_dir ./objs;
# the log level for FFMPEG.
# info warning error fatal panic quiet
# trace debug verbose
# default: warning
ff_log_level warning;
# the log tank, console or file. # the log tank, console or file.
# if console, print log to console. # if console, print log to console.
# if file, write log to file. requires srs_log_file if log to file. # if file, write log to file. requires srs_log_file if log to file.

View file

@ -3487,6 +3487,7 @@ srs_error_t SrsConfig::check_normal_config()
&& n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms" && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms"
&& n != "http_server" && n != "stream_caster" && n != "http_server" && n != "stream_caster"
&& n != "utc_time" && n != "work_dir" && n != "asprocess" && n != "utc_time" && n != "work_dir" && n != "asprocess"
&& n != "ff_log_level"
) { ) {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str()); return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str());
} }
@ -5782,6 +5783,18 @@ string SrsConfig::get_ff_log_dir()
return conf->arg0(); return conf->arg0();
} }
string SrsConfig::get_ff_log_level()
{
static string DEFAULT = "warning";
SrsConfDirective* conf = root->get("ff_log_level");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return conf->arg0();
}
SrsConfDirective* SrsConfig::get_dash(string vhost) SrsConfDirective* SrsConfig::get_dash(string vhost)
{ {
SrsConfDirective* conf = get_vhost(vhost); SrsConfDirective* conf = get_vhost(vhost);

View file

@ -783,6 +783,8 @@ public:
// The ffmpeg log dir. // The ffmpeg log dir.
// @remark, /dev/null to disable it. // @remark, /dev/null to disable it.
virtual std::string get_ff_log_dir(); virtual std::string get_ff_log_dir();
// The ffmpeg log level.
virtual std::string get_ff_log_level();
// The MPEG-DASH section. // The MPEG-DASH section.
private: private:
virtual SrsConfDirective* get_dash(std::string vhost); virtual SrsConfDirective* get_dash(std::string vhost);

View file

@ -82,9 +82,9 @@ SrsFFMPEG::~SrsFFMPEG()
srs_freep(process); srs_freep(process);
} }
void SrsFFMPEG::set_iparams(string iparams) void SrsFFMPEG::append_iparam(string iparam)
{ {
_iparams = iparams; iparams.push_back(iparam);
} }
void SrsFFMPEG::set_oformat(string format) void SrsFFMPEG::set_oformat(string format)
@ -230,8 +230,11 @@ srs_error_t SrsFFMPEG::start()
params.push_back(ffmpeg); params.push_back(ffmpeg);
// input params // input params
if (!_iparams.empty()) { for (int i = 0; i < iparams.size(); i++) {
params.push_back(_iparams); string iparam = iparams.at(i);
if (!iparam.empty()) {
params.push_back(iparam);
}
} }
// build the perfile // build the perfile

View file

@ -45,7 +45,7 @@ private:
std::string log_file; std::string log_file;
private: private:
std::string ffmpeg; std::string ffmpeg;
std::string _iparams; std::vector<std::string> iparams;
std::vector<std::string> perfile; std::vector<std::string> perfile;
std::string iformat; std::string iformat;
std::string input; std::string input;
@ -70,7 +70,7 @@ public:
SrsFFMPEG(std::string ffmpeg_bin); SrsFFMPEG(std::string ffmpeg_bin);
virtual ~SrsFFMPEG(); virtual ~SrsFFMPEG();
public: public:
virtual void set_iparams(std::string iparams); virtual void append_iparam(std::string iparam);
virtual void set_oformat(std::string format); virtual void set_oformat(std::string format);
virtual std::string output(); virtual std::string output();
public: public:

View file

@ -410,6 +410,12 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective*
log_file += ".log"; log_file += ".log";
} }
std::string log_level = _srs_config->get_ff_log_level();
if (!log_level.empty()) {
ffmpeg->append_iparam("-loglevel");
ffmpeg->append_iparam(log_level);
}
// input // input
std::string input_type = _srs_config->get_ingest_input_type(ingest); std::string input_type = _srs_config->get_ingest_input_type(ingest);
if (input_type.empty()) { if (input_type.empty()) {
@ -423,7 +429,7 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective*
} }
// for file, set re. // for file, set re.
ffmpeg->set_iparams("-re"); ffmpeg->append_iparam("-re");
if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) { if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) {
return srs_error_wrap(err, "init ffmpeg"); return srs_error_wrap(err, "init ffmpeg");
@ -435,7 +441,7 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective*
} }
// for stream, no re. // for stream, no re.
ffmpeg->set_iparams(""); ffmpeg->append_iparam("");
if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) { if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) {
return srs_error_wrap(err, "init ffmpeg"); return srs_error_wrap(err, "init ffmpeg");

View file

@ -888,6 +888,11 @@ VOID TEST(ConfigMainTest, CheckConf_ff_log_dir)
MockSrsConfig conf; MockSrsConfig conf;
HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "ff_log_dirs ./objs;")); HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "ff_log_dirs ./objs;"));
} }
if (true) {
MockSrsConfig conf;
HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "ff_log_levels info;"));
}
} }
VOID TEST(ConfigMainTest, CheckConf_srs_log_level) VOID TEST(ConfigMainTest, CheckConf_srs_log_level)
@ -3503,11 +3508,12 @@ VOID TEST(ConfigMainTest, CheckVhostConfig5)
if (true) { if (true) {
MockSrsConfig conf; MockSrsConfig conf;
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "srs_log_tank xxx;srs_log_level xxx2;srs_log_file xxx3;ff_log_dir xxx4;")); HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "srs_log_tank xxx;srs_log_level xxx2;srs_log_file xxx3;ff_log_dir xxx4; ff_log_level xxx5;"));
EXPECT_TRUE(conf.get_log_tank_file()); EXPECT_TRUE(conf.get_log_tank_file());
EXPECT_STREQ("xxx2", conf.get_log_level().c_str()); EXPECT_STREQ("xxx2", conf.get_log_level().c_str());
EXPECT_STREQ("xxx3", conf.get_log_file().c_str()); EXPECT_STREQ("xxx3", conf.get_log_file().c_str());
EXPECT_STREQ("xxx4", conf.get_ff_log_dir().c_str()); EXPECT_STREQ("xxx4", conf.get_ff_log_dir().c_str());
EXPECT_STREQ("xxx5", conf.get_ff_log_level().c_str());
EXPECT_TRUE(conf.get_ff_log_enabled()); EXPECT_TRUE(conf.get_ff_log_enabled());
} }