diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 9c3b9afee..69decbdae 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -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 @@ -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; @@ -2350,6 +2410,57 @@ int SrsConfig::do_reload_pid() return ret; } +int SrsConfig::do_reload_srs_log_tank() +{ + int ret = ERROR_SUCCESS; + + vector::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::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::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; diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index d531ef0a8..0742053a3 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -349,9 +349,24 @@ public: * 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. diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index 16a16ddc5..3cfebeb22 100755 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -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; @@ -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); @@ -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.