2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 Hiroyuki Yamamoto
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 static FILE *log_fp = NULL;
34 void set_log_file(const gchar *filename)
37 log_fp = fopen(filename, "wb");
39 FILE_OP_ERROR(filename, "fopen");
42 void close_log_file(void)
50 static guint log_verbosity_count = 0;
52 void log_verbosity_set(gboolean verbose)
55 log_verbosity_count++;
56 else if (log_verbosity_count > 0)
57 log_verbosity_count--;
62 void log_print(const gchar *format, ...)
65 gchar buf[BUFFSIZE + TIME_LEN];
70 strftime(buf, TIME_LEN + 1, "[%H:%M:%S] ", localtime(&t));
72 va_start(args, format);
73 g_vsnprintf(buf + TIME_LEN, BUFFSIZE, format, args);
76 if (debug_get_mode()) fputs(buf, stdout);
78 logtext.type = LOG_NORMAL;
79 hooks_invoke(LOG_APPEND_TEXT_HOOKLIST, &logtext);
85 callback for gui logging
87 if (log_verbosity_count)
88 statusbar_puts_all(buf + TIME_LEN); */
91 void log_message(const gchar *format, ...)
94 gchar buf[BUFFSIZE + TIME_LEN];
99 strftime(buf, TIME_LEN + 1, "[%H:%M:%S] ", localtime(&t));
101 va_start(args, format);
102 g_vsnprintf(buf + TIME_LEN, BUFFSIZE, format, args);
105 if (debug_get_mode()) g_message("%s", buf + TIME_LEN);
106 logtext.text = buf + TIME_LEN;
107 logtext.type = LOG_MSG;
108 hooks_invoke(LOG_APPEND_TEXT_HOOKLIST, &logtext);
110 fwrite(buf, TIME_LEN, 1, log_fp);
111 fputs("* message: ", log_fp);
112 fputs(buf + TIME_LEN, log_fp);
116 callback for gui logging
118 statusbar_puts_all(buf + TIME_LEN); */
121 void log_warning(const gchar *format, ...)
124 gchar buf[BUFFSIZE + TIME_LEN];
129 strftime(buf, TIME_LEN + 1, "[%H:%M:%S] ", localtime(&t));
131 va_start(args, format);
132 g_vsnprintf(buf + TIME_LEN, BUFFSIZE, format, args);
135 g_warning("%s", buf);
136 logtext.text = buf + TIME_LEN;
137 logtext.type = LOG_WARN;
138 hooks_invoke(LOG_APPEND_TEXT_HOOKLIST, &logtext);
140 fwrite(buf, TIME_LEN, 1, log_fp);
141 fputs("** warning: ", log_fp);
142 fputs(buf + TIME_LEN, log_fp);
147 void log_error(const gchar *format, ...)
150 gchar buf[BUFFSIZE + TIME_LEN];
155 strftime(buf, TIME_LEN + 1, "[%H:%M:%S] ", localtime(&t));
157 va_start(args, format);
158 g_vsnprintf(buf + TIME_LEN, BUFFSIZE, format, args);
161 g_warning("%s", buf);
162 logtext.text = buf + TIME_LEN;
163 logtext.type = LOG_ERROR;
164 hooks_invoke(LOG_APPEND_TEXT_HOOKLIST, &logtext);
166 fwrite(buf, TIME_LEN, 1, log_fp);
167 fputs("*** error: ", log_fp);
168 fputs(buf + TIME_LEN, log_fp);