refine log

pull/133/head
winlin 11 years ago
parent d9104f3b5e
commit b290a00de7

@ -78,7 +78,7 @@ start() {
fi
# check again after start server
sleep 0.5
sleep 1
for ((i = 0; i < 5; i++)); do
# sleep a little while, for srs may start then crash.
sleep 0.1

@ -243,23 +243,21 @@ void SrsFastLog::write_log(char *str_log, int size, int _level)
printf("\033[31m%s\033[0m", str_log);
}
// if specified log file, write log to it.
if (!_srs_config->get_srs_log_file().empty()) {
if (fd < 0) {
std::string filename = _srs_config->get_srs_log_file();
fd = ::open(filename.c_str(), O_RDWR | O_APPEND);
if(fd == -1 && errno == ENOENT) {
fd = open(filename.c_str(),
O_RDWR | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH
);
}
}
if (fd > 0) {
::write(fd, str_log, size);
// open log file.
if (!_srs_config->get_srs_log_file().empty() && fd < 0) {
std::string filename = _srs_config->get_srs_log_file();
fd = ::open(filename.c_str(), O_RDWR | O_APPEND);
if(fd == -1 && errno == ENOENT) {
fd = open(filename.c_str(),
O_RDWR | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH
);
}
}
// write log to file.
if (fd > 0) {
::write(fd, str_log, size);
}
}

Loading…
Cancel
Save