summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@novell.com>2006-12-12 17:26:11 +0000
committerFederico Mena Quintero <federico@src.gnome.org>2006-12-12 17:26:11 +0000
commit7978ff0f89ce8eeb7b1c6c66463957eb361dc1fd (patch)
tree0ad09700a4d149836c87ff8bc632e7ad71f4d9ce
parentd3b555b73b1870527c91f3bcaaf0fcbc4b67ee58 (diff)
downloadnautilus-7978ff0f89ce8eeb7b1c6c66463957eb361dc1fd.tar.gz
Oops, make this 1000 by default; 30000 was way too big for normal usage.
2006-12-12 Federico Mena Quintero <federico@novell.com> * libnautilus-private/nautilus-debug-log.c (DEFAULT_RING_BUFFER_NUM_LINES): Oops, make this 1000 by default; 30000 was way too big for normal usage. (add_to_milestones): New function; adds a milestone string to a linked list of milestones. (nautilus_debug_logv): Call add_to_milestones() if appropriate. (write_string): New helper function. (dump_milestones): New helper function. (dump_configuration): Use write_string(). (dump_ring_buffer): New helper function; moved the code from nautilus_debug_log_dump(). (nautilus_debug_log_dump): Use dump_milestones() and dump_ring_buffer(). (dump_configuration): Print the instructions to re-create the configuration here, instead of in nautilus_debug_log_dump().
-rw-r--r--ChangeLog17
-rw-r--r--libnautilus-private/nautilus-debug-log.c168
2 files changed, 128 insertions, 57 deletions
diff --git a/ChangeLog b/ChangeLog
index 17a40508d..228717f0b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2006-12-12 Federico Mena Quintero <federico@novell.com>
+
+ * libnautilus-private/nautilus-debug-log.c
+ (DEFAULT_RING_BUFFER_NUM_LINES): Oops, make this 1000 by default;
+ 30000 was way too big for normal usage.
+ (add_to_milestones): New function; adds a milestone string to a
+ linked list of milestones.
+ (nautilus_debug_logv): Call add_to_milestones() if appropriate.
+ (write_string): New helper function.
+ (dump_milestones): New helper function.
+ (dump_configuration): Use write_string().
+ (dump_ring_buffer): New helper function; moved the code from
+ nautilus_debug_log_dump().
+ (nautilus_debug_log_dump): Use dump_milestones() and dump_ring_buffer().
+ (dump_configuration): Print the instructions to re-create the
+ configuration here, instead of in nautilus_debug_log_dump().
+
2006-12-12 Christian Persch <chpe@cvs.gnome.org>
* src/ephy-spinner.c:
diff --git a/libnautilus-private/nautilus-debug-log.c b/libnautilus-private/nautilus-debug-log.c
index 5f7a9c53e..b498a8d99 100644
--- a/libnautilus-private/nautilus-debug-log.c
+++ b/libnautilus-private/nautilus-debug-log.c
@@ -1,24 +1,24 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
nautilus-debug-log.c: Ring buffer for logging debug messages
-
+
Copyright (C) 2006 Novell, Inc.
-
+
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
-
+
Author: Federico Mena-Quintero <federico@novell.com>
*/
#include <config.h>
@@ -31,7 +31,7 @@
#include "nautilus-debug-log.h"
#include "nautilus-file.h"
-#define DEFAULT_RING_BUFFER_NUM_LINES 30000
+#define DEFAULT_RING_BUFFER_NUM_LINES 1000
#define KEY_FILE_GROUP "debug log"
#define KEY_FILE_DOMAINS_KEY "enable domains"
@@ -45,6 +45,9 @@ static int ring_buffer_next_index;
static int ring_buffer_num_lines;
static int ring_buffer_max_lines = DEFAULT_RING_BUFFER_NUM_LINES;
+static GSList *milestones_head;
+static GSList *milestones_tail;
+
static void
lock (void)
{
@@ -119,6 +122,23 @@ add_to_ring (char *str)
}
}
+static void
+add_to_milestones (const char *str)
+{
+ char *str_copy;
+
+ str_copy = g_strdup (str);
+
+ if (milestones_tail) {
+ milestones_tail = g_slist_append (milestones_tail, str_copy);
+ milestones_tail = milestones_tail->next;
+ } else {
+ milestones_head = milestones_tail = g_slist_append (NULL, str_copy);
+ }
+
+ g_assert (milestones_head != NULL && milestones_tail != NULL);
+}
+
void
nautilus_debug_logv (gboolean is_milestone, const char *domain, const GList *uris, const char *format, va_list args)
{
@@ -190,8 +210,8 @@ nautilus_debug_logv (gboolean is_milestone, const char *domain, const GList *uri
}
add_to_ring (debug_str);
-
- /* FIXME: deal with milestones */
+ if (is_milestone)
+ add_to_milestones (debug_str);
out:
unlock ();
@@ -413,13 +433,31 @@ make_key_file_from_configuration (void)
}
/* max lines */
-
+
g_key_file_set_integer (key_file, KEY_FILE_GROUP, KEY_FILE_MAX_LINES_KEY, ring_buffer_max_lines);
return key_file;
}
static gboolean
+write_string (const char *filename, FILE *file, const char *str, GError **error)
+{
+ if (fputs (str, file) == EOF) {
+ int saved_errno;
+
+ saved_errno = errno;
+ g_set_error (error,
+ G_FILE_ERROR,
+ g_file_error_from_errno (saved_errno),
+ "error when writing to log file %s", filename);
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
dump_configuration (const char *filename, FILE *file, GError **error)
{
GKeyFile *key_file;
@@ -427,6 +465,15 @@ dump_configuration (const char *filename, FILE *file, GError **error)
gsize length;
gboolean success;
+ if (!write_string (filename, file,
+ "\n\n"
+ "This configuration for the debug log can be re-created\n"
+ "by putting the following in ~/nautilus-debug-log.conf\n"
+ "(use ';' to separate domain names):\n\n",
+ error)) {
+ return FALSE;
+ }
+
success = FALSE;
key_file = make_key_file_from_configuration ();
@@ -435,15 +482,7 @@ dump_configuration (const char *filename, FILE *file, GError **error)
if (!data)
goto out;
- if (fputs (data, file) == EOF) {
- int saved_errno;
-
- saved_errno = errno;
- g_set_error (error,
- G_FILE_ERROR,
- g_file_error_from_errno (saved_errno),
- "error when writing to log file %s", filename);
-
+ if (!write_string (filename, file, data, error)) {
goto out;
}
@@ -453,31 +492,37 @@ dump_configuration (const char *filename, FILE *file, GError **error)
return success;
}
-gboolean
-nautilus_debug_log_dump (const char *filename, GError **error)
+static gboolean
+dump_milestones (const char *filename, FILE *file, GError **error)
{
- FILE *file;
- gboolean success;
- int start_index;
- int i;
+ GSList *l;
- g_assert (error == NULL || *error == NULL);
+ if (!write_string (filename, file, "===== BEGIN MILESTONES =====\n", error))
+ return FALSE;
- lock ();
+ for (l = milestones_head; l; l = l->next) {
+ const char *str;
- success = FALSE;
+ str = l->data;
+ if (!(write_string (filename, file, str, error)
+ && write_string (filename, file, "\n", error)))
+ return FALSE;
+ }
- file = fopen (filename, "w");
- if (!file) {
- int saved_errno;
+ if (!write_string (filename, file, "===== END MILESTONES =====\n", error))
+ return FALSE;
- saved_errno = errno;
- g_set_error (error,
- G_FILE_ERROR,
- g_file_error_from_errno (saved_errno),
- "could not open log file %s", filename);
- goto out;
- }
+ return TRUE;
+}
+
+static gboolean
+dump_ring_buffer (const char *filename, FILE *file, GError **error)
+{
+ int start_index;
+ int i;
+
+ if (!write_string (filename, file, "===== BEGIN RING BUFFER =====\n", error))
+ return FALSE;
if (ring_buffer_num_lines == ring_buffer_max_lines)
start_index = ring_buffer_next_index;
@@ -489,38 +534,47 @@ nautilus_debug_log_dump (const char *filename, GError **error)
idx = (start_index + i) % ring_buffer_max_lines;
- if (fputs (ring_buffer[idx], file) == EOF
- || fputc ('\n', file) == EOF) {
- int saved_errno;
-
- saved_errno = errno;
- g_set_error (error,
- G_FILE_ERROR,
- g_file_error_from_errno (saved_errno),
- "error when writing to log file %s", filename);
-
- goto do_close;
+ if (!(write_string (filename, file, ring_buffer[idx], error)
+ && write_string (filename, file, "\n", error))) {
+ return FALSE;
}
}
- if (fputs ("\n\n"
- "This configuration for the debug log can be re-created\n"
- "by putting the following in ~/nautilus-debug-log.conf\n"
- "(use ';' to separate domain names):\n\n",
- file) == EOF) {
+ if (!write_string (filename, file, "===== END RING BUFFER =====\n", error))
+ return FALSE;
+
+ return TRUE;
+}
+
+gboolean
+nautilus_debug_log_dump (const char *filename, GError **error)
+{
+ FILE *file;
+ gboolean success;
+
+ g_assert (error == NULL || *error == NULL);
+
+ lock ();
+
+ success = FALSE;
+
+ file = fopen (filename, "w");
+ if (!file) {
int saved_errno;
saved_errno = errno;
g_set_error (error,
G_FILE_ERROR,
g_file_error_from_errno (saved_errno),
- "error when writing to log file %s", filename);
-
- goto do_close;
+ "could not open log file %s", filename);
+ goto out;
}
- if (!dump_configuration (filename, file, error))
+ if (!(dump_milestones (filename, file, error)
+ && dump_ring_buffer (filename, file, error)
+ && dump_configuration (filename, file, error))) {
goto do_close;
+ }
success = TRUE;