Gstreamer custom log

Gstreamer log introduce



一、gstreamer debug log介绍

  • gstreamer default log
    gstreamer 默认日志框架包含时间戳、进程ID、线程ID、日志等级、类型、文件名、源码行数、函数名、消息对象、消息等。示例如下:

0:00:00.868050000 1592 09F62420 WARN filesrc gstfilesrc.c:1044:gst_file_src_start: error: No such file “non-existing-file.webm”

  • gstreamer log level
    级别0:不输出任何日志信息。
    级别1:ERROR信息。
    级别2:WARNING信息。
    级别3:FIXME信息。
    级别4:INFO信息。
    级别5:DEBUG信息
    级别6:LOG信息。
    级别7:TRACE信息。
    级别8:MEMDUMP信息,最高级别日志
  • gstreamer log 设置
    使用时将GST_DEBUG设置相应级别,多模块以","隔开,支持“”通配符。
    ex: GST_DEBUG=2 或 GST_DEBUG=
    :2 打印ERRIR和WARNING级别log
    GST_DEBUG=2,audio*:6 以audio开始模块日志级别6,其他默认2.
    GST_DEBUG_FILE=/data/gst.log GST_DEBU_COLOR_MODE=off GST_DEBUG=3, v4l2*:6 日志写入文件输出,禁用色彩,v4l2开头的模块输出6等级日志,其他输出3等级日志。

二、Gstreamer debug log 初始化

1.gstreamer log初始化flow

gstreamer system log init flowGST_DEBUG_OBJECT() → GST_CAT_LEVEL_LOG() → gst_debug_log() → gst_debug_log_valist() → __log_functions
LogfuncEntry结构体中定义了log func,在执行GST_DEBUG_OBJECT()进行打印时,会指向初始化时链表中注册的debug log functions,进而执行对应functions,按照定义的格式打印log.
gstreamer 默认会注册gst_debug_log_default,即原生的log框架. 通过gst_debug_add_log_function来添加自定义log function,gst_debug_remove_log_function来移除默认的log function。

/* all registered debug handlers */
typedef struct
{
  GstLogFunction func;
  gpointer user_data;
  GDestroyNotify notify;
}
LogFuncEntry;

2.gstreamer default output log format

gstreamer_debug_log_default 位于…/gstreamer-1.0/gst/Gstinfo.c,定义日志输出格式。

#define PRINT_FMT " "PID_FMT" "PTR_FMT" %s "CAT_FMT" %s\n"
    fprintf (log_file, "%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
        pid, g_thread_self (), gst_debug_level_get_name (level),
        gst_debug_category_get_name (category), file, line, function, obj,
        gst_debug_message_get (message));
    fflush (log_file);

时间戳格式:"0:00:00.868050000"格式输出时,分,秒,纳秒。
日志等级:调用gst_debug_level_get_name(),默认输出0-9等级,可以在其中自定义等级。
类别:调用gst_debug_category_get_name(),获取日志类别,gstreamer预留了自定义类别接口。

三、Gstreamer custom log

  • using custom log category
    使用gstreamer 提供的日志系统,由gstreamer框架统一管理日志,但可以通过接口定义我们自己的类目,灵活debug。

    1. 首先需要自定义我们的log category
      GST_DEBUG_CATEGORY_STATIC (my_category);
      #define GST_CAT_DEFAULT my_category
      
    2. 在Gstreamer 初始化gst_init()之后,使用GST_DEBUG_CATEGORY_INIT(cat,name,color,description)注册一个新的类别。
      GST_DEBUG_CATEGORY_INIT (my_category, "my category", 0, "This is my very own");
      
  • add custom system log
    实际开发使用gstreamer时,有需要扩充log信息或者添加删除某些log category的需求。gstreamer 提供了接口,可以覆盖gstreamer 默认的系统log

    1. 如何自定义gstreamer system log
      在应用程序初始化前先使用该接口注册自定义log,func为自定义的log,初始化时会覆盖gstreamer_debug_log_default;user_data可指定输出到默认当前控制台或者FILE中。
      初始化之后需要移除系统默认的log func,即可按照我们自定义的log框架输出log。

      gst_debug_add_log_function ( GstLogFunction func,
                           gpointer user_data,
                           GDestroyNotify notify)
      
    2. 完整示例

      /* declare log function*/
      static void Mtk_Gst_log_func(GstDebugCategory * category,
                                             GstDebugLevel level,
                                             const gchar * file,
                                             const gchar * function,
                                             gint line,
                                             GObject * object,
                                             GstDebugMessage * message,
                                             gpointer user_data) {
         /* Add STC log Info, the print is in the same format as the kernel time */
         struct timespec time1={0,0};
         clock_gettime(CLOCK_MONOTONIC, &time1);
              
         printf("MTK_GST_LOG: [%ld.%ld][Level:%d] %s:%s:%d  %s\n",
         time1.tv_sec,time1_nsec,level, file, function, line,
         gst_debug_message_get(message));
      }
      
      int main()
      {
      ...
      /* set log function and remove the default one */
      gst_debug_add_log_function(Mtk_Gst_log_func, NULL, NULL);
      gst_debug_set_active(TRUE);
      gst_debug_set_default_threshold(GST_LEVEL_INFO);
      /* Initialize GStreamer */
      gst_init (&argc, &argv);
      /* default log function is added by gst_init, so we need remove it after that. */
      gst_debug_remove_log_function(gst_debug_log_default);
      ...
      }
      
    3. 执行结果
      MTK_GST_LOG: [STC] [log_level] File Func:line Msg


总结

本文介绍了gstreamer log的等级,如何设置不同的log level,以及自定义gstreamer log如何实现。

  • 42
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值