Jamie Jones <[EMAIL PROTECTED]> wrote: > BTW: would it be a good idea to timestamp stderr/stdout messages ?
I've made a quick patch to add this information to (nearly) all g_warning()s. This could also easily extended to have a more comfortable logging functionalty compared to the current "dbg > x" approach. Christian
Index: main.c
===================================================================
RCS file: /cvsroot/gtk-gnutella/gtk-gnutella-current/src/main.c,v
retrieving revision 1.128
diff -u -r1.128 main.c
--- main.c 10 Jan 2003 22:32:30 -0000 1.128
+++ main.c 6 Feb 2003 07:40:43 -0000
@@ -310,6 +310,39 @@
return FALSE;
}
+static void log_handler(const gchar *log_domain, GLogLevelFlags log_level,
+ const gchar *message, gpointer user_data)
+{
+ time_t now;
+ const char *level;
+ char timestamp[26];
+
+ now = time((time_t *) NULL);
+ ctime_r(&now, timestamp);
+ timestamp[24] = '\0'; /* remove \n */
+ switch (log_level) {
+ case G_LOG_LEVEL_CRITICAL:
+ level = "CRITICAL";
+ break;
+ case G_LOG_LEVEL_ERROR:
+ level = "ERROR";
+ break;
+ case G_LOG_LEVEL_WARNING:
+ level = "WARNING";
+ break;
+ default:
+ level = "UNKNOWN";
+ }
+ fprintf(stderr, "[%s] (%s): %s\n", timestamp, level, message);
+}
+
+static void log_init(void)
+{
+ g_log_set_handler(G_LOG_DOMAIN,
+ G_LOG_LEVEL_ERROR | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL,
+ &log_handler, NULL);
+}
+
gint main(gint argc, gchar ** argv)
{
gint i;
@@ -318,6 +351,7 @@
close(i); /* Just in case */
/* Our inits */
+ log_init();
atoms_init();
version_init();
random_init();
msg00083/pgp00000.pgp
Description: PGP signature
