Skip to main content

StructuredLogWriter

Struct StructuredLogWriter 

Source
pub struct StructuredLogWriter { /* private fields */ }
Expand description

结构化日志器:支持结构化字段、target 过滤与多 sink 输出。

结合 LevelFilterLogSink,提供生产级日志能力:

  1. 按 target 过滤日志级别
  2. 记录结构化字段
  3. 扇出到多个输出后端

Implementations§

Source§

impl StructuredLogWriter

Source

pub fn new(filter: LevelFilter) -> Self

创建结构化日志写入器

Source

pub fn add_sink(&mut self, sink: Arc<dyn StructuredSink>) -> &mut Self

添加结构化 sink

Source

pub fn sink_count(&self) -> usize

获取 sink 数量

Source

pub fn sink_names(&self) -> Vec<String>

获取 sink 名称列表

Source

pub fn filter(&self) -> &LevelFilter

获取级别过滤器引用

Source

pub fn filter_mut(&mut self) -> &mut LevelFilter

获取级别过滤器可变引用

Source

pub fn log(&self, entry: &StructuredLogEntry)

记录一条结构化日志。

根据 target 通过 LevelFilter 过滤后扇出到所有 sink。 target 为 None 时使用默认级别。

Source

pub fn log_with_fields( &self, target: impl Into<String>, level: LogLevel, message: impl Into<String>, fields: StructuredFields, )

便捷方法:记录一条带 target 和字段的日志

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, 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.