Changeset 13 for trunk/txlib/txlogfil.c

Show
Ignore:
Timestamp:
05/13/06 20:33:09 (3 years ago)
Author:
jvw
Message:

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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/txlib/txlogfil.c

    r11 r13  
    3939#include <txlib.h> 
    4040 
    41 static  FILE          *log_handle = 0; 
    42 static  TXLN           log_fname; 
    43 static  BOOL           log_7bit   = TRUE; 
    44 static  BOOL           log_reopen = FALSE;      // reopen on each line 
     41static  FILE      *log_handle = 0; 
     42static  TXLN       log_fname   = "logfile"; 
     43static  BOOL       log_7bit    = TRUE; 
     44static  BOOL       log_reopen  = FALSE;         // reopen on each line 
    4545 
    4646/*****************************************************************************/ 
     
    4949BOOL TxAppendToLogFile                          // RET   logfile opened 
    5050( 
    51    char                *fname                   // IN    name of (new) logfile 
     51   char               *fname,                   // IN    name of (new) logfile 
     52   BOOL                verbose                  // IN    Show the action 
    5253) 
    5354{ 
    5455   if (log_handle != 0)                         // close old one 
    5556   { 
    56       TxPrint("Closing logfile   : '%s'\n", log_fname); 
     57      if (verbose) 
     58      { 
     59         TxPrint("Closing logfile   : '%s'\n", log_fname); 
     60      } 
    5761      fclose(log_handle); 
    5862      log_handle = 0; 
     
    6569         TxFnameExtension( log_fname, "log"); 
    6670      } 
    67       if ((log_handle = fopen(log_fname, "a" TXFMODE)) == 0) 
     71      if (((log_handle = fopen(log_fname, "a" TXFMODE)) == 0) && (verbose)) 
    6872      { 
    6973         TxPrint("Error opening log : '%s'\n", log_fname); 
     
    7276      { 
    7377         TxLogfileState( DEVICE_ON);            // always ON for new file 
    74          if (TxaOptUnSet('7'))                  // NO strip to 7-bit ASCII 
    75          { 
    76             log_7bit = FALSE; 
    77          } 
    78          if (TxaExeArgc() != 0)                 // Switches already parsed ? 
    79          {                                      // (-q = quiet switch to come) 
    80             TxPrint("Appending to log  : '%s' (%s-bit ASCII)\n", 
    81                       log_fname, (log_7bit) ? "7" : "8"); 
     78         if (verbose)                           // avoid any TxPrint when 
     79         {                                      // working in quiet mode 
     80            if (TxaOptUnSet('7'))               // NO strip to 7-bit ASCII 
     81            { 
     82               log_7bit = FALSE; 
     83            } 
     84            if (TxaExeArgc() != 0)              // Switches already parsed ? 
     85            {                                   // (-q = quiet switch to come) 
     86               TxPrint("Appending to log  : '%s' (%s-bit ASCII)\n", 
     87                         log_fname, (log_7bit) ? "7" : "8"); 
     88            } 
    8289         } 
    8390      } 
     
    148155/*---------------------------------------------------------------------------*/ 
    149156 
     157 
    150158/*****************************************************************************/ 
    151159// Get name for current logfile, if any 
     
    166174/*---------------------------------------------------------------------------*/ 
    167175 
     176 
     177/*****************************************************************************/ 
     178// Construct name for new logfile based upon a sequence number 0..n 
     179/*****************************************************************************/ 
     180char *TxBuildLogName                            // RET   filename or NULL 
     181( 
     182   ULONG               seq,                     // IN    sequence number 
     183   TXLN                buf                      // IN    filename buffer 
     184) 
     185{ 
     186   char               *rc = buf; 
     187   TXTS                ext; 
     188 
     189   if (seq == 0)                                // first will be .log 
     190   { 
     191      strcpy( ext, "log"); 
     192   } 
     193   else 
     194   { 
     195      sprintf( ext, "l%02lu", seq); 
     196   } 
     197   strcpy( rc, log_fname); 
     198 
     199   TxStripExtension( rc);                       // remove current extension 
     200   TxFnameExtension( rc, ext);                  // and add new one 
     201 
     202   return (rc); 
     203}                                               // end 'TxBuildLogName' 
     204/*---------------------------------------------------------------------------*/ 
     205