void log_rotate(void) { log_file_check(log_file_sys); log_file_check(log_file_err); log_file_check(log_file_pt); log_file_rotate(log_file_sys); }
void TDebugLog::log_proc() { int used; char *tmp = new char[TDebugLog::BUFFER_SIZE]; setproctitle(_log_name.c_str(), "log"); _lock->get(); while (!stop || _buf->used > 0) { /* 等待日志信号到来 */ if (_buf->used <= 0) { sigset_t wait; sigfillset(&wait); sigdelset(&wait, SIGINT); sigdelset(&wait, SIGUSR1); _lock->post(); sigsuspend(&wait); // 等待信号 _lock->get(); } used = _buf->used; if (used > 0) { memcpy(tmp, _buf->data, used); // 拷贝数据到临时缓冲区用于写入文件 _buf->used = 0; // 清空日志缓冲 } _lock->post(); /* 将信息写入日志文件 */ if (used > 0 && _log_file >= 0) write(_log_file, tmp, used); // 检查日志文件大小 log_file_check(); // 重新获取锁 _lock->get(); } _lock->post(); delete [] tmp; }