问题描述
在此功能中,如果尚未创建,我将打开/创建文件,然后在另一个prinf函数中打印一些内容。
以下是问题:由于内存消耗原因,如何为日志文件设置最大大小。这样文件就不会变大并降低性能问题。
设置文件大小后,我希望旧的日志消息被覆盖,以便新的日志消息可以继续追加到文件末尾。
static int lnx_debug_file_open(const char *file) {
#ifdef CONfig_DEBUG_FILE
int dfile_fd = -1;
if(!file)
return 0;
dfile_fd = open(file,O_CREAT | O_APPEND | O_WRONLY,S_IRUSR | S_IWUSR | S_IRGRP);
if(dfile_fd < 0) {
lnx_printf(LOG_TAG,"Logging_Library","Debug logging file %s opening Failed",file);
return -1;
}
if (fcntl(dfile_fd,F_SETFD,FD_CLOEXEC) < 0) {
lnx_printf(LOG_TAG,"Debug logging file %s Failed to set FD_CLOEXEC",file);
}
out_file = fdopen(dfile_fd,"a");
if (out_file == NULL) {
lnx_printf(LOG_TAG,"Debug logging file %s Failed to open,using stdout",file);
close(dfile_fd);
return -1;
}
#endif /* CONfig_DEBUG_FILE */
return 0;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)