ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/log.c
Revision: 5647
Committed: Sun Mar 8 13:15:45 2015 UTC (11 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 2142 byte(s)
Log Message:
- log.c, log.h: constification

File Contents

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

Properties

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