Return to Snippet

Revision: 25057
at March 18, 2010 16:03 by deepsoul


Initial Code
FILE *log= NULL;

int printflog( const char *format, ... )
{
  va_list arglist;
  int ret;

  va_start(arglist, format);
  ret= vprintf(format, arglist);
  if( log )
    vfprintf(log, format, arglist);
  return ret;
}

int fprintflog( FILE *stream, const char *format, ... )
{
  va_list arglist;
  int ret;

  va_start(arglist, format);
  ret= vfprintf(stream, format, arglist);
  if( log )
    vfprintf(log, format, arglist);
  return ret;
}

Initial URL

                                

Initial Description
With the code fragment below, you can easily add output logging to a text-based program.  Add the functions, open the log file and replace calls to (f)printf by (f)printflog.

Initial Title
Log all output to file

Initial Tags

                                

Initial Language
C