Skip to content

Commit a0c0dbf

Browse files
committed
address comments
1 parent dca0e22 commit a0c0dbf

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

opentelemetry-sdk/src/logs/log_emitter.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@ use opentelemetry::logs::Severity;
1616
use std::sync::atomic::AtomicBool;
1717
use std::{borrow::Cow, sync::Arc};
1818

19-
use lazy_static::lazy_static;
20-
21-
lazy_static! {
22-
// a no nop logger provider used as placeholder when the provider is shutdown
23-
static ref NOOP_LOGGER_PROVIDER: LoggerProvider = LoggerProvider {
24-
inner: Arc::new(LoggerProviderInner {
25-
processors: Vec::new(),
26-
config: Config::default(),
27-
}),
28-
is_shutdown: Arc::new(AtomicBool::new(true)),
29-
};
30-
}
19+
use once_cell::sync::Lazy;
20+
21+
// a no nop logger provider used as placeholder when the provider is shutdown
22+
static NOOP_LOGGER_PROVIDER: Lazy<LoggerProvider> = Lazy::new(|| LoggerProvider {
23+
inner: Arc::new(LoggerProviderInner {
24+
processors: Vec::new(),
25+
config: Config::default(),
26+
}),
27+
is_shutdown: Arc::new(AtomicBool::new(true)),
28+
});
3129

3230
#[derive(Debug, Clone)]
3331
/// Creator for `Logger` instances.

opentelemetry/src/logs/logger.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::{borrow::Cow, sync::Arc};
22

3-
use crate::{logs::{LogRecord, LogResult}, InstrumentationLibrary, InstrumentationLibraryBuilder, KeyValue};
3+
use crate::{
4+
logs::{LogRecord, LogResult},
5+
InstrumentationLibrary, InstrumentationLibraryBuilder, KeyValue,
6+
};
47

58
#[cfg(feature = "logs_level_enabled")]
69
use super::Severity;
@@ -114,6 +117,15 @@ pub trait LoggerProvider {
114117
fn logger(&self, name: impl Into<Cow<'static, str>>) -> Self::Logger {
115118
self.logger_builder(name).build()
116119
}
120+
121+
/// Shuts down this `LoggerProvider`
122+
/// After shutdown the logger provider cannot be used to create new loggers.
123+
/// The implementation should propagate the shutdown signal down to ensure no new logs are emitted.
124+
/// Shutdown the logger provider. Noop logger will be returned after shutdown.
125+
///
126+
/// Note that `shutdown` doesn't mean `Drop`(though `Drop` can call `shutdown`).
127+
/// It simply means the provider will emit anything in the buffer(if applicable) and stop processing
128+
fn shutdown(&self) -> Vec<LogResult<()>>;
117129
}
118130

119131
#[derive(Debug)]
@@ -145,10 +157,4 @@ impl<'a, T: LoggerProvider + ?Sized> LoggerBuilder<'a, T> {
145157
self.provider
146158
.library_logger(Arc::new(self.library_builder.build()))
147159
}
148-
149-
/// Shutdown the logger provider. Noop logger will be returned after shutdown.
150-
///
151-
/// Note that `shutdown` doesn't mean `Drop`(though `Drop` can call `shutdown`).
152-
/// It simply means the provider will emit anything in the buffer(if applicable) and stop processing
153-
fn shutdown(&self) -> Vec<LogResult<()>>;
154160
}

0 commit comments

Comments
 (0)