Skip to main content

OpenNetLogger

Struct OpenNetLogger 

Source
pub struct OpenNetLogger;
Expand description

Callback-only logging. The library does not print or persist log records.

Implementations§

Source§

impl OpenNetLogger

Source

pub fn register_log_listener( listener: LogListener, log_types: &[LogType], ) -> Result<LogSubscription>

Registers an independent subscription with a queue of 256 records.

Only explicitly listed origins are accepted, including for overflow reports. An empty type list is invalid. The returned handle must remain alive. Registration can fail if the callback thread cannot be created.

Source

pub fn register_log_listener_with_capacity( listener: LogListener, log_types: &[LogType], capacity: usize, ) -> Result<LogSubscription>

Registers a subscription with a bounded number of queued records.

Producers never wait for queue capacity. Overflow increments LogSubscription::dropped_count and is reported after the consumer resumes as a synthetic log_subscription_overflow record using the first listed origin.

Capacity must be in 1..=16_384. Zero, larger capacities and an empty type list return io::ErrorKind::InvalidInput before allocating the queue or starting the callback thread. The limit counts queued records, not their payload bytes or the total memory used by all subscriptions. Registration can also fail if the callback thread cannot be created.

Source

pub fn register_shared_log_listener( listener: SharedLogListener, options: LogSubscriptionOptions, ) -> Result<LogSubscription>

Registers a subscription sharing immutable records with other listeners.

Only configured origins and levels are delivered. Exported log macros skip content parameter evaluation when no subscription needs the origin/level; another listener (including a legacy listener accepting every level) may still require construction. Concurrent subscription changes can occur after this check. Legacy listeners receive owned records at delivery time and can still require a deep copy.

Producers never wait for queue space. Records exceeding a configured limit are dropped whole and counted by LogSubscription::drop_stats. A Debug log_subscription_overflow report can be delivered after a callback returns, using the first configured origin. It bypasses the queue but obeys the subscription’s level and single-record limit. A suppressed report does not create another drop; counters remain available independently.

Returns io::ErrorKind::InvalidInput before allocating a queue or starting a worker for empty origins, a capacity outside 1..=16_384, zero byte limits, or a single-record limit greater than the queued-byte limit. Registration can also fail if the callback thread cannot be created.

use open_net::{LogLevel, LogSubscriptionOptions, LogType, OpenNetLogger};
let subscription = OpenNetLogger::register_shared_log_listener(
    Box::new(|record| eprintln!("{}: {}", record.tag, record.content)),
    LogSubscriptionOptions::new(&[LogType::Engine, LogType::HTTP])
        .with_max_level(LogLevel::Warn),
)?;
// Keep the handle alive while logging is needed.
let oversized = subscription.drop_stats().oversized;
Source

pub fn clear_global_log_listener()

Clears all global subscriptions without waiting for callbacks in progress.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more