winlin

refine log

@@ -78,7 +78,7 @@ start() { @@ -78,7 +78,7 @@ start() {
78 fi 78 fi
79 79
80 # check again after start server 80 # check again after start server
81 - sleep 0.5 81 + sleep 1
82 for ((i = 0; i < 5; i++)); do 82 for ((i = 0; i < 5; i++)); do
83 # sleep a little while, for srs may start then crash. 83 # sleep a little while, for srs may start then crash.
84 sleep 0.1 84 sleep 0.1
@@ -243,23 +243,21 @@ void SrsFastLog::write_log(char *str_log, int size, int _level) @@ -243,23 +243,21 @@ void SrsFastLog::write_log(char *str_log, int size, int _level)
243 printf("\033[31m%s\033[0m", str_log); 243 printf("\033[31m%s\033[0m", str_log);
244 } 244 }
245 245
246 - // if specified log file, write log to it.  
247 - if (!_srs_config->get_srs_log_file().empty()) {  
248 - if (fd < 0) {  
249 - std::string filename = _srs_config->get_srs_log_file();  
250 -  
251 - fd = ::open(filename.c_str(), O_RDWR | O_APPEND);  
252 -  
253 - if(fd == -1 && errno == ENOENT) {  
254 - fd = open(filename.c_str(),  
255 - O_RDWR | O_CREAT | O_TRUNC,  
256 - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH  
257 - );  
258 - }  
259 - }  
260 -  
261 - if (fd > 0) {  
262 - ::write(fd, str_log, size); 246 + // open log file.
  247 + if (!_srs_config->get_srs_log_file().empty() && fd < 0) {
  248 + std::string filename = _srs_config->get_srs_log_file();
  249 +
  250 + fd = ::open(filename.c_str(), O_RDWR | O_APPEND);
  251 +
  252 + if(fd == -1 && errno == ENOENT) {
  253 + fd = open(filename.c_str(),
  254 + O_RDWR | O_CREAT | O_TRUNC,
  255 + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH
  256 + );
263 } 257 }
264 } 258 }
  259 + // write log to file.
  260 + if (fd > 0) {
  261 + ::write(fd, str_log, size);
  262 + }
265 } 263 }