Skip to content
Snippets Groups Projects
Commit 738b88aa authored by George Kiagiadakis's avatar George Kiagiadakis
Browse files

debug: randomize object printout colors

This way we can more easily distinguish different objects when
looking at the log, although it's not perfect
parent 2c1df41a
No related branches found
No related tags found
No related merge requests found
...@@ -48,7 +48,13 @@ struct common_fields ...@@ -48,7 +48,13 @@ struct common_fields
/* our palette */ /* our palette */
#define DOMAIN_COLOR COLOR_MAGENTA #define DOMAIN_COLOR COLOR_MAGENTA
#define LOCATION_COLOR COLOR_BLUE #define LOCATION_COLOR COLOR_BLUE
#define OBJECT_COLOR COLOR_YELLOW
/* available colors for object printouts (the <Object:0xfoobar>) */
static const gchar *object_colors[] = {
COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_MAGENTA, COLOR_CYAN,
COLOR_BRIGHT_RED, COLOR_BRIGHT_GREEN, COLOR_BRIGHT_YELLOW,
COLOR_BRIGHT_MAGENTA, COLOR_BRIGHT_CYAN
};
/* /*
* priority numbers are based on GLib's gmessages.c * priority numbers are based on GLib's gmessages.c
...@@ -173,8 +179,14 @@ write_debug_message (FILE *s, struct common_fields *cf) ...@@ -173,8 +179,14 @@ write_debug_message (FILE *s, struct common_fields *cf)
static inline gchar * static inline gchar *
format_message (struct common_fields *cf) format_message (struct common_fields *cf)
{ {
const gchar *object_color = "";
if (use_color) {
guint h = g_direct_hash (cf->object) % G_N_ELEMENTS (object_colors);
object_color = object_colors[h];
}
return g_strdup_printf ("%s<%s%s%p>%s %s", return g_strdup_printf ("%s<%s%s%p>%s %s",
use_color ? OBJECT_COLOR : "", object_color,
cf->object_type != 0 ? g_type_name (cf->object_type) : "", cf->object_type != 0 ? g_type_name (cf->object_type) : "",
cf->object_type != 0 ? ":" : "", cf->object_type != 0 ? ":" : "",
cf->object, cf->object,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment