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

refine log, can be used when _srs_config is NULL.

This commit is contained in:
winlin 2014-07-26 14:58:33 +08:00
parent 7241fa8744
commit 9f2da4e095
4 changed files with 19 additions and 19 deletions

View file

@ -205,6 +205,10 @@ void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...)
int SrsFastLog::on_reload_log_tank() int SrsFastLog::on_reload_log_tank()
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
if (!_srs_config) {
return ret;
}
bool tank = log_to_file_tank; bool tank = log_to_file_tank;
log_to_file_tank = _srs_config->get_log_tank_file(); log_to_file_tank = _srs_config->get_log_tank_file();
@ -229,6 +233,10 @@ int SrsFastLog::on_reload_log_level()
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
if (!_srs_config) {
return ret;
}
_level = srs_get_log_level(_srs_config->get_log_level()); _level = srs_get_log_level(_srs_config->get_log_level());
return ret; return ret;
@ -237,6 +245,10 @@ int SrsFastLog::on_reload_log_level()
int SrsFastLog::on_reload_log_file() int SrsFastLog::on_reload_log_file()
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
if (!_srs_config) {
return ret;
}
if (!log_to_file_tank) { if (!log_to_file_tank) {
return ret; return ret;
@ -345,6 +357,10 @@ void SrsFastLog::write_log(int& fd, char *str_log, int size, int level)
void SrsFastLog::open_log_file() void SrsFastLog::open_log_file()
{ {
if (!_srs_config) {
return;
}
std::string filename = _srs_config->get_log_file(); std::string filename = _srs_config->get_log_file();
if (filename.empty()) { if (filename.empty()) {

View file

@ -57,6 +57,8 @@ public:
/** /**
* we use memory/disk cache and donot flush when write log. * we use memory/disk cache and donot flush when write log.
* it's ok to use it without config, which will log to console, and default trace level.
* when you want to use different level, override this classs, set the protected _level.
*/ */
class SrsFastLog : public ISrsLog, public ISrsReloadHandler class SrsFastLog : public ISrsLog, public ISrsReloadHandler
{ {
@ -64,6 +66,7 @@ class SrsFastLog : public ISrsLog, public ISrsReloadHandler
protected: protected:
// defined in SrsLogLevel. // defined in SrsLogLevel.
int _level; int _level;
private:
char* log_data; char* log_data;
// log to file if specified srs_log_file // log to file if specified srs_log_file
int fd; int fd;

View file

@ -45,21 +45,6 @@ MockEmptyLog::~MockEmptyLog()
{ {
} }
int MockEmptyLog::on_reload_log_tank()
{
return ERROR_SUCCESS;
}
int MockEmptyLog::on_reload_log_level()
{
return ERROR_SUCCESS;
}
int MockEmptyLog::on_reload_log_file()
{
return ERROR_SUCCESS;
}
void __srs_bytes_print(char* pa, int size) void __srs_bytes_print(char* pa, int size)
{ {
for(int i = 0; i < size; i++) { for(int i = 0; i < size; i++) {

View file

@ -61,10 +61,6 @@ private:
public: public:
MockEmptyLog(int level); MockEmptyLog(int level);
virtual ~MockEmptyLog(); virtual ~MockEmptyLog();
public:
virtual int on_reload_log_tank();
virtual int on_reload_log_level();
virtual int on_reload_log_file();
}; };
#endif #endif