ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/log.c
Revision: 5351
Committed: Sun Jan 11 13:24:19 2015 UTC (10 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 2162 byte(s)
Log Message:
- Update license headers

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

Properties

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