我的应用程序的log文件变得越来越大,请问如何使用循环logging?

来源:百度知道 编辑:UC知道 时间:2024/06/14 19:37:09
能否给出一段C/C++的代码?万分感谢!

以下这段程序是我自己 编写并测试过了的测试过了的.....
最大定义的默认的可循环logfile size是500M
不过,在使用的时候,用logfilesize 来替代
除非logfilesize=0才使用

本程序的使用方法:

if(traceEnabled) {
trace("....");
}

#define MAXFILESIZE (500*1024*1024) /*Maximum file size in Kbytes:500M*/

static CRITICAL_SECTION traceMutex ;
//static CRITICAL_SECTION performanceTraceMutex ;
static char fname[256]=LOGDIR; /*set a default logdir*/
static int initialized=0; /*trace() should call traceInit if this value is not set*/
extern int removeTraceFiles; /*t==1, the log file will be deleted at anytime*/
extern int maxfilesize; /*filesize Kbytes */
extern long position;
void
traceInit(char *p_logDir) {

strcpy(fname, p_logDir) ;

InitializeCriticalSection(&traceMutex) ;
//InitializeCriticalSection(&performanceTraceMutex) ;

if (removeTraceFiles) {
DeleteFile(fname