Creating a log on daily basis

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • abhi147@gmail.com

    Creating a log on daily basis

    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_fil e, "%s.log", "sample");
    fp_stdout = fopen(log_file, "a");

    Thanks for your help !

  • mdler

    #2
    Re: Creating a log on daily basis

    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",t ijd2->tm_year+1900,t ijd2->tm_mon,tijd2->tm_mday);
    return (ULong)atol(tij da);
    }

    {
    char log_file[80];
    FILE *fp_stdout=NULL ;
    sprintf(log_fil e, "%s_%08d.lo g", "sample",today( ));
    fp_stdout = fopen(log_file, "a");
    }


    now every day there is a new logfile name created

    today it should be 'sample_2006090 8.log'

    Greetings Olaf

    abhi147@gmail.c om 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_fil e, "%s.log", "sample");
    fp_stdout = fopen(log_file, "a");
    >
    Thanks for your help !

    Comment

    • abhi147@gmail.com

      #3
      Re: Creating a log on daily basis


      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",t ijd2->tm_year+1900,t ijd2->tm_mon,tijd2->tm_mday);
      return (ULong)atol(tij da);
      }
      >
      {
      char log_file[80];
      FILE *fp_stdout=NULL ;
      sprintf(log_fil e, "%s_%08d.lo g", "sample",today( ));
      fp_stdout = fopen(log_file, "a");
      }
      >
      >
      now every day there is a new logfile name created
      >
      today it should be 'sample_2006090 8.log'
      >
      Greetings Olaf
      >
      abhi147@gmail.c om 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_fil e, "%s.log", "sample");
      fp_stdout = fopen(log_file, "a");

      Thanks for your help !

      Thanks a lot :- )

      Comment

      • Dave Thompson

        #4
        Re: Creating a log on daily basis

        On 8 Sep 2006 02:37:20 -0700, "mdler" <olaf.giezenaar @gmail.com>
        wrote:
        (topposting fixed)
        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",t ijd2->tm_year+1900,t ijd2->tm_mon,tijd2->tm_mday);
        return (ULong)atol(tij da);
        Or to avoid the useless conversions, just
        return (long)(t->tm_year+1900)* 10000L + t->mon*100 + t->tm_mday;
        /* or t->tm_year*1000 0L + 19000000 + ...
        }
        >
        {
        char log_file[80];
        FILE *fp_stdout=NULL ;
        sprintf(log_fil e, "%s_%08d.lo g", "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.ne t

        Comment

        Working...