File: log.c

package info (click to toggle)
bopm 3.1.2-12
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,964 kB
  • ctags: 1,345
  • sloc: ansic: 8,611; sh: 7,456; yacc: 461; perl: 429; lex: 232; makefile: 124; php: 64
file content (109 lines) | stat: -rw-r--r-- 2,148 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
46
47
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* vim: set shiftwidth=3 softtabstop=3 expandtab: */ 

/*
Copyright (C) 2002  Erik Fears
 
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
 
This program is distributed in the hope that it will be useful,
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
along with this program; if not, write to

      The Free Software Foundation, Inc.
      59 Temple Place - Suite 330
      Boston, MA  02111-1307, USA.
 
*/

#include "setup.h"

#include <stdio.h>
#include <errno.h>

#ifdef STDC_HEADERS
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#endif

#include <time.h>

#include "compat.h"
#include "config.h"
#include "extern.h"
#include "log.h"


FILE *logfile;
FILE *scanlogfile;

void log_open(char *filename)
{
   logfile = fopen(filename, "a");

   if(!logfile)
   {
      perror("Cannot open log file. Aborting.");
      exit(EXIT_FAILURE);
   }

}

void log_close(void)
{
   fclose(logfile);
}

void scanlog_open(char *filename)
{
   scanlogfile = fopen(filename, "a");

   if(!scanlogfile)
   {
      log_printf("Failed to open scan log file: %s", strerror(errno));
   }
}

void scanlog_close(void)
{
   if(scanlogfile)
      fclose(scanlogfile);
}

void log_printf(char *data, ...)
{
   char data2[513];
   char buf_present[25];
   va_list arglist;
   time_t present;
   struct tm *tm_present;

   if(!OPT_DEBUG && !logfile)
      return;

   time(&present);
   tm_present = gmtime(&present);
   strftime(buf_present, sizeof(buf_present), "%b %d %H:%M:%S %Y", tm_present);

   va_start(arglist, data);
   vsnprintf(data2, 512, data, arglist);
   va_end(arglist);

   if(OPT_DEBUG)
   {
      fprintf(stderr, "[%s] %s\n", buf_present, data2);
   }
   else
   {
      fprintf(logfile, "[%s] %s\n", buf_present, data2);
      fflush(logfile);
   }
}