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

Annotation of /imapfilter/log.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations)
Sun Aug 26 20:02:53 2001 UTC (22 years, 7 months ago) by lefcha
Branch: MAIN
Changes since 1.7: +7 -7 lines
File MIME type: text/plain
More effective logfile's existence checking.

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 lefcha 1.5 extern char logfile[PATH_MAX];
14 lefcha 1.8 extern unsigned int options;
15 lefcha 1.6
16 lefcha 1.8 static FILE *logfp = NULL; /* Points to logfile. */
17 lefcha 1.1
18    
19     /*
20 lefcha 1.7 * Prints message if not in OPT_DETAILS_QUITE mode.
21     */
22     void info(const char *info, ...)
23     {
24     va_list args;
25 lefcha 1.8
26 lefcha 1.7 if (!(options & OPT_DETAILS_QUITE)) {
27     va_start(args, info);
28     vprintf(info, args);
29     va_end(args);
30     }
31     }
32    
33    
34     /*
35 lefcha 1.6 * Prints message if in OPT_DETAILS_VERBOSE mode.
36 lefcha 1.1 */
37     void verbose(const char *info, ...)
38     {
39     va_list args;
40    
41 lefcha 1.6 if (options & OPT_DETAILS_VERBOSE) {
42 lefcha 1.1 va_start(args, info);
43     vprintf(info, args);
44     va_end(args);
45     }
46     }
47    
48     /*
49     * Prints error message and writes it into logfile.
50     */
51     void error(const char *errmsg, ...)
52     {
53     va_list args;
54    
55     va_start(args, errmsg);
56    
57 lefcha 1.8 if (logfp) {
58 lefcha 1.1 vfprintf(logfp, errmsg, args);
59     }
60    
61     vfprintf(stderr, errmsg, args);
62     va_end(args);
63     }
64    
65    
66     /*
67     * Opens the file to save logging information.
68     */
69     int open_logfile(void)
70     {
71 lefcha 1.5 if (!(logfile[0]))
72 lefcha 1.6 return 0; /* Logging not enabled. */
73 lefcha 1.4
74 lefcha 1.1 #ifdef DEBUG
75 lefcha 1.8 printf("debug: logfile: '%s'\n", logfile);
76 lefcha 1.1 #endif
77    
78 lefcha 1.5 logfp = fopen(logfile, "a");
79 lefcha 1.1
80     if (!logfp) {
81     fprintf(stderr, "imapfilter: opening logfile %s: %s\n",
82 lefcha 1.5 logfile, strerror(errno));
83 lefcha 1.6 return 1;
84 lefcha 1.1 }
85    
86 lefcha 1.6 return 0;
87 lefcha 1.1 }
88    
89    
90     /*
91     * Closes the logfile.
92     */
93     int close_logfile(void)
94     {
95 lefcha 1.8 if (!logfp)
96 lefcha 1.6 return 0;
97 lefcha 1.1 else
98     return fclose(logfp);
99     }
100    
101    
102 lefcha 1.2 /*
103     * Writes information to logfile.
104     */
105 lefcha 1.1 void log_info(const char *info, ...)
106     {
107     va_list args;
108    
109 lefcha 1.8 if (logfp) {
110 lefcha 1.1 va_start(args, info);
111     vfprintf(logfp, info, args);
112     va_end(args);
113     }
114     }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26