c++logginggstreamerlog4cplus

How to redirect gstreamer debug information to a logging library


I have gstreamer pipelines running in my C++ application. To check problems relative to those, I enable printing debug information by setting the variable GST_DEBUG as explained on this page : https://gstreamer.freedesktop.org/documentation/tutorials/basic/debugging-tools.html?gi-language=c. However, this prints directly on cout and I use a logging library (log4cplus) in my application. As gstreamer debug information is divided in categories very similar to the ones in log4cplus (error, warn, debug, etc.), I expected it would be possible to redirect those messages in my logger but I cannot find any information on how to do it.

I used the Qt framework before, and it has a function 'qInstallMessageHandler' which enables redirecting qt logs to a custom logger. Does gstreamer have anything like that?


Solution

  • I have no experience with this but it looks like you can register a C function that will get called by the Gstreamer framework when it logs.

    static void gst_log_handler(GstDebugCategory *category,
        GstDebugLevel level, const gchar *file, const gchar *function,
        gint line, GObject *object, GstDebugMessage *message, gpointer user_data) {
        // Convert into log4cplus::spi::InternalLoggingEvent and log it.
    }
    
    // Somewhere else then register it:
    gst_debug_add_log_function(debug_category, gst_log_handler, nullptr);