1 |
michael |
5052 |
/* |
2 |
michael |
5351 |
* Copyright (c) 2002 Erik Fears |
3 |
|
|
* Copyright (c) 2014-2015 ircd-hybrid development team |
4 |
|
|
* |
5 |
|
|
* This program is free software; you can redistribute it and/or modify |
6 |
|
|
* it under the terms of the GNU General Public License as published by |
7 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
8 |
|
|
* (at your option) any later version. |
9 |
|
|
* |
10 |
|
|
* This program is distributed in the hope that it will be useful, |
11 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
* GNU General Public License for more details. |
14 |
|
|
* |
15 |
|
|
* You should have received a copy of the GNU General Public License |
16 |
|
|
* along with this program; if not, write to the Free Software |
17 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
18 |
|
|
* USA |
19 |
|
|
*/ |
20 |
michael |
5052 |
|
21 |
|
|
#include "setup.h" |
22 |
|
|
|
23 |
|
|
#include <stdio.h> |
24 |
|
|
#include <errno.h> |
25 |
|
|
#include <stdlib.h> |
26 |
|
|
#include <stdarg.h> |
27 |
|
|
#include <string.h> |
28 |
|
|
#include <time.h> |
29 |
|
|
|
30 |
|
|
#include "log.h" |
31 |
michael |
5207 |
#include "main.h" |
32 |
michael |
6970 |
#include "misc.h" |
33 |
michael |
5052 |
|
34 |
|
|
|
35 |
|
|
FILE *logfile; |
36 |
|
|
FILE *scanlogfile; |
37 |
|
|
|
38 |
michael |
5357 |
void |
39 |
michael |
5647 |
log_open(const char *filename) |
40 |
michael |
5052 |
{ |
41 |
michael |
5357 |
logfile = fopen(filename, "a"); |
42 |
michael |
5052 |
|
43 |
michael |
5357 |
if (logfile == NULL) |
44 |
|
|
{ |
45 |
|
|
perror("Cannot open log file. Aborting."); |
46 |
|
|
exit(EXIT_FAILURE); |
47 |
|
|
} |
48 |
michael |
5052 |
} |
49 |
|
|
|
50 |
michael |
5357 |
void |
51 |
|
|
log_close(void) |
52 |
michael |
5052 |
{ |
53 |
michael |
5357 |
fclose(logfile); |
54 |
michael |
5052 |
} |
55 |
|
|
|
56 |
michael |
5357 |
void |
57 |
michael |
5647 |
scanlog_open(const char *filename) |
58 |
michael |
5052 |
{ |
59 |
michael |
5357 |
scanlogfile = fopen(filename, "a"); |
60 |
michael |
5052 |
|
61 |
michael |
5357 |
if (scanlogfile == NULL) |
62 |
|
|
log_printf("Failed to open scan log file: %s", strerror(errno)); |
63 |
michael |
5052 |
} |
64 |
|
|
|
65 |
michael |
5357 |
void |
66 |
|
|
scanlog_close(void) |
67 |
michael |
5052 |
{ |
68 |
michael |
5357 |
if (scanlogfile) |
69 |
|
|
fclose(scanlogfile); |
70 |
michael |
5052 |
} |
71 |
|
|
|
72 |
michael |
5357 |
void |
73 |
michael |
6972 |
log_printf(const char *fmt, ...) |
74 |
michael |
5052 |
{ |
75 |
michael |
6974 |
char buf[LOG_BUFSIZE]; |
76 |
michael |
6972 |
va_list args; |
77 |
michael |
5052 |
|
78 |
michael |
5357 |
if (OPT_DEBUG == 0 && logfile == NULL) |
79 |
|
|
return; |
80 |
michael |
5052 |
|
81 |
michael |
6972 |
va_start(args, fmt); |
82 |
|
|
vsnprintf(buf, sizeof(buf), fmt, args); |
83 |
|
|
va_end(args); |
84 |
michael |
5052 |
|
85 |
michael |
5357 |
if (OPT_DEBUG) |
86 |
michael |
6972 |
fprintf(stderr, "[%s] %s\n", date_iso8601(0), buf); |
87 |
michael |
5357 |
else |
88 |
|
|
{ |
89 |
michael |
6972 |
fprintf(logfile, "[%s] %s\n", date_iso8601(0), buf); |
90 |
michael |
5357 |
fflush(logfile); |
91 |
|
|
} |
92 |
michael |
5052 |
} |