How to obtain the log from the GST source code through adb logcat?

A small question, how to obtain the log from the GST source code through adb logcat , such as GST_ ERROR, GST_ ERROR_ OBJECT、GST_WARNING_OBJECT and so on.

BRs,
Nancy

#include <gst/gst.h>
#include <iostream>
#include <fstream>

// Custom log handler function
static void on_gst_log(GstDebugCategory *category,
                       GstDebugLevel level,
                       const gchar *file,
                       const gchar *function,
                       gint line,
                       GObject *object,
                       GstDebugMessage *message,
                       gpointer user_data) {
    // Log GStreamer messages to a file
    std::ofstream log_file("gstreamer_log.txt", std::ios::app);
    log_file << "GStreamer Message: " << gst_debug_message_get(message) << std::endl;
}

int main(int argc, char *argv[]) {
    // Redirect stderr to a log file
    freopen("gstreamer_log.txt", "a", stderr);

    // Initialize GStreamer
    gst_init(&argc, &argv);

    // Set up the custom log handler
    GstDebugCategory *debug_category = gst_debug_category_get("your-app-name");
    gst_debug_category_set_threshold(debug_category, GST_LEVEL_DEBUG);
    gst_debug_add_log_function(debug_category, on_gst_log, nullptr);

    // Create and set up your GStreamer pipeline or element here...

    // Run the GStreamer main loop
    GMainLoop *main_loop = g_main_loop_new(nullptr, FALSE);
    g_main_loop_run(main_loop);

    // Clean up resources
    gst_debug_remove_log_function(debug_category, on_gst_log);
    gst_main_quit();

    return 0;
}

If you are using a recent enough GStreamer, then the GStreamer debug log is written to logcat automatically with this code: subprojects/gstreamer/gst/gstandroid.c · main · GStreamer / gstreamer · GitLab

If you set the relevant GStreamer debug categories using the gst_debug_set_threshold* family of functions, then you will be able see GStreamer debug logging from adb logcat.

Hi Joe & ystreet00,

Thank you for your help.

I have got all gst log by adb with gst_debug_set_default_threshold();
But thank you all the same !

BRs,
Nancy