会写日志的朋友看一下

来源:百度知道 编辑:UC知道 时间:2024/06/09 07:00:59
有哪位朋友写过日志文件,就是写一个模块,负责将每个时间单元的事件生成log文件。
如果有现成的代码恳请贴出来,劳烦注释一下,谢谢

int Server::system_log(char *log)
{
memset(log_buf,'\0',MAXSIZE);
time_t timer;
timer = time(NULL);
strcat(log_buf,ctime(&timer));
strcat(log_buf," ");
strcat(log_buf,log);
strcat(log_buf,"\r\n");
if ( write(log_fd,log_buf,strlen(log_buf)) == -1 )
{
cout<<"写文件错误"<<endl;
exit(1);
}

}