ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/log.c
Revision: 6035
Committed: Wed Jun 3 16:41:02 2015 UTC (10 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 2053 byte(s)
Log Message:
- log.c: remove header includes we don't need

File Contents

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

Properties

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