opentelemetry::logs

Trait LoggerProvider

source
pub trait LoggerProvider {
    type Logger: Logger;

    // Required method
    fn library_logger(
        &self,
        library: Arc<InstrumentationLibrary>,
    ) -> Self::Logger;

    // Provided methods
    fn versioned_logger(
        &self,
        name: impl Into<Cow<'static, str>>,
        version: Option<Cow<'static, str>>,
        schema_url: Option<Cow<'static, str>>,
        attributes: Option<Vec<KeyValue>>,
    ) -> Self::Logger { ... }
    fn logger_builder(
        &self,
        name: impl Into<Cow<'static, str>>,
    ) -> LoggerBuilder<'_, Self> { ... }
    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 library_logger(&self, library: Arc<InstrumentationLibrary>) -> Self::Logger

Returns a new versioned logger with the given instrumentation library.

§Examples
use opentelemetry::InstrumentationLibrary;
use crate::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 library = std::sync::Arc::new(
    InstrumentationLibrary::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.library_logger(library);

Provided Methods§

source

fn versioned_logger( &self, name: impl Into<Cow<'static, str>>, version: Option<Cow<'static, str>>, schema_url: Option<Cow<'static, str>>, attributes: Option<Vec<KeyValue>>, ) -> Self::Logger

👎Deprecated since 0.23.0: Please use logger_builder() instead

Deprecated, use LoggerProvider::logger_builder()

Returns a new versioned logger with a 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. Create a new versioned Logger instance.

source

fn logger_builder( &self, name: impl Into<Cow<'static, str>>, ) -> LoggerBuilder<'_, Self>

Returns a new builder for creating a Logger instance

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.

§Examples
use opentelemetry::InstrumentationLibrary;
use crate::opentelemetry::logs::LoggerProvider;
use opentelemetry_sdk::logs::LoggerProvider as SdkLoggerProvider;

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

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

// logger used in libraries/crates that optionally includes version and schema url
let logger = provider.logger_builder("my_library")
    .with_version(env!("CARGO_PKG_VERSION"))
    .with_schema_url("https://opentelemetry.io/schema/1.0.0")
    .build();
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§