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

Contents of /imapfilter/log.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show 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 #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 extern char logfile[PATH_MAX];
15
16 static FILE *logfp; /* Points to logfile. */
17
18
19 /*
20 * Prints message if in OPT_DETAILS_VERBOSE mode.
21 */
22 void verbose(const char *info, ...)
23 {
24 va_list args;
25
26 if (options & OPT_DETAILS_VERBOSE) {
27 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 if (logfile[0]) {
43 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 if (!(logfile[0]))
57 return 0; /* Logging not enabled. */
58
59 #ifdef DEBUG
60 printf("debug: logfile: %s\n", logfile);
61 #endif
62
63 logfp = fopen(logfile, "a");
64
65 if (!logfp) {
66 fprintf(stderr, "imapfilter: opening logfile %s: %s\n",
67 logfile, strerror(errno));
68 return 1;
69 }
70
71 return 0;
72 }
73
74
75 /*
76 * Closes the logfile.
77 */
78 int close_logfile(void)
79 {
80 if (!(logfile[0]))
81 return 0;
82 else
83 return fclose(logfp);
84 }
85
86
87 /*
88 * Writes information to logfile.
89 */
90 void log_info(const char *info, ...)
91 {
92 va_list args;
93
94 if (logfile[0]) {
95 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