正在显示
4 个修改的文件
包含
19 行增加
和
19 行删除
| @@ -205,6 +205,10 @@ void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...) | @@ -205,6 +205,10 @@ void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...) | ||
| 205 | int SrsFastLog::on_reload_log_tank() | 205 | int SrsFastLog::on_reload_log_tank() |
| 206 | { | 206 | { |
| 207 | int ret = ERROR_SUCCESS; | 207 | int ret = ERROR_SUCCESS; |
| 208 | + | ||
| 209 | + if (!_srs_config) { | ||
| 210 | + return ret; | ||
| 211 | + } | ||
| 208 | 212 | ||
| 209 | bool tank = log_to_file_tank; | 213 | bool tank = log_to_file_tank; |
| 210 | log_to_file_tank = _srs_config->get_log_tank_file(); | 214 | log_to_file_tank = _srs_config->get_log_tank_file(); |
| @@ -229,6 +233,10 @@ int SrsFastLog::on_reload_log_level() | @@ -229,6 +233,10 @@ int SrsFastLog::on_reload_log_level() | ||
| 229 | { | 233 | { |
| 230 | int ret = ERROR_SUCCESS; | 234 | int ret = ERROR_SUCCESS; |
| 231 | 235 | ||
| 236 | + if (!_srs_config) { | ||
| 237 | + return ret; | ||
| 238 | + } | ||
| 239 | + | ||
| 232 | _level = srs_get_log_level(_srs_config->get_log_level()); | 240 | _level = srs_get_log_level(_srs_config->get_log_level()); |
| 233 | 241 | ||
| 234 | return ret; | 242 | return ret; |
| @@ -237,6 +245,10 @@ int SrsFastLog::on_reload_log_level() | @@ -237,6 +245,10 @@ int SrsFastLog::on_reload_log_level() | ||
| 237 | int SrsFastLog::on_reload_log_file() | 245 | int SrsFastLog::on_reload_log_file() |
| 238 | { | 246 | { |
| 239 | int ret = ERROR_SUCCESS; | 247 | int ret = ERROR_SUCCESS; |
| 248 | + | ||
| 249 | + if (!_srs_config) { | ||
| 250 | + return ret; | ||
| 251 | + } | ||
| 240 | 252 | ||
| 241 | if (!log_to_file_tank) { | 253 | if (!log_to_file_tank) { |
| 242 | return ret; | 254 | return ret; |
| @@ -345,6 +357,10 @@ void SrsFastLog::write_log(int& fd, char *str_log, int size, int level) | @@ -345,6 +357,10 @@ void SrsFastLog::write_log(int& fd, char *str_log, int size, int level) | ||
| 345 | 357 | ||
| 346 | void SrsFastLog::open_log_file() | 358 | void SrsFastLog::open_log_file() |
| 347 | { | 359 | { |
| 360 | + if (!_srs_config) { | ||
| 361 | + return; | ||
| 362 | + } | ||
| 363 | + | ||
| 348 | std::string filename = _srs_config->get_log_file(); | 364 | std::string filename = _srs_config->get_log_file(); |
| 349 | 365 | ||
| 350 | if (filename.empty()) { | 366 | if (filename.empty()) { |
| @@ -57,6 +57,8 @@ public: | @@ -57,6 +57,8 @@ public: | ||
| 57 | 57 | ||
| 58 | /** | 58 | /** |
| 59 | * we use memory/disk cache and donot flush when write log. | 59 | * we use memory/disk cache and donot flush when write log. |
| 60 | +* it's ok to use it without config, which will log to console, and default trace level. | ||
| 61 | +* when you want to use different level, override this classs, set the protected _level. | ||
| 60 | */ | 62 | */ |
| 61 | class SrsFastLog : public ISrsLog, public ISrsReloadHandler | 63 | class SrsFastLog : public ISrsLog, public ISrsReloadHandler |
| 62 | { | 64 | { |
| @@ -64,6 +66,7 @@ class SrsFastLog : public ISrsLog, public ISrsReloadHandler | @@ -64,6 +66,7 @@ class SrsFastLog : public ISrsLog, public ISrsReloadHandler | ||
| 64 | protected: | 66 | protected: |
| 65 | // defined in SrsLogLevel. | 67 | // defined in SrsLogLevel. |
| 66 | int _level; | 68 | int _level; |
| 69 | +private: | ||
| 67 | char* log_data; | 70 | char* log_data; |
| 68 | // log to file if specified srs_log_file | 71 | // log to file if specified srs_log_file |
| 69 | int fd; | 72 | int fd; |
| @@ -45,21 +45,6 @@ MockEmptyLog::~MockEmptyLog() | @@ -45,21 +45,6 @@ MockEmptyLog::~MockEmptyLog() | ||
| 45 | { | 45 | { |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | -int MockEmptyLog::on_reload_log_tank() | ||
| 49 | -{ | ||
| 50 | - return ERROR_SUCCESS; | ||
| 51 | -} | ||
| 52 | - | ||
| 53 | -int MockEmptyLog::on_reload_log_level() | ||
| 54 | -{ | ||
| 55 | - return ERROR_SUCCESS; | ||
| 56 | -} | ||
| 57 | - | ||
| 58 | -int MockEmptyLog::on_reload_log_file() | ||
| 59 | -{ | ||
| 60 | - return ERROR_SUCCESS; | ||
| 61 | -} | ||
| 62 | - | ||
| 63 | void __srs_bytes_print(char* pa, int size) | 48 | void __srs_bytes_print(char* pa, int size) |
| 64 | { | 49 | { |
| 65 | for(int i = 0; i < size; i++) { | 50 | for(int i = 0; i < size; i++) { |
| @@ -61,10 +61,6 @@ private: | @@ -61,10 +61,6 @@ private: | ||
| 61 | public: | 61 | public: |
| 62 | MockEmptyLog(int level); | 62 | MockEmptyLog(int level); |
| 63 | virtual ~MockEmptyLog(); | 63 | virtual ~MockEmptyLog(); |
| 64 | -public: | ||
| 65 | - virtual int on_reload_log_tank(); | ||
| 66 | - virtual int on_reload_log_level(); | ||
| 67 | - virtual int on_reload_log_file(); | ||
| 68 | }; | 64 | }; |
| 69 | 65 | ||
| 70 | #endif | 66 | #endif |
-
请 注册 或 登录 后发表评论