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 "compat.h" |
31 |
|
|
#include "config.h" |
32 |
|
|
#include "log.h" |
33 |
michael |
5207 |
#include "main.h" |
34 |
michael |
5052 |
|
35 |
|
|
|
36 |
|
|
FILE *logfile; |
37 |
|
|
FILE *scanlogfile; |
38 |
|
|
|
39 |
michael |
5357 |
void |
40 |
michael |
5647 |
log_open(const char *filename) |
41 |
michael |
5052 |
{ |
42 |
michael |
5357 |
logfile = fopen(filename, "a"); |
43 |
michael |
5052 |
|
44 |
michael |
5357 |
if (logfile == NULL) |
45 |
|
|
{ |
46 |
|
|
perror("Cannot open log file. Aborting."); |
47 |
|
|
exit(EXIT_FAILURE); |
48 |
|
|
} |
49 |
michael |
5052 |
} |
50 |
|
|
|
51 |
michael |
5357 |
void |
52 |
|
|
log_close(void) |
53 |
michael |
5052 |
{ |
54 |
michael |
5357 |
fclose(logfile); |
55 |
michael |
5052 |
} |
56 |
|
|
|
57 |
michael |
5357 |
void |
58 |
michael |
5647 |
scanlog_open(const char *filename) |
59 |
michael |
5052 |
{ |
60 |
michael |
5357 |
scanlogfile = fopen(filename, "a"); |
61 |
michael |
5052 |
|
62 |
michael |
5357 |
if (scanlogfile == NULL) |
63 |
|
|
log_printf("Failed to open scan log file: %s", strerror(errno)); |
64 |
michael |
5052 |
} |
65 |
|
|
|
66 |
michael |
5357 |
void |
67 |
|
|
scanlog_close(void) |
68 |
michael |
5052 |
{ |
69 |
michael |
5357 |
if (scanlogfile) |
70 |
|
|
fclose(scanlogfile); |
71 |
michael |
5052 |
} |
72 |
|
|
|
73 |
michael |
5357 |
void |
74 |
|
|
log_printf(const char *data, ...) |
75 |
michael |
5052 |
{ |
76 |
michael |
5357 |
char data2[513]; |
77 |
michael |
5662 |
char buf_present[32]; |
78 |
michael |
5357 |
va_list arglist; |
79 |
michael |
5659 |
time_t present = 0; |
80 |
michael |
5052 |
|
81 |
michael |
5357 |
if (OPT_DEBUG == 0 && logfile == NULL) |
82 |
|
|
return; |
83 |
michael |
5052 |
|
84 |
michael |
5357 |
time(&present); |
85 |
michael |
5659 |
strftime(buf_present, sizeof(buf_present), "%FT%H:%M:%S%z", localtime(&present)); |
86 |
michael |
5052 |
|
87 |
michael |
5357 |
va_start(arglist, data); |
88 |
|
|
vsnprintf(data2, 512, data, arglist); |
89 |
|
|
va_end(arglist); |
90 |
michael |
5052 |
|
91 |
michael |
5357 |
if (OPT_DEBUG) |
92 |
|
|
fprintf(stderr, "[%s] %s\n", buf_present, data2); |
93 |
|
|
else |
94 |
|
|
{ |
95 |
|
|
fprintf(logfile, "[%s] %s\n", buf_present, data2); |
96 |
|
|
fflush(logfile); |
97 |
|
|
} |
98 |
michael |
5052 |
} |