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)
39 /* backup old logfile if existing */
40 if (is_file_exist(filename)) {
43 backupname = g_strconcat(filename, ".bak", NULL);
44 if (rename(filename, backupname) < 0)
45 FILE_OP_ERROR(filename, "rename");
49 log_fp = fopen(filename, "wb");
51 FILE_OP_ERROR(filename, "fopen");
54 void close_log_file(void)
62 static guint log_verbosity_count = 0;
64 void log_verbosity_set(gboolean verbose)
67 log_verbosity_count++;
68 else if (log_verbosity_count > 0)
69 log_verbosity_count--;
74 void log_print(const gchar *format, ...)
77 gchar buf[BUFFSIZE + TIME_LEN];
82 strftime(buf, TIME_LEN + 1, "[%H:%M:%S] ", localtime(&t));
84 va_start(args, format);
85 g_vsnprintf(buf + TIME_LEN, BUFFSIZE, format, args);
88 if (debug_get_mode()) fputs(buf, stdout);
90 logtext.type = LOG_NORMAL;
91 hooks_invoke(LOG_APPEND_TEXT_HOOKLIST, &logtext);
97 logtext.text = buf + TIME_LEN;
98 if (log_verbosity_count)
99 hooks_invoke(STATUSBAR_PUTS_ALL_HOOKLIST, &logtext);
102 void log_message(const gchar *format, ...)
105 gchar buf[BUFFSIZE + TIME_LEN];
110 strftime(buf, TIME_LEN + 1, "[%H:%M:%S] ", localtime(&t));
112 va_start(args, format);
113 g_vsnprintf(buf + TIME_LEN, BUFFSIZE, format, args);
116 if (debug_get_mode()) g_message("%s", buf + TIME_LEN);
117 logtext.text = buf + TIME_LEN;
118 logtext.type = LOG_MSG;
119 hooks_invoke(LOG_APPEND_TEXT_HOOKLIST, &logtext);
121 fwrite(buf, TIME_LEN, 1, log_fp);
122 fputs("* message: ", log_fp);
123 fputs(buf + TIME_LEN, log_fp);
127 logtext.text = buf + TIME_LEN;
128 hooks_invoke(STATUSBAR_PUTS_ALL_HOOKLIST, &logtext);
131 void log_warning(const gchar *format, ...)
134 gchar buf[BUFFSIZE + TIME_LEN];
139 strftime(buf, TIME_LEN + 1, "[%H:%M:%S] ", localtime(&t));
141 va_start(args, format);
142 g_vsnprintf(buf + TIME_LEN, BUFFSIZE, format, args);
145 g_warning("%s", buf);
146 logtext.text = buf + TIME_LEN;
147 logtext.type = LOG_WARN;
148 hooks_invoke(LOG_APPEND_TEXT_HOOKLIST, &logtext);
150 fwrite(buf, TIME_LEN, 1, log_fp);
151 fputs("** warning: ", log_fp);
152 fputs(buf + TIME_LEN, log_fp);
157 void log_error(const gchar *format, ...)
160 gchar buf[BUFFSIZE + TIME_LEN];
165 strftime(buf, TIME_LEN + 1, "[%H:%M:%S] ", localtime(&t));
167 va_start(args, format);
168 g_vsnprintf(buf + TIME_LEN, BUFFSIZE, format, args);
171 g_warning("%s", buf);
172 logtext.text = buf + TIME_LEN;
173 logtext.type = LOG_ERROR;
174 hooks_invoke(LOG_APPEND_TEXT_HOOKLIST, &logtext);
176 fwrite(buf, TIME_LEN, 1, log_fp);
177 fputs("*** error: ", log_fp);
178 fputs(buf + TIME_LEN, log_fp);