logfile.c 1.84 KB
Newer Older
1
/*  dvdisaster: Additional error correction for optical media.
2
 *  Copyright (C) 2004-2015 Carsten Gnoerlich.
3
 *
4 5 6 7 8 9
 *  Email: carsten@dvdisaster.org  -or-  cgnoerlich@fsfe.org
 *  Project homepage: http://www.dvdisaster.org
 *
 *  This file is part of dvdisaster.
 *
 *  dvdisaster is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation, either version 3 of the License, or
12 13
 *  (at your option) any later version.
 *
14
 *  dvdisaster is distributed in the hope that it will be useful,
15 16 17 18 19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
20
 *  along with dvdisaster. If not, see <http://www.gnu.org/licenses/>.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
 */

#include "dvdisaster.h"
#include <time.h>

/*
 * Create default dotfile path
 */

void DefaultLogFile()
{
   Closure->logFile = g_strdup_printf("%s/.dvdisaster.log", g_getenv("HOME"));
}

/*
 * Print time stamp to log file 
 */

void LogTimeStamp()
{  time_t now;

   if(!Closure->logFileEnabled)
      return;

   time(&now);
46 47
   PrintLogFile("*\n* %s\n* logging started at %s*\n",
		Closure->versionString, ctime(&now));
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
}


/* 
 * Print a message to the log file.
 * Tries hard to make the log messages survive a system crash.
 */

void VPrintLogFile(char *format, va_list argp)
{  FILE *file;

   if(!Closure->logFileStamped)
   {  Closure->logFileStamped = TRUE;
      LogTimeStamp();
   }

   file = fopen(Closure->logFile, "a");
   if(!file)
     return;

   g_vfprintf(file, format, argp);
   fflush(file);
   fclose(file);
}

void PrintLogFile(char *format, ...)
{  va_list argp;

   va_start(argp, format);
   VPrintLogFile(format, argp);
   va_end(argp);
}