Struct LogContext

Source
pub struct LogContext(/* private fields */);
Expand description

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

⚠️ The following code is in c ⚠️

// 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):

⚠️ The following code is in c ⚠️

// 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:

⚠️ The following code is in c ⚠️

// 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);
);

Implementations§

Source§

impl LogContext

Source

pub fn category(&self) -> DebugCategory

Get the DebugCategory associated with this log context.

§Returns

the DebugCategory to which the context is bound

Source

pub fn reset(&self)

Resets the logging context, clearing all tracked messages.

Source

pub fn as_ptr(&self) -> *mut GstLogContext

Source

pub fn log( &self, obj: Option<&impl IsA<Object>>, level: DebugLevel, file: &GStr, function: &str, line: u32, args: Arguments<'_>, )

Source

pub fn log_literal( &self, obj: Option<&impl IsA<Object>>, level: DebugLevel, file: &GStr, function: &str, line: u32, msg: &GStr, )

Source

pub fn log_id( &self, id: impl AsRef<GStr>, level: DebugLevel, file: &GStr, function: &str, line: u32, args: Arguments<'_>, )

Source

pub fn log_id_literal( &self, id: impl AsRef<GStr>, level: DebugLevel, file: &GStr, function: &str, line: u32, msg: &GStr, )

Trait Implementations§

Source§

impl Debug for LogContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DebugLogger for LogContext

Source§

fn log_id_literal_unfiltered( &self, id: impl AsRef<GStr>, level: DebugLevel, file: &GStr, function: &str, line: u32, msg: &GStr, )

Logs without checking the log level.

Source§

fn above_threshold(&self, level: DebugLevel) -> bool

Source§

fn log_unfiltered( &self, obj: Option<&impl IsA<Object>>, level: DebugLevel, file: &GStr, function: &str, line: u32, args: Arguments<'_>, )

Source§

fn log_literal_unfiltered( &self, obj: Option<&impl IsA<Object>>, level: DebugLevel, file: &GStr, function: &str, line: u32, msg: &GStr, )

Source§

fn log_id_unfiltered( &self, id: impl AsRef<GStr>, level: DebugLevel, file: &GStr, function: &str, line: u32, args: Arguments<'_>, )

Source§

impl Drop for LogContext

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for LogContext

Source§

impl Sync for LogContext

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.