aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorSrinivasa Ragavan <sragavan@novell.com>2007-12-17 04:19:53 +0800
committerSrinivasa Ragavan <sragavan@src.gnome.org>2007-12-17 04:19:53 +0800
commit5b89cbe4f598387a56d22627558b5308da6044bc (patch)
tree620d37062cec0df7cbfa107d8317b62fb28ce9ee /e-util
parent9bf01a179e346a25967a0898c900c863ed7b95db (diff)
downloadgsoc2013-evolution-5b89cbe4f598387a56d22627558b5308da6044bc.tar.gz
gsoc2013-evolution-5b89cbe4f598387a56d22627558b5308da6044bc.tar.zst
gsoc2013-evolution-5b89cbe4f598387a56d22627558b5308da6044bc.zip
** Non-intrusive errror reporting and basic logging support.
2007-12-17 Srinivasa Ragavan <sragavan@novell.com> ** Non-intrusive errror reporting and basic logging support. * em-folder-browser.c: (emfb_help_debug): Invoke the debug menu. * evolution-mail.schemas.in: Schema for error timeout and level. * mail-component.c: (mail_component_init), (render_pixbuf), (render_level), (render_date), (append_logs), (spin_value_changed), (mail_component_show_logger): Handle the lifecycle of the logger. * mail-component.h: Api to show the logger. * mail-config.c: (gconf_error_time_changed), (gconf_error_level_changed), (mail_config_init), (mail_config_get_error_timeout), (mail_config_get_error_level): Load and get the error time and level. * mail-config.h: * mail-mt.c: (mail_msg_set_cancelable), (mail_msg_new), (end_event_callback), (mail_msg_free), (mail_msg_check_error), (operation_cancel), (do_op_status): Revamp the error handling. * mail-mt.h: * mail-ops.c: (send_queue_send), (mail_send_queue): Handle the send/receive case of error reporting separately. * mail-send-recv.c: (free_send_info), (mail_send): 2007-12-17 Srinivasa Ragavan <sragavan@novell.com> ** Revamped Activity handler and task bar/widget for non-intrusive error reporting * e-activity-handler.c: (activity_info_new), (activity_info_free), (task_widget_new_from_activity_info), (setup_task_bar), (e_activity_handler_init), (e_activity_handler_set_error_flush_time), (e_activity_handler_set_logger), (cancel_wrapper), (e_activity_handler_cancelable_operation_started), (e_activity_handler_operation_started), (handle_error), (error_cleanup), (e_activity_handler_make_error), (e_activity_handler_operation_set_error), (e_activity_handler_operation_progressing), (e_activity_handler_operation_finished): * e-activity-handler.h: * e-task-bar.c: (e_task_bar_prepend_task), (e_task_bar_remove_task_from_id), (e_task_bar_remove_task), (e_task_bar_get_task_widget_from_id): * e-task-bar.h: * e-task-widget.c: (e_task_widget_init), (button_press_event_cb), (prepare_popup), (e_task_widget_construct), (e_task_widget_new_with_cancel), (e_task_widget_new), (e_task_widget_update_image): * e-task-widget.h: 2007-12-17 Srinivasa Ragavan <sragavan@novell.com> * Makefile.am: Add e-logger.[ch] to compilation * e-error.c: (e_error_newv): Add primary/secondary text to the error dialog to the gobject as data. * e-logger.[ch]: A new logger provision Evolution. 2007-12-17 Srinivasa Ragavan <sragavan@novell.com> * evolution-mail-global.xml: Add Debug Log menu item for mailer. * evolution.xml: Add place holder for Debug menu item. svn path=/trunk/; revision=34712
Diffstat (limited to 'e-util')
-rw-r--r--e-util/ChangeLog7
-rw-r--r--e-util/Makefile.am2
-rw-r--r--e-util/e-error.c22
-rw-r--r--e-util/e-logger.c173
-rw-r--r--e-util/e-logger.h64
5 files changed, 262 insertions, 6 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index 3d07500de2..f33a5bef7a 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,10 @@
+2007-12-17 Srinivasa Ragavan <sragavan@novell.com>
+
+ * Makefile.am: Add e-logger.[ch] to compilation
+ * e-error.c: (e_error_newv): Add primary/secondary text to the error
+ dialog to the gobject as data.
+ * e-logger.[ch]: A new logger provision Evolution.
+
2007-12-05 Srinivasa Ragavan <sragavan@novell.com>
* e-util.h: Fix a compiler warning
diff --git a/e-util/Makefile.am b/e-util/Makefile.am
index 8ae7c41aa8..3031358452 100644
--- a/e-util/Makefile.am
+++ b/e-util/Makefile.am
@@ -56,6 +56,7 @@ eutilinclude_HEADERS = \
e-html-utils.h \
e-icon-factory.h \
e-import.h \
+ e-logger.h \
e-menu.h \
e-mktemp.h \
e-print.h \
@@ -94,6 +95,7 @@ libeutil_la_SOURCES = \
e-html-utils.c \
e-icon-factory.c \
e-import.c \
+ e-logger.c \
e-menu.c \
e-mktemp.c \
e-plugin.c \
diff --git a/e-util/e-error.c b/e-util/e-error.c
index 94ad35f31a..007d910f0d 100644
--- a/e-util/e-error.c
+++ b/e-util/e-error.c
@@ -419,10 +419,10 @@ e_error_newv(GtkWindow *parent, const char *tag, const char *arg0, va_list ap)
struct _e_error_button *b;
GtkWidget *hbox, *w, *scroll=NULL;
char *tmp, *domain, *id;
- GString *out;
+ GString *out, *oerr;
GPtrArray *args;
GtkDialog *dialog;
- gchar *str;
+ gchar *str, *perr=NULL, *serr=NULL;
if (error_table == NULL)
ee_load_tables();
@@ -529,11 +529,19 @@ e_error_newv(GtkWindow *parent, const char *tag, const char *arg0, va_list ap)
g_string_append(out, "<span weight=\"bold\" size=\"larger\">");
ee_build_label(out, dgettext(table->translation_domain, e->primary), args);
g_string_append(out, "</span>\n\n");
+ oerr = g_string_new("");
+ ee_build_label(oerr, dgettext(table->translation_domain, e->primary), args);
+ perr = g_strdup (oerr->str);
+ g_string_free (oerr, TRUE);
}
-
- if (e->secondary)
+
+ if (e->secondary) {
ee_build_label(out, dgettext(table->translation_domain, e->secondary), args);
-
+ oerr = g_string_new("");
+ ee_build_label(oerr, dgettext(table->translation_domain, e->secondary), args);
+ serr = g_strdup (oerr->str);
+ g_string_free (oerr, TRUE);
+ }
g_ptr_array_free(args, TRUE);
if (e->scroll) {
@@ -556,7 +564,9 @@ e_error_newv(GtkWindow *parent, const char *tag, const char *arg0, va_list ap)
gtk_widget_show_all(hbox);
gtk_box_pack_start((GtkBox *)dialog->vbox, hbox, TRUE, TRUE, 0);
-
+ g_object_set_data_full ((GObject *) dialog, "primary", perr, g_free);
+ g_object_set_data_full ((GObject *) dialog, "secondary", serr, g_free);
+
return (GtkWidget *)dialog;
}
diff --git a/e-util/e-logger.c b/e-util/e-logger.c
new file mode 100644
index 0000000000..369f7ea90d
--- /dev/null
+++ b/e-util/e-logger.c
@@ -0,0 +1,173 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Authors: Srinivasa Ragavan <sragavan@gnome.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <glib.h>
+#include <glib/gstdio.h>
+#include "e-logger.h"
+#include "e-mktemp.h"
+
+/* 5 Minutes */
+#define TIMEOUT_INTERVAL 300000
+
+static GObjectClass *parent;
+
+struct _ELoggerPrivate {
+ char *component;
+ char *logfile;
+ FILE *fp;
+
+ guint timer;
+};
+
+static gboolean
+flush_logfile (ELogger *el)
+{
+ fflush (el->priv->fp);
+ el->priv->timer = 0;
+
+ return FALSE;
+}
+
+static void
+el_init(GObject *o)
+{
+ ELogger *l = (ELogger *) o;
+ ELoggerPrivate *priv;
+
+ priv = g_new (ELoggerPrivate, 1);
+ priv->logfile = NULL;
+ priv->fp = NULL;
+ l->priv=priv;
+}
+
+static void
+el_finalise(GObject *o)
+{
+ ELogger *el = (ELogger *) o;
+ ELoggerPrivate *priv = el->priv;
+
+ if (priv->timer)
+ g_source_remove (priv->timer);
+ flush_logfile (el);
+ fclose (el->priv->fp);
+ g_free (el->priv);
+ ((GObjectClass *)parent)->finalize(o);
+}
+
+static void
+el_class_init(GObjectClass *klass)
+{
+ klass->finalize = el_finalise;
+
+}
+
+GType
+e_logger_get_type(void)
+{
+ static GType type = 0;
+
+ if (type == 0) {
+ static const GTypeInfo info = {
+ sizeof(ELoggerClass),
+ NULL, NULL,
+ (GClassInitFunc)el_class_init,
+ NULL, NULL,
+ sizeof(ELogger), 0,
+ (GInstanceInitFunc)el_init
+ };
+ parent = g_type_class_ref(G_TYPE_OBJECT);
+ type = g_type_register_static(G_TYPE_OBJECT, "ELogger", &info, 0);
+ }
+
+ return type;
+}
+
+
+ELogger *e_logger_create(char *component)
+{
+ ELogger *el = g_object_new(e_logger_get_type(), 0);
+ ELoggerPrivate *priv;
+ char *tmp;
+
+ tmp = g_strdup_printf("%s.log.XXXXXX", component);
+ priv = el->priv;
+ priv->component = g_strdup (component);
+ priv->logfile = e_mktemp (tmp);
+ g_free (tmp);
+ priv->fp = g_fopen (priv->logfile, "w");
+
+ priv->timer = 0;
+ return el;
+}
+
+
+
+static void set_dirty (ELogger *el)
+{
+ if (el->priv->timer)
+ return;
+
+ el->priv->timer = g_timeout_add (TIMEOUT_INTERVAL, (GSourceFunc) flush_logfile, el);
+}
+
+void
+e_logger_log (ELogger *el, int level, char *primary, char *secondary)
+{
+ time_t t = time (NULL);
+
+ fprintf(el->priv->fp, "%d:%ld:%s\n", level, t, primary);
+ fprintf(el->priv->fp, "%d:%ld:%s\n", level, t, secondary);
+ set_dirty (el);
+}
+
+void
+e_logger_get_logs (ELogger *el, ELogFunction func, gpointer data)
+{
+ FILE *fp;
+ char buf[250];
+ gboolean error = FALSE;
+
+ /* Flush everything before we get the logs */
+ fflush (el->priv->fp);
+ fp = g_fopen (el->priv->logfile, "r");
+ while (!error || feof(fp)) {
+ char *tmp;
+ tmp = fgets (buf, 250, fp);
+ if (!tmp)
+ break;
+#if 0
+ if (strlen(tmp) == 249) {
+ /* FIXME: There may be more */
+ }
+#endif
+ func (tmp, data);
+ }
+ fclose(fp);
+}
+
diff --git a/e-util/e-logger.h b/e-util/e-logger.h
new file mode 100644
index 0000000000..0dc8b53921
--- /dev/null
+++ b/e-util/e-logger.h
@@ -0,0 +1,64 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Authors: Srinivasa Ragavan <sragavan@gnome.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef __E_LOGGER_H__
+#define __E_LOGGER_H__
+
+#include <glib-object.h>
+
+#ifdef __cplusplus
+extern "C" {
+#pragma }
+#endif /* __cplusplus */
+
+typedef struct _ELogger ELogger;
+typedef struct _ELoggerClass ELoggerClass;
+typedef struct _ELoggerPrivate ELoggerPrivate;
+
+typedef void (* ELogFunction) (char *line, gpointer data);
+
+enum e_log_level_t {
+ E_LOG_ERROR,
+ E_LOG_WARNINGS,
+ E_LOG_DEBUG
+};
+
+/* The object */
+struct _ELogger {
+ GObject parent;
+
+ struct _ELoggerPrivate *priv;
+};
+
+struct _ELoggerClass {
+ GObjectClass popup_class;
+};
+
+GType e_logger_get_type(void);
+ELogger *e_logger_create(char *component);
+void e_logger_log (ELogger *el, int level, char *primary, char *secondary);
+void e_logger_get_logs (ELogger *el, ELogFunction func, gpointer data);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __E_LOGGER_H__ */