函数的参数:想往日志里写什么就加什么参数
改完参数记得更改sprintf()中的参数
下面代码写在日志中的格式:
时间|进程绝对路径|IP|端口|结果
void writeRecord(const char* bufTime,const char* processPath,const char* ip,const char* port,const char* ret)
{
char* recordFilePath = "/home/projects/protectFile/recordDaily.txt";
char record[1024]={0};
FILE* fp=fopen(recordFilePath,"a+");
if(fp==NULL)
{
printf("fp is NULL and open file fail\n");
return;
}
//printf("fp!=NULL\n");
if(sprintf(record,"%.*s|%.*s|%.*s|%.*s|%.*s",(int)strlen(bufTime),bufTime,(int)strlen(processPath),processPath,(int)strlen(ip),ip,(int)strlen(port),port,(int)strlen(ret),ret)<0)
printf("sprintf() error!\n");
if(record)
{
fwrite(record,strlen(record),1,fp);
char* next= "\n";
fwrite(next,strlen(next),1,fp);
}
fclose(fp);
}