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

add srs_log_file to write log to file. change to 0.9.27

This commit is contained in:
winlin 2014-03-23 12:21:36 +08:00
parent 4ddb5256ac
commit d94b9f44b3
10 changed files with 76 additions and 10 deletions

View file

@ -26,6 +26,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <stdarg.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <srs_app_config.hpp>
SrsThreadContext::SrsThreadContext()
{
}
@ -57,11 +63,18 @@ SrsFastLog::SrsFastLog()
{
level = SrsLogLevel::Trace;
log_data = new char[LOG_MAX_SIZE];
fd = -1;
}
SrsFastLog::~SrsFastLog()
{
srs_freepa(log_data);
if (fd > 0) {
::close(fd);
fd = -1;
}
}
void SrsFastLog::verbose(const char* tag, int context_id, const char* fmt, ...)
@ -229,4 +242,24 @@ void SrsFastLog::write_log(char *str_log, int size, int _level)
} else{
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);
}
}
}