ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/log.c
Revision: 8184
Committed: Thu Apr 13 20:00:32 2017 UTC (8 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 1905 byte(s)
Log Message:
- Sort out unused header includes

File Contents

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

Properties

Name Value
svn:eol-style native
svn:keywords Id