Re: PATCH: Re: Gtk-CRITICAL error



On 1 Aug 1999, Owen Taylor wrote:

> 
> Tim Janik <timj@gtk.org> writes:
> 
> > On Sun, 1 Aug 1999, Iain wrote:
> 
> > in general, there is no need to additionally prefix warnings, errors
> > messages, etc... with the program name.
> > through the log domains, we already feature specific compile time log
> > layers. if the panel or other applications want their own warnings
> > to appear prefixed, just define -DG_LOG_DOMAIN=\"PANEL\" upon their
> > compilation.
> 
> Actually, no, G_LOG_DOMAIN doesn't do any good here.
> 
> Most of the warnings people see are being generated instide
> of GTK+ or GDK so they will have the GTK+ or GDK
> log domain. The reason why people want this is because
> a bunch of progams are all sending stderr to the same log
> file, and you need to figure out what program is producing
> the messages.
> 
> We aren't talking about trying to distinguish what library
> or app is producing the messages within the same process.

yep, i get the point. though i think programs that actually generate
warnings should be debugged seperatedly and in conjunction with
--g-fatal-warnings and gdb to get informative backtraces, the requested
feature should (if at all) be implemented along the lines of the appended
patch, which covers the process id as well; e.g. a simple "panel" prefix
doesn't do you much good if you are running multiple instances and the
warnings get intermixed.

> 
> Regards,
>                                         Owen
> 

---
ciaoTJ


cvs server: Diffing .
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/glib/ChangeLog,v
retrieving revision 1.315
diff -u -u -r1.315 ChangeLog
--- ChangeLog	1999/08/01 00:54:14	1.315
+++ ChangeLog	1999/08/02 19:08:36
@@ -1,3 +1,11 @@
+Mon Aug  2 21:03:10 1999  Tim Janik  <timj@gtk.org>
+
+	* configure.in: added --enable-msg-prefix option.
+
+	* gmessages.c (g_log_default_handler): feature "prg_name (pid:%u): "
+	if --enable-msg-prefix was selected (use "(process:%u): " if
+	g_get_prgname () returns NULL, along the lines of g_on_error_query).
+
 Sat Jul 31 17:52:03 PDT 1999 Manish Singh <yosh@gimp.org>
 
 	* glib.h
Index: NEWS
===================================================================
RCS file: /cvs/gnome/glib/NEWS,v
retrieving revision 1.25
diff -u -u -r1.25 NEWS
--- NEWS	1999/07/24 18:50:55	1.25
+++ NEWS	1999/08/02 19:08:37
@@ -8,6 +8,8 @@
 * Improvements to the OS/2 port, OS/2 module support.
 * Double ended queue implementation.
 * GLib macros for printf() formatting, e.g. G_GULONG_FORMAT = "lu"
+* New configure option --enable-msg-prefix to prefix messages, warnings
+  et ceteri with the program name and the process id.
 * New thread-safe random number generator Mersenne Twister.
 
 
Index: acconfig.h
===================================================================
RCS file: /cvs/gnome/glib/acconfig.h,v
retrieving revision 1.20
diff -u -u -r1.20 acconfig.h
--- acconfig.h	1999/07/01 09:30:18	1.20
+++ acconfig.h	1999/08/02 19:08:37
@@ -40,6 +40,7 @@
 #undef REALLOC_0_WORKS
 
 #undef G_COMPILED_WITH_DEBUGGING
+#undef G_ENABLE_MSG_PREFIX
 #undef G_THREADS_ENABLED
 
 #undef GLIB_SIZEOF_GMUTEX
Index: configure.in
===================================================================
RCS file: /cvs/gnome/glib/configure.in,v
retrieving revision 1.110
diff -u -u -r1.110 configure.in
--- configure.in	1999/07/24 18:50:55	1.110
+++ configure.in	1999/08/02 19:08:38
@@ -104,6 +104,7 @@
 
 dnl declare --enable-* args and collect ac_help strings
 AC_ARG_ENABLE(debug, [  --enable-debug=[no/minimum/yes] turn on debugging [default=$debug_default]],,enable_debug=$debug_default)
+AC_ARG_ENABLE(msg-prefix, [  --enable-msg-prefix     turn on program name and PID prefixing of messages and warnings],,enable_msg_prefix=no)
 AC_ARG_ENABLE(mem_check, [  --enable-mem-check      turn on malloc/free sanity checking [default=no]],,enable_mem_check=no)
 AC_ARG_ENABLE(mem_profile, [  --enable-mem-profile    turn on malloc profiling atexit [default=no]],,enable_mem_profile=no)
 AC_ARG_ENABLE(ansi, [  --enable-ansi           turn on strict ansi [default=no]],
@@ -143,6 +144,10 @@
 fi
 
 AC_DEFINE_UNQUOTED(G_COMPILED_WITH_DEBUGGING, "${enable_debug}")
+
+if test "x$enable_msg_prefix" = "xyes"; then
+  AC_DEFINE_UNQUOTED(G_ENABLE_MSG_PREFIX, 1)
+fi
 
 # Checks for programs.
 AC_PROG_CC
Index: gmessages.c
===================================================================
RCS file: /cvs/gnome/glib/gmessages.c,v
retrieving revision 1.12
diff -u -u -r1.12 gmessages.c
--- gmessages.c	1999/02/24 06:13:45	1.12
+++ gmessages.c	1999/08/02 19:08:39
@@ -42,8 +42,9 @@
 #endif
 
 #ifdef NATIVE_WIN32
-#define STRICT
-#include <windows.h>
+#  define STRICT
+#  include <windows.h>
+#  include <process.h>          /* For _getpid() */
 
 /* Just use stdio. If we're out of memory, we're hosed anyway. */
 #undef write
@@ -420,9 +421,10 @@
 #endif
   gboolean in_recursion;
   gboolean is_fatal;  
-  GErrorFunc     local_glib_error_func;
-  GWarningFunc   local_glib_warning_func;
-  GPrintFunc     local_glib_message_func;
+  GErrorFunc local_glib_error_func;
+  GWarningFunc local_glib_warning_func;
+  GPrintFunc local_glib_message_func;
+  gchar prg_pid[64], *prg_name = g_get_prgname ();
 
   in_recursion = (log_level & G_LOG_FLAG_RECURSION) != 0;
   is_fatal = (log_level & G_LOG_FLAG_FATAL) != 0;
@@ -430,6 +432,13 @@
   
   if (!message)
     message = "g_log_default_handler(): (NULL) message";
+  if (!prg_name)
+    {
+      prg_name = "(process";
+      sprintf (prg_pid, ":%u): ", getpid ());
+    }
+  else
+    sprintf (prg_pid, " (pid:%u): ", getpid ());
   
 #ifdef NATIVE_WIN32
   /* Use just stdout as stderr is hard to get redirected from the
@@ -457,19 +466,23 @@
 	}
       /* use write(2) for output, in case we are out of memeory */
       ensure_stdout_valid ();
+      write (fd, "\n", 1);
+#ifdef G_ENABLE_MSG_PREFIX
+      write (fd, prg_name, strlen (prg_name));
+      write (fd, prg_pid, strlen (prg_pid));
+#endif /* G_ENABLE_MSG_PREFIX */
       if (log_domain)
 	{
-	  write (fd, "\n", 1);
 	  write (fd, log_domain, strlen (log_domain));
 	  write (fd, "-", 1);
 	}
       else
-	write (fd, "\n** ", 4);
+	write (fd, "** ", 3);
       if (in_recursion)
 	write (fd, "ERROR (recursed) **: ", 21);
       else
 	write (fd, "ERROR **: ", 10);
-      write (fd, message, strlen(message));
+      write (fd, message, strlen (message));
       if (is_fatal)
 	write (fd, "\naborting...\n", 13);
       else
@@ -477,19 +490,23 @@
       break;
     case G_LOG_LEVEL_CRITICAL:
       ensure_stdout_valid ();
+      write (fd, "\n", 1);
+#ifdef G_ENABLE_MSG_PREFIX
+      write (fd, prg_name, strlen (prg_name));
+      write (fd, prg_pid, strlen (prg_pid));
+#endif /* G_ENABLE_MSG_PREFIX */
       if (log_domain)
 	{
-	  write (fd, "\n", 1);
 	  write (fd, log_domain, strlen (log_domain));
 	  write (fd, "-", 1);
 	}
       else
-	write (fd, "\n** ", 4);
+	write (fd, "** ", 3);
       if (in_recursion)
 	write (fd, "CRITICAL (recursed) **: ", 24);
       else
 	write (fd, "CRITICAL **: ", 13);
-      write (fd, message, strlen(message));
+      write (fd, message, strlen (message));
       if (is_fatal)
 	write (fd, "\naborting...\n", 13);
       else
@@ -503,19 +520,23 @@
 	  return;
 	}
       ensure_stdout_valid ();
+      write (fd, "\n", 1);
+#ifdef G_ENABLE_MSG_PREFIX
+      write (fd, prg_name, strlen (prg_name));
+      write (fd, prg_pid, strlen (prg_pid));
+#endif /* G_ENABLE_MSG_PREFIX */
       if (log_domain)
 	{
-	  write (fd, "\n", 1);
 	  write (fd, log_domain, strlen (log_domain));
 	  write (fd, "-", 1);
 	}
       else
-	write (fd, "\n** ", 4);
+	write (fd, "** ", 3);
       if (in_recursion)
 	write (fd, "WARNING (recursed) **: ", 23);
       else
 	write (fd, "WARNING **: ", 12);
-      write (fd, message, strlen(message));
+      write (fd, message, strlen (message));
       if (is_fatal)
 	write (fd, "\naborting...\n", 13);
       else
@@ -529,6 +550,10 @@
 	  return;
 	}
       ensure_stdout_valid ();
+#ifdef G_ENABLE_MSG_PREFIX
+      write (fd, prg_name, strlen (prg_name));
+      write (fd, prg_pid, strlen (prg_pid));
+#endif /* G_ENABLE_MSG_PREFIX */
       if (log_domain)
 	{
 	  write (fd, log_domain, strlen (log_domain));
@@ -538,7 +563,7 @@
 	write (fd, "Message (recursed): ", 20);
       else
 	write (fd, "Message: ", 9);
-      write (fd, message, strlen(message));
+      write (fd, message, strlen (message));
       if (is_fatal)
 	write (fd, "\naborting...\n", 13);
       else
@@ -546,6 +571,10 @@
       break;
     case G_LOG_LEVEL_INFO:
       ensure_stdout_valid ();
+#ifdef G_ENABLE_MSG_PREFIX
+      write (fd, prg_name, strlen (prg_name));
+      write (fd, prg_pid, strlen (prg_pid));
+#endif /* G_ENABLE_MSG_PREFIX */
       if (log_domain)
 	{
 	  write (fd, log_domain, strlen (log_domain));
@@ -555,7 +584,7 @@
 	write (fd, "INFO (recursed): ", 17);
       else
 	write (fd, "INFO: ", 6);
-      write (fd, message, strlen(message));
+      write (fd, message, strlen (message));
       if (is_fatal)
 	write (fd, "\naborting...\n", 13);
       else
@@ -563,6 +592,10 @@
       break;
     case G_LOG_LEVEL_DEBUG:
       ensure_stdout_valid ();
+#ifdef G_ENABLE_MSG_PREFIX
+      write (fd, prg_name, strlen (prg_name));
+      write (fd, prg_pid, strlen (prg_pid));
+#endif /* G_ENABLE_MSG_PREFIX */
       if (log_domain)
 	{
 	  write (fd, log_domain, strlen (log_domain));
@@ -572,7 +605,7 @@
 	write (fd, "DEBUG (recursed): ", 18);
       else
 	write (fd, "DEBUG: ", 7);
-      write (fd, message, strlen(message));
+      write (fd, message, strlen (message));
       if (is_fatal)
 	write (fd, "\naborting...\n", 13);
       else
@@ -583,6 +616,10 @@
        * try to make the best out of it.
        */
       ensure_stdout_valid ();
+#ifdef G_ENABLE_MSG_PREFIX
+      write (fd, prg_name, strlen (prg_name));
+      write (fd, prg_pid, strlen (prg_pid));
+#endif /* G_ENABLE_MSG_PREFIX */
       if (log_domain)
 	{
 	  write (fd, log_domain, strlen (log_domain));
@@ -612,7 +649,7 @@
 	}
       else
 	write (fd, "): ", 3);
-      write (fd, message, strlen(message));
+      write (fd, message, strlen (message));
       if (is_fatal)
 	write (fd, "\naborting...\n", 13);
       else
cvs server: Diffing debian
cvs server: Diffing docs
cvs server: Diffing gmodule
cvs server: Diffing gthread
cvs server: Diffing tests



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]