adium 3560:ac80f58b979a: Log all of GLib's (error) messages to t...

commits at adium.im commits at adium.im
Sun Nov 21 20:24:08 UTC 2010


details:	http://hg.adium.im/adium/rev/ac80f58b979a
revision:	3560:ac80f58b979a
author:		Thijs Alkemade <thijsalkemade at gmail.com>
date:		Sun Nov 21 21:22:41 2010 +0100

Log all of GLib's (error) messages to the debug log as well.

Copying the way Finch handles this (maybe not all domains are relevant for Adium). This will make debug logs more complete, and should stop users from whining about spam in Console.

diffs (60 lines):

diff -r 64ac33da3725 -r ac80f58b979a Plugins/Purple Service/SLPurpleCocoaAdapter.m
--- a/Plugins/Purple Service/SLPurpleCocoaAdapter.m	Sat Nov 20 14:47:45 2010 -0800
+++ b/Plugins/Purple Service/SLPurpleCocoaAdapter.m	Sun Nov 21 21:22:41 2010 +0100
@@ -169,13 +169,55 @@
 	configurePurpleDebugLogging();
 }
 
+void adium_glib_print(const char *string)
+{
+	AILog(@"(GLib): %s", string);
+}
+
+void adium_glib_log(const gchar *log_domain, GLogLevelFlags flags, const gchar *message, gpointer user_data)
+{
+	if (!AIDebugLoggingIsEnabled()) return;
+	
+	NSString *level;
+	
+	if (!log_domain) log_domain = "general";
+	
+	if ((flags & G_LOG_LEVEL_ERROR) == G_LOG_LEVEL_ERROR)
+		level = @"ERROR";
+	else if ((flags & G_LOG_LEVEL_CRITICAL) == G_LOG_LEVEL_CRITICAL)
+		level = @"CRITICAL";
+	else if ((flags & G_LOG_LEVEL_WARNING) == G_LOG_LEVEL_WARNING)
+		level = @"WARNING";
+	else if ((flags & G_LOG_LEVEL_MESSAGE) == G_LOG_LEVEL_MESSAGE)
+		level = @"MESSAGE";
+	else if ((flags & G_LOG_LEVEL_INFO) == G_LOG_LEVEL_INFO)
+		level = @"INFO";
+	else if ((flags & G_LOG_LEVEL_DEBUG) == G_LOG_LEVEL_DEBUG)
+		level = @"MISC";
+	else
+		level = @"UNKNOWN";
+
+	
+	AILog(@"(GLib : %s): %@: %s", log_domain, level, message);
+}
+
 - (void)initLibPurple
 {
 	/* Initializing libpurple may result in loading a ton of buddies if our permit and deny lists are large; that, in
 	 * turn, would create and update a ton of contacts.
 	 */
 	[[AIContactObserverManager sharedManager] delayListObjectNotifications];
-
+	
+	// Redirect every possible glib error message to AILog
+	g_set_print_handler(adium_glib_print);
+	g_set_printerr_handler(adium_glib_print);
+	
+	for (NSString *domain in [NSArray arrayWithObjects:@"GLib", @"GModule", @"GLib-GObject", @"GThread", @"Gnt", @"GStreamer", @"stderr", nil]) {
+		g_log_set_handler([domain UTF8String], G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, adium_glib_log, NULL);
+	}
+	
+	g_log_set_handler(NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, adium_glib_log, NULL);
+	
 	// Init the glib type system (used by GObjects)
 	g_type_init();
 	




More information about the commits mailing list