On 8 Sep 2006 02:37:20 -0700, "mdler" <ol************@gmail.com>
wrote:
(topposting fixed)
ab*****@gmail.com schreef:
I need to know that is it possible to create new log daily on
a running system ?
t is posible, make something from the date in the logfilename
I use mostly yyyymmdd as subplement on the filename
long today(void)
{
char tijda[11];
time_t tijd;
struct tm *tijd2;
tijd = time(NULL);
tijd2 = localtime(&tijd);
tijd2->tm_mon++; /* heeft 0=jan tot 11=dec */
sprintf(tijda,"%04d%02d%02d",tijd2->tm_year+1900,tijd2->tm_mon,tijd2->tm_mday);
return (ULong)atol(tijda);
Or to avoid the useless conversions, just
return (long)(t->tm_year+1900)*10000L + t->mon*100 + t->tm_mday;
/* or t->tm_year*10000L + 19000000 + ...
}
{
char log_file[80];
FILE *fp_stdout=NULL;
sprintf(log_file, "%s_%08d.log", "sample",today());
fp_stdout = fopen(log_file, "a");
}
now every day there is a new logfile name created
Every time _this code is executed_ on a different day.
In a 'running system' or more specifically program, if you only open
the logfile at startup, it won't automatically switch. You must either
(close and) reopen it on _every_ output, which can be inefficient (but
also robust); or check on every output whether the date has changed
and reopen if so; or <not standard Cset yourself to receive some
kind of signal or alarm when the date changes and reopen then. </>
- David.Thompson1 at worldnet.att.net