| 1 |
/* |
| 2 |
* Copyright (c) 2002 Erik Fears |
| 3 |
* Copyright (c) 2014-2019 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 |
|
| 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 |
#include "main.h" |
| 32 |
#include "misc.h" |
| 33 |
|
| 34 |
|
| 35 |
FILE *logfile; |
| 36 |
FILE *scanlogfile; |
| 37 |
|
| 38 |
void |
| 39 |
log_open(const char *filename) |
| 40 |
{ |
| 41 |
logfile = fopen(filename, "a"); |
| 42 |
|
| 43 |
if (logfile == NULL) |
| 44 |
{ |
| 45 |
perror("Cannot open log file. Aborting."); |
| 46 |
exit(EXIT_FAILURE); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
void |
| 51 |
log_close(void) |
| 52 |
{ |
| 53 |
fclose(logfile); |
| 54 |
} |
| 55 |
|
| 56 |
void |
| 57 |
scanlog_open(const char *filename) |
| 58 |
{ |
| 59 |
scanlogfile = fopen(filename, "a"); |
| 60 |
|
| 61 |
if (scanlogfile == NULL) |
| 62 |
log_printf("Failed to open scan log file: %s", strerror(errno)); |
| 63 |
} |
| 64 |
|
| 65 |
void |
| 66 |
scanlog_close(void) |
| 67 |
{ |
| 68 |
if (scanlogfile) |
| 69 |
fclose(scanlogfile); |
| 70 |
} |
| 71 |
|
| 72 |
void |
| 73 |
log_printf(const char *fmt, ...) |
| 74 |
{ |
| 75 |
char buf[LOG_BUFSIZE]; |
| 76 |
va_list args; |
| 77 |
|
| 78 |
if (OPT_DEBUG == 0 && logfile == NULL) |
| 79 |
return; |
| 80 |
|
| 81 |
va_start(args, fmt); |
| 82 |
vsnprintf(buf, sizeof(buf), fmt, args); |
| 83 |
va_end(args); |
| 84 |
|
| 85 |
if (OPT_DEBUG) |
| 86 |
fprintf(stderr, "[%s] %s\n", date_iso8601(0), buf); |
| 87 |
else |
| 88 |
{ |
| 89 |
fprintf(logfile, "[%s] %s\n", date_iso8601(0), buf); |
| 90 |
fflush(logfile); |
| 91 |
} |
| 92 |
} |