mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 11:21:52 +00:00
For #1592, support ff_log_level and default to warning
This commit is contained in:
parent
2fa151726b
commit
c50c51889a
7 changed files with 46 additions and 11 deletions
|
@ -19,11 +19,16 @@ pid ./objs/srs.pid;
|
|||
# performance about 10%.
|
||||
# default: 60000
|
||||
chunk_size 60000;
|
||||
# the logs dir.
|
||||
# the log dir for FFMPEG.
|
||||
# if enabled ffmpeg, each transcoding stream will create a log file.
|
||||
# /dev/null to disable the log.
|
||||
# default: ./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.
|
||||
# if console, print log to console.
|
||||
# if file, write log to file. requires srs_log_file if log to 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_server" && n != "stream_caster"
|
||||
&& 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());
|
||||
}
|
||||
|
@ -5782,6 +5783,18 @@ string SrsConfig::get_ff_log_dir()
|
|||
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* conf = get_vhost(vhost);
|
||||
|
|
|
@ -783,6 +783,8 @@ public:
|
|||
// The ffmpeg log dir.
|
||||
// @remark, /dev/null to disable it.
|
||||
virtual std::string get_ff_log_dir();
|
||||
// The ffmpeg log level.
|
||||
virtual std::string get_ff_log_level();
|
||||
// The MPEG-DASH section.
|
||||
private:
|
||||
virtual SrsConfDirective* get_dash(std::string vhost);
|
||||
|
|
|
@ -82,9 +82,9 @@ SrsFFMPEG::~SrsFFMPEG()
|
|||
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)
|
||||
|
@ -230,8 +230,11 @@ srs_error_t SrsFFMPEG::start()
|
|||
params.push_back(ffmpeg);
|
||||
|
||||
// input params
|
||||
if (!_iparams.empty()) {
|
||||
params.push_back(_iparams);
|
||||
for (int i = 0; i < iparams.size(); i++) {
|
||||
string iparam = iparams.at(i);
|
||||
if (!iparam.empty()) {
|
||||
params.push_back(iparam);
|
||||
}
|
||||
}
|
||||
|
||||
// build the perfile
|
||||
|
|
|
@ -45,7 +45,7 @@ private:
|
|||
std::string log_file;
|
||||
private:
|
||||
std::string ffmpeg;
|
||||
std::string _iparams;
|
||||
std::vector<std::string> iparams;
|
||||
std::vector<std::string> perfile;
|
||||
std::string iformat;
|
||||
std::string input;
|
||||
|
@ -70,7 +70,7 @@ public:
|
|||
SrsFFMPEG(std::string ffmpeg_bin);
|
||||
virtual ~SrsFFMPEG();
|
||||
public:
|
||||
virtual void set_iparams(std::string iparams);
|
||||
virtual void append_iparam(std::string iparam);
|
||||
virtual void set_oformat(std::string format);
|
||||
virtual std::string output();
|
||||
public:
|
||||
|
|
|
@ -409,7 +409,13 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective*
|
|||
log_file += stream;
|
||||
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
|
||||
std::string input_type = _srs_config->get_ingest_input_type(ingest);
|
||||
if (input_type.empty()) {
|
||||
|
@ -423,7 +429,7 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective*
|
|||
}
|
||||
|
||||
// for file, set re.
|
||||
ffmpeg->set_iparams("-re");
|
||||
ffmpeg->append_iparam("-re");
|
||||
|
||||
if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) {
|
||||
return srs_error_wrap(err, "init ffmpeg");
|
||||
|
@ -435,7 +441,7 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective*
|
|||
}
|
||||
|
||||
// for stream, no re.
|
||||
ffmpeg->set_iparams("");
|
||||
ffmpeg->append_iparam("");
|
||||
|
||||
if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) {
|
||||
return srs_error_wrap(err, "init ffmpeg");
|
||||
|
|
|
@ -888,6 +888,11 @@ VOID TEST(ConfigMainTest, CheckConf_ff_log_dir)
|
|||
MockSrsConfig conf;
|
||||
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)
|
||||
|
@ -3503,11 +3508,12 @@ VOID TEST(ConfigMainTest, CheckVhostConfig5)
|
|||
|
||||
if (true) {
|
||||
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_STREQ("xxx2", conf.get_log_level().c_str());
|
||||
EXPECT_STREQ("xxx3", conf.get_log_file().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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue