0

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?

parsley72
  • 8,449
  • 8
  • 65
  • 98

1 Answers1

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;
}
Community
  • 1
  • 1
parsley72
  • 8,449
  • 8
  • 65
  • 98