ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/log.c
Revision: 5052
Committed: Mon Dec 22 11:56:03 2014 UTC (9 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 2148 byte(s)
Log Message:
- Initial import of bopm 3.1.3

File Contents

# User Rev Content
1 michael 5052 /* vim: set shiftwidth=3 softtabstop=3 expandtab: */
2    
3     /*
4     Copyright (C) 2002 Erik Fears
5    
6     This program is free software; you can redistribute it and/or
7     modify it under the terms of the GNU General Public License
8     as published by the Free Software Foundation; either version 2
9     of the License, or (at your option) any later version.
10    
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     GNU General Public License for more details.
15    
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to
18    
19     The Free Software Foundation, Inc.
20     59 Temple Place - Suite 330
21     Boston, MA 02111-1307, USA.
22    
23     */
24    
25     #include "setup.h"
26    
27     #include <stdio.h>
28     #include <errno.h>
29    
30     #ifdef STDC_HEADERS
31     #include <stdlib.h>
32     #include <stdarg.h>
33     #include <string.h>
34     #endif
35    
36     #include <time.h>
37    
38     #include "compat.h"
39     #include "config.h"
40     #include "extern.h"
41     #include "log.h"
42    
43    
44     FILE *logfile;
45     FILE *scanlogfile;
46    
47     void log_open(char *filename)
48     {
49     logfile = fopen(filename, "a");
50    
51     if(!logfile)
52     {
53     perror("Cannot open log file. Aborting.");
54     exit(EXIT_FAILURE);
55     }
56    
57     }
58    
59     void log_close(void)
60     {
61     fclose(logfile);
62     }
63    
64     void scanlog_open(char *filename)
65     {
66     scanlogfile = fopen(filename, "a");
67    
68     if(!scanlogfile)
69     {
70     log_printf("Failed to open scan log file: %s", strerror(errno));
71     }
72     }
73    
74     void scanlog_close(void)
75     {
76     if(scanlogfile)
77     fclose(scanlogfile);
78     }
79    
80     void log_printf(char *data, ...)
81     {
82     char data2[513];
83     char buf_present[25];
84     va_list arglist;
85     time_t present;
86     struct tm *tm_present;
87    
88     if(!OPT_DEBUG && !logfile)
89     return;
90    
91     time(&present);
92     tm_present = gmtime(&present);
93     strftime(buf_present, sizeof(buf_present), "%b %d %H:%M:%S %Y", tm_present);
94    
95     va_start(arglist, data);
96     vsnprintf(data2, 512, data, arglist);
97     va_end(arglist);
98    
99     if(OPT_DEBUG)
100     {
101     fprintf(stderr, "[%s] %s\n", buf_present, data2);
102     }
103     else
104     {
105     fprintf(logfile, "[%s] %s\n", buf_present, data2);
106     fflush(logfile);
107     }
108     }
109