forked from open-telemetry/opentelemetry-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.rs
52 lines (46 loc) · 1.9 KB
/
logger.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::borrow::Cow;
use crate::{logs::LogRecord, KeyValue};
/// The interface for emitting [`LogRecord`]s.
pub trait Logger {
/// Emit a [`LogRecord`]. If this `Logger` was created with
/// `include_trace_context` set to `true`, the logger will set the record's
/// [`TraceContext`] to the active trace context, using the current thread's
/// [`Context`].
///
/// [`Context`]: crate::Context
/// [`TraceContext`]: crate::logs::TraceContext
fn emit(&self, record: LogRecord);
}
/// Interfaces that can create [`Logger`] instances.
pub trait LoggerProvider {
/// The [`Logger`] type that this provider will return.
type Logger;
/// 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.
///
/// If `include_trace_context` is `true`, the newly created [`Logger`]
/// should set the [`TraceContext`] associated with a record to the
/// current thread's active trace context, using [`Context`].
///
/// [`Context`]: crate::Context
/// [`TraceContext`]: crate::logs::TraceContext
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>>,
include_trace_context: bool,
) -> 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.
fn logger(&self, name: impl Into<Cow<'static, str>>) -> Self::Logger {
self.versioned_logger(name, None, None, None, true)
}
}