LogContext#

Added in version 1.28.

class LogContext(*args, **kwargs)#

A context for controlling logging behavior, for example to handle logging once or periodic logging, avoiding to spam the terminal with the same log message multiple times.

Simple log context using static macros#

// At global/file scope:
GST_LOG_CONTEXT_STATIC_DEFINE(my_context, GST_LOG_CONTEXT_FLAG_THROTTLE, );
#define MY_CONTEXT GST_LOG_CONTEXT_LAZY_INIT(my_context)

// Then in code:
GST_CTX_INFO(MY_CONTEXT, "This will only appear once per file/line");

Periodic logging#

For messages that should be logged periodically (e.g., maximum once per minute):

// At global/file scope:
GST_LOG_CONTEXT_STATIC_DEFINE(my_periodic_context, GST_LOG_CONTEXT_FLAG_THROTTLE,
  GST_LOG_CONTEXT_BUILDER_SET_INTERVAL(60 * GST_SECOND);
);
#define MY_PERIODIC_CONTEXT GST_LOG_CONTEXT_LAZY_INIT(my_periodic_context)

// Then in code:
GST_CTX_INFO(MY_PERIODIC_CONTEXT, "This appears once per minute");

Customizing Message hash with custom flags and category#

By default, a message’s hash is determined by the file name, object pointer, and format string. You can customize this with builder operations:

// Ignore the object pointer when determining message hash (with throttling)
GST_LOG_CONTEXT_STATIC_DEFINE(obj_independent_ctx, GST_LOG_CONTEXT_FLAG_THROTTLE,
  GST_LOG_CONTEXT_BUILDER_SET_HASH_FLAGS(GST_LOG_CONTEXT_IGNORE_OBJECT);
);

// Use a custom category (without throttling)
GST_LOG_CONTEXT_STATIC_DEFINE(custom_cat_ctx, GST_LOG_CONTEXT_FLAG_NONE,
  GST_LOG_CONTEXT_BUILDER_SET_CATEGORY(my_category);
);

Methods#

class LogContext
free() None#

Free the logging context, clearing all tracked messages.

Added in version 1.28.

reset() None#

Resets the logging context, clearing all tracked messages.

Added in version 1.28.