Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Creating a log on daily basis

Reply
Thread Tools

Creating a log on daily basis

 
 
abhi147@gmail.com
Guest
Posts: n/a
 
      09-08-2006
Hi ,

I need to know that is it possible to create new log daily on
a running system ?

I am using these basic file write statements to print the logs :

char log_file[80];
FILE *fp_stdout;
FILE *fp_stderr;

sprintf(log_file, "%s.log", "sample");
fp_stdout = fopen(log_file, "a");

Thanks for your help !

 
Reply With Quote
 
 
 
 
mdler
Guest
Posts: n/a
 
      09-08-2006
Hello

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);
}

{
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

today it should be 'sample_20060908.log'

Greetings Olaf

http://www.velocityreviews.com/forums/(E-Mail Removed) schreef:

> Hi ,
>
> I need to know that is it possible to create new log daily on
> a running system ?
>
> I am using these basic file write statements to print the logs :
>
> char log_file[80];
> FILE *fp_stdout;
> FILE *fp_stderr;
>
> sprintf(log_file, "%s.log", "sample");
> fp_stdout = fopen(log_file, "a");
>
> Thanks for your help !


 
Reply With Quote
 
 
 
 
abhi147@gmail.com
Guest
Posts: n/a
 
      09-11-2006

mdler wrote:
> Hello
>
> 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);
> }
>
> {
> 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
>
> today it should be 'sample_20060908.log'
>
> Greetings Olaf
>
> (E-Mail Removed) schreef:
>
> > Hi ,
> >
> > I need to know that is it possible to create new log daily on
> > a running system ?
> >
> > I am using these basic file write statements to print the logs :
> >
> > char log_file[80];
> > FILE *fp_stdout;
> > FILE *fp_stderr;
> >
> > sprintf(log_file, "%s.log", "sample");
> > fp_stdout = fopen(log_file, "a");
> >
> > Thanks for your help !



Thanks a lot :- )

 
Reply With Quote
 
Dave Thompson
Guest
Posts: n/a
 
      09-21-2006
On 8 Sep 2006 02:37:20 -0700, "mdler" <(E-Mail Removed)>
wrote:
(topposting fixed)
> (E-Mail Removed) 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 C> set yourself to receive some
kind of signal or alarm when the date changes and reopen then. </>


- David.Thompson1 at worldnet.att.net
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search log for string and display hourly/daily report spek06@gmail.com Python 4 01-24-2013 12:57 AM
splitting an XML file on the basis on basis of XML tags bijeshn@gmail.com Python 14 04-08-2008 04:26 AM
DHCP on a per-vlan basis? brut Cisco 3 01-09-2006 04:42 AM
Changing styles sheets on a per user basis =?Utf-8?B?VGVycnk=?= ASP .Net 2 02-04-2004 03:41 AM
sending an aspx report (or any web page) as an e-mail on periodic basis NoSf3RaTu ASP .Net 0 01-21-2004 03:25 PM



Advertisments