c++ - 如何让 g_print() 出现?

标签 c++ linux glib

我刚刚从离开公司的人那里继承了一个图书馆。它是用 C++ 编写的,并且在整个代码中都使用了 g_print()。我知道该库正在运行,但我看不到任何调试输出。我需要做些什么才能让它显示出来吗? g_print() 只在调试版本中起作用吗?还有其他建议吗?

最佳答案

我最终使用了 g_log (如上面 David Schwartz 所建议的),然后按照 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;
}

关于c++ - 如何让 g_print() 出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13732455/

相关文章:

linux - 如何在不更改 cd 的情况下更改 tcsh 中的目录 -

c - 通过 mmap 分配的内存没有 munmap 会在进程退出或终端后导致泄漏

c - 警告 : data definition has no type or storage class despite including header

c - GLib 哈希表 : Invalid free()

c++ - C++编译时关联数组

java - 在 python 和 java 中设置线程关联

c++ - 理解 C++11 中的正则表达式

c++ - 将 char* 数组作为字符串返回 -> 内存泄漏?

linux - Bugzilla 限制错误状态

python - 在 Python 中,字符串序列到底是什么? (或者 Glib 错误?)