Changeset 13 for trunk/txlib/txcon.c


Ignore:
Timestamp:
May 13, 2006, 8:33:09 PM (19 years ago)
Author:
Jan van Wijk
Message:

Logfile size-limit and automatic logfile rotation, very useful for crash tracing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/txlib/txcon.c

    r11 r13  
    7575static  char  txc_ansi   = A_ON;
    7676
     77//- logfile cycling and size control
     78static  ULONG      log_written = 0;             // bytes written on this file
     79static  ULONG      log_maxsize = 0;             // maximum size per logfile
     80static  ULONG      log_seq_num = 0;             // sequence number 0..n
     81static  ULONG      log_retain  = 0;             // log recycle retain count
    7782
    7883//- Note: 256 color strings sorted in default PC order
     
    460465
    461466/*****************************************************************************/
     467// Set logfile maximum size per file
     468/*****************************************************************************/
     469void TxSetLogMaxSize
     470(
     471   ULONG               size                     // IN    maximum size, bytes
     472)
     473{
     474   log_maxsize = size;
     475}                                               // end 'TxSetLogMaxSize'
     476/*---------------------------------------------------------------------------*/
     477
     478
     479/*****************************************************************************/
     480// Set logfile number of files to retain on cycle, #files besides .log itself
     481/*****************************************************************************/
     482void TxSetLogRetain
     483(
     484   ULONG               retain                   // IN    retain count
     485)
     486{
     487   log_retain = retain;
     488}                                               // end 'TxSetLogRetain'
     489/*---------------------------------------------------------------------------*/
     490
     491
     492/*****************************************************************************/
    462493// printf-like print on stdout, LOG filehandle and raw/clean copy hooks
    463494/*****************************************************************************/
     
    528559               TxAscii827( txm_buff, TXASCII827_TRANS);
    529560            }
     561
     562            if ((log_maxsize > size) && (log_written > (log_maxsize - size)))
     563            {
     564               TXLN    fname;
     565
     566               log_written = 0;                 // avoid recursive cycling
     567               fprintf( log_handle, "\nClosing logfile at size limit\n");
     568
     569               TxAppendToLogFile( NULL, FALSE); // close current log, quiet
     570               if (log_seq_num >= log_retain)   // need to delete one
     571               {
     572                  TxBuildLogName( log_seq_num - log_retain, fname);
     573                  remove( fname);               // delete a logfile (cycle)
     574               }
     575               TxBuildLogName( (log_retain) ? ++log_seq_num : 0, fname);
     576               TxAppendToLogFile( fname, FALSE); // open next logfile, quiet
     577               log_handle  = TxQueryLogFile( &log7bit, &logreopen);
     578               fprintf( log_handle, "Start next logfile: '%s'\n", fname);
     579            }
     580            else
     581            {
     582               log_written += size;             // maintain total size in log
     583            }
     584
    530585            fprintf( log_handle, "%s", txm_buff);
    531586            if (logreopen)
Note: See TracChangeset for help on using the changeset viewer.