Trait opentelemetry::logs::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. If the name is empty, then an implementation-defined default name may be used instead.

Object Safety§

This trait is not object safe.

Implementors§