Skip to content

Commit

Permalink
for #319, raw api support update srs log tank, level and file.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Sep 9, 2015
1 parent 8107e5f commit 6aafd07
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 22 deletions.
153 changes: 132 additions & 21 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,38 +951,23 @@ int SrsConfig::reload_conf(SrsConfig* conf)

// merge config: srs_log_tank
if (!srs_directive_equals(root->get("srs_log_tank"), old_root->get("srs_log_tank"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_log_tank()) != ERROR_SUCCESS) {
srs_error("notify subscribes reload srs_log_tank failed. ret=%d", ret);
return ret;
}
if ((ret = do_reload_srs_log_tank()) != ERROR_SUCCESS) {
return ret;
}
srs_trace("reload srs_log_tank success.");
}

// merge config: srs_log_level
if (!srs_directive_equals(root->get("srs_log_level"), old_root->get("srs_log_level"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_log_level()) != ERROR_SUCCESS) {
srs_error("notify subscribes reload srs_log_level failed. ret=%d", ret);
return ret;
}
if ((ret = do_reload_srs_log_level()) != ERROR_SUCCESS) {
return ret;
}
srs_trace("reload srs_log_level success.");
}

// merge config: srs_log_file
if (!srs_directive_equals(root->get("srs_log_file"), old_root->get("srs_log_file"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_log_file()) != ERROR_SUCCESS) {
srs_error("notify subscribes reload srs_log_file failed. ret=%d", ret);
return ret;
}
if ((ret = do_reload_srs_log_file()) != ERROR_SUCCESS) {
return ret;
}
srs_trace("reload srs_log_file success.");
}

// merge config: pithy_print_ms
Expand Down Expand Up @@ -2316,6 +2301,81 @@ int SrsConfig::raw_set_ff_log_dir(string ff_log_dir, bool& applied)
return ret;
}

int SrsConfig::raw_set_srs_log_tank(string srs_log_tank, bool& applied)
{
int ret = ERROR_SUCCESS;

applied = false;


SrsConfDirective* conf = root->get_or_create("srs_log_tank");

if (conf->arg0() == srs_log_tank) {
return ret;
}

conf->args.clear();
conf->args.push_back(srs_log_tank);

if ((ret = do_reload_srs_log_tank()) != ERROR_SUCCESS) {
return ret;
}

applied = true;

return ret;
}

int SrsConfig::raw_set_srs_log_level(string srs_log_level, bool& applied)
{
int ret = ERROR_SUCCESS;

applied = false;


SrsConfDirective* conf = root->get_or_create("srs_log_level");

if (conf->arg0() == srs_log_level) {
return ret;
}

conf->args.clear();
conf->args.push_back(srs_log_level);

if ((ret = do_reload_srs_log_level()) != ERROR_SUCCESS) {
return ret;
}

applied = true;

return ret;
}

int SrsConfig::raw_set_srs_log_file(string srs_log_file, bool& applied)
{
int ret = ERROR_SUCCESS;

applied = false;


SrsConfDirective* conf = root->get_or_create("srs_log_file");

if (conf->arg0() == srs_log_file) {
return ret;
}

conf->args.clear();
conf->args.push_back(srs_log_file);

if ((ret = do_reload_srs_log_file()) != ERROR_SUCCESS) {
return ret;
}

applied = true;

return ret;
}

int SrsConfig::do_reload_listen()
{
int ret = ERROR_SUCCESS;
Expand Down Expand Up @@ -2350,6 +2410,57 @@ int SrsConfig::do_reload_pid()
return ret;
}

int SrsConfig::do_reload_srs_log_tank()
{
int ret = ERROR_SUCCESS;

vector<ISrsReloadHandler*>::iterator it;
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_log_tank()) != ERROR_SUCCESS) {
srs_error("notify subscribes reload srs_log_tank failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload srs_log_tank success.");

return ret;
}

int SrsConfig::do_reload_srs_log_level()
{
int ret = ERROR_SUCCESS;

vector<ISrsReloadHandler*>::iterator it;
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_log_level()) != ERROR_SUCCESS) {
srs_error("notify subscribes reload srs_log_level failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload srs_log_level success.");

return ret;
}

int SrsConfig::do_reload_srs_log_file()
{
int ret = ERROR_SUCCESS;

vector<ISrsReloadHandler*>::iterator it;
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_log_file()) != ERROR_SUCCESS) {
srs_error("notify subscribes reload srs_log_file failed. ret=%d", ret);
return ret;
}
}
srs_trace("reload srs_log_file success.");

return ret;
}

string SrsConfig::config()
{
return config_file;
Expand Down
15 changes: 15 additions & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,24 @@ class SrsConfig
* raw set the global ffmpeg log dir.
*/
virtual int raw_set_ff_log_dir(std::string ff_log_dir, bool& applied);
/**
* raw set the global log tank.
*/
virtual int raw_set_srs_log_tank(std::string srs_log_tank, bool& applied);
/**
* raw set the global log level.
*/
virtual int raw_set_srs_log_level(std::string srs_log_level, bool& applied);
/**
* raw set the global log file path for file tank.
*/
virtual int raw_set_srs_log_file(std::string srs_log_file, bool& applied);
private:
virtual int do_reload_listen();
virtual int do_reload_pid();
virtual int do_reload_srs_log_tank();
virtual int do_reload_srs_log_level();
virtual int do_reload_srs_log_file();
public:
/**
* get the config file path.
Expand Down
40 changes: 39 additions & 1 deletion trunk/src/app/srs_app_http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,10 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
// listen 1935,1936 the port list.
// pid ./objs/srs.pid the pid file of srs.
// chunk_size 60000 the global RTMP chunk_size.
// ff_log_dir ./objs the dir for ffmpeg log.
// srs_log_tank file the tank to log, file or console.
// srs_log_level trace the level of log, verbose, info, trace, warn, error.
// srs_log_file ./objs/srs.log the log file when tank is file.
if (rpc == "update") {
if (!allow_update) {
ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED;
Expand All @@ -1004,7 +1008,8 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
return srs_api_response_code(w, r, ret);
}
if (scope != "listen" && scope != "pid" && scope != "chunk_size"
&& scope != "ff_log_dir"
&& scope != "ff_log_dir" && scope != "srs_log_tank" && scope != "srs_log_level"
&& scope != "srs_log_file"
) {
ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED;
srs_error("raw api query invalid scope=%s. ret=%d", scope.c_str(), ret);
Expand Down Expand Up @@ -1068,6 +1073,39 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
srs_error("raw api update ff_log_dir=%s failed. ret=%d", value.c_str(), ret);
return srs_api_response_code(w, r, ret);
}
} else if (scope == "srs_log_tank") {
if (value.empty() || (value != "file" && value != "console")) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS;
srs_error("raw api update check srs_log_tank=%s failed. ret=%d", value.c_str(), ret);
return srs_api_response_code(w, r, ret);
}

if ((ret = _srs_config->raw_set_srs_log_tank(value, applied)) != ERROR_SUCCESS) {
srs_error("raw api update srs_log_tank=%s failed. ret=%d", value.c_str(), ret);
return srs_api_response_code(w, r, ret);
}
} else if (scope == "srs_log_level") {
if (value != "verbose" && value != "info" && value != "trace" && value != "warn" && value != "error") {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS;
srs_error("raw api update check srs_log_level=%s failed. ret=%d", value.c_str(), ret);
return srs_api_response_code(w, r, ret);
}

if ((ret = _srs_config->raw_set_srs_log_level(value, applied)) != ERROR_SUCCESS) {
srs_error("raw api update srs_log_level=%s failed. ret=%d", value.c_str(), ret);
return srs_api_response_code(w, r, ret);
}
} else if (scope == "srs_log_file") {
if (value.empty() || !srs_string_starts_with(value, "./", "/tmp/", "/var/") || !srs_string_ends_with(value, ".log")) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS;
srs_error("raw api update check srs_log_file=%s failed. ret=%d", value.c_str(), ret);
return srs_api_response_code(w, r, ret);
}

if ((ret = _srs_config->raw_set_srs_log_file(value, applied)) != ERROR_SUCCESS) {
srs_error("raw api update srs_log_file=%s failed. ret=%d", value.c_str(), ret);
return srs_api_response_code(w, r, ret);
}
}

// whether the config applied.
Expand Down

0 comments on commit 6aafd07

Please sign in to comment.