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

add log tank config, default to console.

This commit is contained in:
winlin 2014-03-23 14:40:55 +08:00
parent b290a00de7
commit 7930add7f9
9 changed files with 100 additions and 62 deletions

View file

@ -308,7 +308,7 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<string>& arg
srs_error("line %d: unexpected end of file, expecting ; or \"}\"", buffer->line);
return ERROR_SYSTEM_CONFIG_INVALID;
}
srs_trace("end of file. ret=%d", ret);
srs_trace("config parsed EOF");
return ret;
}
@ -684,7 +684,13 @@ int SrsConfig::parse_file(const char* filename)
// TODO: check http.
// TODO: check pid.
// check log
std::string log_filename = this->get_srs_log_file();
if (this->get_srs_log_tank_file() && log_filename.empty()) {
ret = ERROR_SYSTEM_CONFIG_INVALID;
srs_error("must specifies the file to write log to. ret=%d", ret);
return ret;
}
if (!log_filename.empty()) {
srs_trace("log file is %s", log_filename.c_str());
}
@ -1282,6 +1288,18 @@ string SrsConfig::get_srs_log_file()
return conf->arg0();
}
bool SrsConfig::get_srs_log_tank_file()
{
srs_assert(root);
SrsConfDirective* conf = root->get("srs_log_tank");
if (conf && conf->arg0() == "file") {
return true;
}
return false;
}
bool SrsConfig::get_deamon()
{
srs_assert(root);

View file

@ -148,6 +148,7 @@ public:
virtual void get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams);
virtual std::string get_engine_output(SrsConfDirective* engine);
virtual std::string get_ffmpeg_log_dir();
virtual bool get_srs_log_tank_file();
virtual std::string get_srs_log_file();
virtual bool get_deamon();
virtual int get_max_connections();

View file

@ -42,7 +42,7 @@ SrsThreadContext::~SrsThreadContext()
void SrsThreadContext::generate_id()
{
static int id = 1;
static int id = 100;
cache[st_thread_self()] = id++;
}
@ -230,20 +230,22 @@ void SrsFastLog::write_log(char *str_log, int size, int _level)
log_data[size++] = LOG_TAIL;
log_data[size++] = 0;
// if is error msg, then print color msg.
// \033[31m : red text code in shell
// \033[32m : green text code in shell
// \033[33m : yellow text code in shell
// \033[0m : normal text code
if (_level <= SrsLogLevel::Trace) {
printf("%s", str_log);
} else if (_level == SrsLogLevel::Warn) {
printf("\033[33m%s\033[0m", str_log);
} else{
printf("\033[31m%s\033[0m", str_log);
if (fd < 0 || !_srs_config->get_srs_log_tank_file()) {
// if is error msg, then print color msg.
// \033[31m : red text code in shell
// \033[32m : green text code in shell
// \033[33m : yellow text code in shell
// \033[0m : normal text code
if (_level <= SrsLogLevel::Trace) {
printf("%s", str_log);
} else if (_level == SrsLogLevel::Warn) {
printf("\033[33m%s\033[0m", str_log);
} else{
printf("\033[31m%s\033[0m", str_log);
}
}
// open log file.
// open log file. if specified
if (!_srs_config->get_srs_log_file().empty() && fd < 0) {
std::string filename = _srs_config->get_srs_log_file();
@ -256,8 +258,9 @@ void SrsFastLog::write_log(char *str_log, int size, int _level)
);
}
}
// write log to file.
if (fd > 0) {
if (fd > 0 && _srs_config->get_srs_log_tank_file()) {
::write(fd, str_log, size);
}
}

View file

@ -179,26 +179,6 @@ SrsServer::~SrsServer()
int SrsServer::initialize()
{
int ret = ERROR_SUCCESS;
// use linux epoll.
if (st_set_eventsys(ST_EVENTSYS_ALT) == -1) {
ret = ERROR_ST_SET_EPOLL;
srs_error("st_set_eventsys use linux epoll failed. ret=%d", ret);
return ret;
}
srs_verbose("st_set_eventsys use linux epoll success");
if(st_init() != 0){
ret = ERROR_ST_INITIALIZE;
srs_error("st_init failed. ret=%d", ret);
return ret;
}
srs_verbose("st_init success");
// set current log id.
_srs_context->generate_id();
srs_info("log set id success");
return ret;
}
@ -277,6 +257,32 @@ int SrsServer::acquire_pid_file()
return ret;
}
int SrsServer::initialize_st()
{
int ret = ERROR_SUCCESS;
// use linux epoll.
if (st_set_eventsys(ST_EVENTSYS_ALT) == -1) {
ret = ERROR_ST_SET_EPOLL;
srs_error("st_set_eventsys use linux epoll failed. ret=%d", ret);
return ret;
}
srs_verbose("st_set_eventsys use linux epoll success");
if(st_init() != 0){
ret = ERROR_ST_INITIALIZE;
srs_error("st_init failed. ret=%d", ret);
return ret;
}
srs_verbose("st_init success");
// set current log id.
_srs_context->generate_id();
srs_info("log set id success");
return ret;
}
int SrsServer::listen()
{
int ret = ERROR_SUCCESS;

View file

@ -80,6 +80,7 @@ public:
public:
virtual int initialize();
virtual int acquire_pid_file();
virtual int initialize_st();
virtual int listen();
virtual int cycle();
virtual void remove(SrsConnection* conn);