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

Contents of /imapfilter/log.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Sun Aug 12 16:06:45 2001 UTC (22 years, 8 months ago) by lefcha
Branch: MAIN
Changes since 1.2: +6 -14 lines
File MIME type: text/plain
Merged small changes from v0.1.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 extern account_data account;
15 static FILE *logfp; /* Points to logfile. */
16
17
18 /*
19 * Print message if in OPTION_DETAILS_VERBOSE mode.
20 */
21 void verbose(const char *info, ...)
22 {
23 va_list args;
24
25 if (options & OPTION_DETAILS_VERBOSE) {
26 va_start(args, info);
27 vprintf(info, args);
28 va_end(args);
29 }
30 }
31
32 /*
33 * Prints error message and writes it into logfile.
34 */
35 void error(const char *errmsg, ...)
36 {
37 va_list args;
38
39 va_start(args, errmsg);
40
41 if (account.logfile[0]) {
42 vfprintf(logfp, errmsg, args);
43 }
44
45 vfprintf(stderr, errmsg, args);
46 va_end(args);
47 }
48
49
50 /*
51 * Opens the file to save logging information.
52 */
53 int open_logfile(void)
54 {
55 if (!(account.logfile[0]))
56 return SUCCESS; /* Logging not enabled. */
57
58 #ifdef DEBUG
59 printf("debug: logfile: %s\n", account.logfile);
60 #endif
61
62 logfp = fopen(account.logfile, "a");
63
64 if (!logfp) {
65 fprintf(stderr, "imapfilter: opening logfile %s: %s\n",
66 account.logfile, strerror(errno));
67 return FAILURE;
68 }
69
70 return SUCCESS;
71 }
72
73
74 /*
75 * Closes the logfile.
76 */
77 int close_logfile(void)
78 {
79 if (!(account.logfile[0]))
80 return SUCCESS;
81 else
82 return fclose(logfp);
83 }
84
85
86 /*
87 * Writes information to logfile.
88 */
89 void log_info(const char *info, ...)
90 {
91 va_list args;
92
93 if (account.logfile[0]) {
94 va_start(args, info);
95 vfprintf(logfp, info, args);
96 va_end(args);
97 }
98 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26