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 void log_print(const gchar *format, ...)
65 gchar buf[BUFFSIZE + LOG_TIME_LEN];
70 strftime(buf, LOG_TIME_LEN + 1, "[%H:%M:%S] ", localtime(&t));
72 va_start(args, format);
73 g_vsnprintf(buf + LOG_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);
86 void log_message(const gchar *format, ...)
89 gchar buf[BUFFSIZE + LOG_TIME_LEN];
94 strftime(buf, LOG_TIME_LEN + 1, "[%H:%M:%S] ", localtime(&t));
96 va_start(args, format);
97 g_vsnprintf(buf + LOG_TIME_LEN, BUFFSIZE, format, args);
100 if (debug_get_mode()) g_message("%s", buf + LOG_TIME_LEN);
101 logtext.text = buf + LOG_TIME_LEN;
102 logtext.type = LOG_MSG;
103 hooks_invoke(LOG_APPEND_TEXT_HOOKLIST, &logtext);
105 fwrite(buf, LOG_TIME_LEN, 1, log_fp);
106 fputs("* message: ", log_fp);
107 fputs(buf + LOG_TIME_LEN, log_fp);
112 void log_warning(const gchar *format, ...)
115 gchar buf[BUFFSIZE + LOG_TIME_LEN];
120 strftime(buf, LOG_TIME_LEN + 1, "[%H:%M:%S] ", localtime(&t));
122 va_start(args, format);
123 g_vsnprintf(buf + LOG_TIME_LEN, BUFFSIZE, format, args);
126 g_warning("%s", buf);
127 logtext.text = buf + LOG_TIME_LEN;
128 logtext.type = LOG_WARN;
129 hooks_invoke(LOG_APPEND_TEXT_HOOKLIST, &logtext);
131 fwrite(buf, LOG_TIME_LEN, 1, log_fp);
132 fputs("** warning: ", log_fp);
133 fputs(buf + LOG_TIME_LEN, log_fp);
138 void log_error(const gchar *format, ...)
141 gchar buf[BUFFSIZE + LOG_TIME_LEN];
146 strftime(buf, LOG_TIME_LEN + 1, "[%H:%M:%S] ", localtime(&t));
148 va_start(args, format);
149 g_vsnprintf(buf + LOG_TIME_LEN, BUFFSIZE, format, args);
152 g_warning("%s", buf);
153 logtext.text = buf + LOG_TIME_LEN;
154 logtext.type = LOG_ERROR;
155 hooks_invoke(LOG_APPEND_TEXT_HOOKLIST, &logtext);
157 fwrite(buf, LOG_TIME_LEN, 1, log_fp);
158 fputs("*** error: ", log_fp);
159 fputs(buf + LOG_TIME_LEN, log_fp);