From b290a00de719deec8cbd78a8b50a083f2d20a09f Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 23 Mar 2014 13:53:07 +0800 Subject: [PATCH] refine log --- trunk/etc/init.d/srs | 2 +- trunk/src/app/srs_app_log.cpp | 32 +++++++++++++++----------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/trunk/etc/init.d/srs b/trunk/etc/init.d/srs index bcbf30f9f..7e50d4e22 100755 --- a/trunk/etc/init.d/srs +++ b/trunk/etc/init.d/srs @@ -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 diff --git a/trunk/src/app/srs_app_log.cpp b/trunk/src/app/srs_app_log.cpp index a327171eb..9b4a009b5 100644 --- a/trunk/src/app/srs_app_log.cpp +++ b/trunk/src/app/srs_app_log.cpp @@ -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); + } }