mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-11-04 10:08:56 +01:00 
			
		
		
		
	gmessages: fix dropping irrelevant log domains
If the string of one log domain is contained in another, it was printing both. For example, if G_MESSAGES_DEBUG is "Gtkspecial", it would also keep the logs of the "Gtk" domain
This commit is contained in:
		
				
					committed by
					
						
						Philip Withnall
					
				
			
			
				
	
			
			
			
						parent
						
							6d38e8be22
						
					
				
				
					commit
					ae8018d360
				
			@@ -2465,6 +2465,26 @@ log_is_old_api (const GLogField *fields,
 | 
				
			|||||||
          g_strcmp0 (fields[0].value, "1") == 0);
 | 
					          g_strcmp0 (fields[0].value, "1") == 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static gboolean
 | 
				
			||||||
 | 
					domain_found (const gchar *domains,
 | 
				
			||||||
 | 
					              const char  *log_domain)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  guint len;
 | 
				
			||||||
 | 
					  const gchar *found;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  len = strlen (log_domain);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  for (found = strstr (domains, log_domain); found;
 | 
				
			||||||
 | 
					       found = strstr (found + 1, log_domain))
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      if ((found == domains || found[-1] == ' ')
 | 
				
			||||||
 | 
					          && (found[len] == 0 || found[len] == ' '))
 | 
				
			||||||
 | 
					        return TRUE;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return FALSE;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Internal version of g_log_writer_default_would_drop(), which can
 | 
					 * Internal version of g_log_writer_default_would_drop(), which can
 | 
				
			||||||
 * read from either a log_domain or an array of fields. This avoids
 | 
					 * read from either a log_domain or an array of fields. This avoids
 | 
				
			||||||
@@ -2504,7 +2524,7 @@ should_drop_message (GLogLevelFlags   log_level,
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (strcmp (domains, "all") != 0 &&
 | 
					      if (strcmp (domains, "all") != 0 &&
 | 
				
			||||||
          (log_domain == NULL || !strstr (domains, log_domain)))
 | 
					          (log_domain == NULL || !domain_found (domains, log_domain)))
 | 
				
			||||||
        return TRUE;
 | 
					        return TRUE;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -244,6 +244,46 @@ test_default_handler_would_drop (void)
 | 
				
			|||||||
  g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
 | 
					  g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
 | 
				
			||||||
  g_assert_false (g_log_writer_default_would_drop (1<<G_LOG_LEVEL_USER_SHIFT, "foo"));
 | 
					  g_assert_false (g_log_writer_default_would_drop (1<<G_LOG_LEVEL_USER_SHIFT, "foo"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_setenv ("G_MESSAGES_DEBUG", "foobar", TRUE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
 | 
				
			||||||
 | 
					  g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_setenv ("G_MESSAGES_DEBUG", "foobar bar", TRUE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
 | 
				
			||||||
 | 
					  g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_setenv ("G_MESSAGES_DEBUG", "foobar bar barfoo", TRUE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
 | 
				
			||||||
 | 
					  g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_setenv ("G_MESSAGES_DEBUG", "foobar bar foo barfoo", TRUE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
 | 
				
			||||||
 | 
					  g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar"));
 | 
				
			||||||
 | 
					  g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "baz"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_setenv ("G_MESSAGES_DEBUG", "foo bar baz", TRUE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
 | 
				
			||||||
 | 
					  g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar"));
 | 
				
			||||||
 | 
					  g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "baz"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_setenv ("G_MESSAGES_DEBUG", "foo", TRUE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
 | 
				
			||||||
 | 
					  g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar"));
 | 
				
			||||||
 | 
					  g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foobarbaz"));
 | 
				
			||||||
 | 
					  g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "barfoobaz"));
 | 
				
			||||||
 | 
					  g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "barbazfoo"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  g_setenv ("G_MESSAGES_DEBUG", "   foo    bar  foobaz ", TRUE);
 | 
				
			||||||
 | 
					  g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "foo"));
 | 
				
			||||||
 | 
					  g_assert_false (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "bar"));
 | 
				
			||||||
 | 
					  g_assert_true (g_log_writer_default_would_drop (G_LOG_LEVEL_DEBUG, "baz"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  exit (0);
 | 
					  exit (0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user