opentelemetry::logs

Trait LoggerProvider

Source
pub trait LoggerProvider {
    type Logger: Logger;

    // Required method
    fn logger_with_scope(&self, scope: InstrumentationScope) -> Self::Logger;

    // Provided method
    fn logger(&self, name: impl Into<Cow<'static, str>>) -> Self::Logger { ... }
}
Expand description

Interfaces that can create Logger instances.

Required Associated Types§

Source

type Logger: Logger

The Logger type that this provider will return.

Required Methods§

Source

fn logger_with_scope(&self, scope: InstrumentationScope) -> Self::Logger

Returns a new logger with the given instrumentation scope.

§Examples
use opentelemetry::InstrumentationScope;
use opentelemetry::logs::LoggerProvider;
use opentelemetry_sdk::logs::LoggerProvider as SdkLoggerProvider;

let provider = SdkLoggerProvider::builder().build();

// logger used in applications/binaries
let logger = provider.logger("my_app");

// logger used in libraries/crates that optionally includes version and schema url
let scope = InstrumentationScope::builder(env!("CARGO_PKG_NAME"))
    .with_version(env!("CARGO_PKG_VERSION"))
    .with_schema_url("https://opentelemetry.io/schema/1.0.0")
    .build();

let logger = provider.logger_with_scope(scope);

Provided Methods§

Source

fn logger(&self, name: impl Into<Cow<'static, str>>) -> Self::Logger

Returns a new logger with the given name.

The name should be the application name or the name of the library providing instrumentation.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§