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§
Required Methods§
sourcefn logger_with_scope(&self, scope: InstrumentationScope) -> Self::Logger
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§
Object Safety§
This trait is not object safe.