/[svn]/hopm/trunk/src/log.c
ViewVC logotype

Contents of /hopm/trunk/src/log.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5137 - (show annotations)
Thu Dec 25 19:36:37 2014 UTC (7 years, 7 months ago) by michael
File MIME type: text/x-chdr
File size: 2099 byte(s)
- Removed vim settings from the source files

1 /*
2 Copyright (C) 2002 Erik Fears
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to
16
17 The Free Software Foundation, Inc.
18 59 Temple Place - Suite 330
19 Boston, MA 02111-1307, USA.
20
21 */
22
23 #include "setup.h"
24
25 #include <stdio.h>
26 #include <errno.h>
27
28 #ifdef STDC_HEADERS
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <string.h>
32 #endif
33
34 #include <time.h>
35
36 #include "compat.h"
37 #include "config.h"
38 #include "extern.h"
39 #include "log.h"
40
41
42 FILE *logfile;
43 FILE *scanlogfile;
44
45 void log_open(char *filename)
46 {
47 logfile = fopen(filename, "a");
48
49 if(!logfile)
50 {
51 perror("Cannot open log file. Aborting.");
52 exit(EXIT_FAILURE);
53 }
54
55 }
56
57 void log_close(void)
58 {
59 fclose(logfile);
60 }
61
62 void scanlog_open(char *filename)
63 {
64 scanlogfile = fopen(filename, "a");
65
66 if(!scanlogfile)
67 {
68 log_printf("Failed to open scan log file: %s", strerror(errno));
69 }
70 }
71
72 void scanlog_close(void)
73 {
74 if(scanlogfile)
75 fclose(scanlogfile);
76 }
77
78 void log_printf(const char *data, ...)
79 {
80 char data2[513];
81 char buf_present[25];
82 va_list arglist;
83 time_t present;
84 struct tm *tm_present;
85
86 if(!OPT_DEBUG && !logfile)
87 return;
88
89 time(&present);
90 tm_present = gmtime(&present);
91 strftime(buf_present, sizeof(buf_present), "%b %d %H:%M:%S %Y", tm_present);
92
93 va_start(arglist, data);
94 vsnprintf(data2, 512, data, arglist);
95 va_end(arglist);
96
97 if(OPT_DEBUG)
98 {
99 fprintf(stderr, "[%s] %s\n", buf_present, data2);
100 }
101 else
102 {
103 fprintf(logfile, "[%s] %s\n", buf_present, data2);
104 fflush(logfile);
105 }
106 }
107

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28