/[imapfilter]/imapfilter/log.c
ViewVC logotype

Annotation of /imapfilter/log.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations)
Sun Aug 26 01:18:24 2001 UTC (22 years, 7 months ago) by lefcha
Branch: MAIN
Changes since 1.5: +7 -6 lines
File MIME type: text/plain
Structural changes

1 lefcha 1.1 #include <stdio.h>
2     #include <stdlib.h>
3     #include <errno.h>
4     #include <string.h>
5     #include <stdarg.h>
6     #include <limits.h>
7    
8     #include "config.h"
9     #include "imapfilter.h"
10     #include "log.h"
11    
12    
13     extern int options;
14 lefcha 1.5 extern char logfile[PATH_MAX];
15 lefcha 1.6
16 lefcha 1.1 static FILE *logfp; /* Points to logfile. */
17    
18    
19     /*
20 lefcha 1.6 * Prints message if in OPT_DETAILS_VERBOSE mode.
21 lefcha 1.1 */
22     void verbose(const char *info, ...)
23     {
24     va_list args;
25    
26 lefcha 1.6 if (options & OPT_DETAILS_VERBOSE) {
27 lefcha 1.1 va_start(args, info);
28     vprintf(info, args);
29     va_end(args);
30     }
31     }
32    
33     /*
34     * Prints error message and writes it into logfile.
35     */
36     void error(const char *errmsg, ...)
37     {
38     va_list args;
39    
40     va_start(args, errmsg);
41    
42 lefcha 1.5 if (logfile[0]) {
43 lefcha 1.1 vfprintf(logfp, errmsg, args);
44     }
45    
46     vfprintf(stderr, errmsg, args);
47     va_end(args);
48     }
49    
50    
51     /*
52     * Opens the file to save logging information.
53     */
54     int open_logfile(void)
55     {
56 lefcha 1.5 if (!(logfile[0]))
57 lefcha 1.6 return 0; /* Logging not enabled. */
58 lefcha 1.4
59 lefcha 1.1 #ifdef DEBUG
60 lefcha 1.5 printf("debug: logfile: %s\n", logfile);
61 lefcha 1.1 #endif
62    
63 lefcha 1.5 logfp = fopen(logfile, "a");
64 lefcha 1.1
65     if (!logfp) {
66     fprintf(stderr, "imapfilter: opening logfile %s: %s\n",
67 lefcha 1.5 logfile, strerror(errno));
68 lefcha 1.6 return 1;
69 lefcha 1.1 }
70    
71 lefcha 1.6 return 0;
72 lefcha 1.1 }
73    
74    
75     /*
76     * Closes the logfile.
77     */
78     int close_logfile(void)
79     {
80 lefcha 1.5 if (!(logfile[0]))
81 lefcha 1.6 return 0;
82 lefcha 1.1 else
83     return fclose(logfp);
84     }
85    
86    
87 lefcha 1.2 /*
88     * Writes information to logfile.
89     */
90 lefcha 1.1 void log_info(const char *info, ...)
91     {
92     va_list args;
93    
94 lefcha 1.5 if (logfile[0]) {
95 lefcha 1.1 va_start(args, info);
96     vfprintf(logfp, info, args);
97     va_end(args);
98     }
99     }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26