I've just inherited a library from someone who left the company. It's written in C++ and g_print() is used throughout the code. I know the library is running but I can't see any debug output. Is there something I need to do to get it to show up? Does g_print() only work in debug builds? Any other suggestions?
Asked
Active
Viewed 3,478 times
0
-
I thought it was part of glib? http://developer.gnome.org/glib/2.31/glib-Warnings-and-Assertions.html#g-print – parsley72 Dec 05 '12 at 21:11
-
1Is `g_print` only used for debugging output? If so, change it to `g_message`. (Or, if you have the time, to `g_log`.) – David Schwartz Dec 05 '12 at 21:12
-
@parsley72: Oops -- I missed the `glib` tag. Sorry 'bout that. – Jerry Coffin Dec 05 '12 at 21:16
1 Answers
1
I ended up using g_log (as suggested by David Schwartz above) then overriding it as specified in C - gtk Logging overriding:
void log_handler(const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer user_data)
{
FILE *logfile = fopen ("/tmp/debug.log", "a");
if (logfile == NULL)
{
/* Fall back to console output if unable to open file */
printf ("Rerouted to console: %s", message);
return;
}
fprintf (logfile, "%s", message);
fclose (logfile);
}
uint handlerid = g_log_set_handler(NULL,
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
log_handler,
NULL);
if (!g_main_loop_is_running())
{
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, "g_main_loop_is_running() returned 0\n");
}
if (handlerid != 0)
{
g_log_remove_handler(NULL, handlerid);
handlerid = 0;
}