summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2013-10-04 20:00:33 -0400
committerRyan Lortie <desrt@desrt.ca>2013-10-04 20:00:33 -0400
commitc1624e02a41bab21e3496f2a3d26eb2d14a210ca (patch)
treed14f15f2b75d0a449de19ac81ff57abe0b907cb6
parent97a8ead5f701db052323a3d78cab0174fce03eb2 (diff)
Use GLib logging facilities with handler func
...instead of our custom-rolled macros. This will allow splitting users of the logging functions into separate files that don't need direct access to global variables.
-rw-r--r--src/Makefile.am1
-rw-r--r--src/update-desktop-database.c41
2 files changed, 26 insertions, 16 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 3ebf03d..28c3444 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,6 +5,7 @@ bin_PROGRAMS = \
AM_CPPFLAGS = \
$(DESKTOP_FILE_UTILS_CFLAGS) \
+ -DG_LOG_DOMAIN=\"desktop-file-utils\" \
-DDATADIR="\"$(datadir)\"" \
-D_FILE_OFFSET_BITS=64 \
-D_LARGEFILE64_SOURCE
diff --git a/src/update-desktop-database.c b/src/update-desktop-database.c
index 30ab6ce..92cb9a3 100644
--- a/src/update-desktop-database.c
+++ b/src/update-desktop-database.c
@@ -42,12 +42,24 @@
#define NAME "update-desktop-database"
#define CACHE_FILENAME "mimeinfo.cache"
-#define udd_print(...) if (!quiet) g_printerr (__VA_ARGS__)
-#define udd_verbose_print(...) if (!quiet && verbose) g_printerr (__VA_ARGS__)
-
static gboolean verbose = FALSE, quiet = FALSE;
static void
+log_handler (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer user_data)
+{
+ if (g_str_equal (log_domain, G_LOG_DOMAIN))
+ {
+ if (verbose || ((log_level & G_LOG_LEVEL_WARNING) && !quiet))
+ g_printerr ("%s\n", message);
+ }
+ else
+ g_log_default_handler (log_domain, log_level, message, NULL);
+}
+
+static void
list_free_deep (gpointer key, GList *l, gpointer data)
{
g_list_foreach (l, (GFunc)g_free, NULL);
@@ -131,13 +143,13 @@ process_desktop_file (GHashTable *mime_types_map,
case MU_VALID:
break;
case MU_DISCOURAGED:
- udd_print (_("Warning in file \"%s\": usage of MIME type \"%s\" is "
+ g_warning (_("Warning in file \"%s\": usage of MIME type \"%s\" is "
"discouraged (%s)\n"),
desktop_file, mime_types[i], valid_error);
g_free (valid_error);
break;
case MU_INVALID:
- udd_print (_("Error in file \"%s\": \"%s\" is an invalid MIME type "
+ g_warning (_("Error in file \"%s\": \"%s\" is an invalid MIME type "
"(%s)\n"),
desktop_file, mime_types[i], valid_error);
g_free (valid_error);
@@ -195,8 +207,7 @@ process_desktop_files (GHashTable *mime_types_map,
if (process_error != NULL)
{
- udd_verbose_print (_("Could not process directory \"%s\": %s\n"),
- full_path, process_error->message);
+ g_warning (_("Could not process directory \"%s\": %s\n"), full_path, process_error->message);
g_error_free (process_error);
process_error = NULL;
}
@@ -219,13 +230,11 @@ process_desktop_files (GHashTable *mime_types_map,
G_KEY_FILE_ERROR,
G_KEY_FILE_ERROR_KEY_NOT_FOUND))
{
- udd_print (_("Could not parse file \"%s\": %s\n"), full_path,
- process_error->message);
+ g_warning (_("Could not parse file \"%s\": %s\n"), full_path, process_error->message);
}
else
{
- udd_verbose_print (_("File \"%s\" lacks MimeType key\n"),
- full_path);
+ g_debug (_("File \"%s\" lacks MimeType key\n"), full_path);
}
g_error_free (process_error);
@@ -352,7 +361,7 @@ print_desktop_dirs (const char **dirs)
char *directories;
directories = g_strjoinv (", ", (char **) dirs);
- udd_verbose_print(_("Search path is now: [%s]\n"), directories);
+ g_debug (_("Search path is now: [%s]\n"), directories);
g_free (directories);
}
@@ -396,6 +405,8 @@ main (int argc,
return 1;
}
+ g_log_set_default_handler (log_handler, NULL);
+
if (desktop_dirs == NULL || desktop_dirs[0] == NULL)
desktop_dirs = get_default_search_path ();
@@ -409,8 +420,7 @@ main (int argc,
if (error != NULL)
{
- udd_verbose_print (_("Could not create cache file in \"%s\": %s\n"),
- desktop_dirs[i], error->message);
+ g_warning (_("Could not create cache file in \"%s\": %s\n"), desktop_dirs[i], error->message);
g_error_free (error);
error = NULL;
}
@@ -424,8 +434,7 @@ main (int argc,
char *directories;
directories = g_strjoinv (", ", (char **) desktop_dirs);
- udd_print (_("The databases in [%s] could not be updated.\n"),
- directories);
+ g_warning (_("The databases in [%s] could not be updated.\n"), directories);
g_free (directories);