pub struct GlobalLog { /* private fields */ }Expand description
The global logger/tracer for stdout, file and full open telemetry. Works with the tracing crates (info!, debug!, warn!, error!) and span funcs and decorators.
GlobalLog::meter is also provided to create metrics, these aren’t native to the tracing crate.
Unlike my other lang implementations, for file and stdout this uses a separate flow, they won’t use metrics and only receive basic span information. Simply because I did it first, plus the rust opentelemetry sdk is very new, so difficult to use and the benefit of handling file and stdout through otlp is minimal.
Open telemetry support is opinionated: unencrypted/uncompressed output to a local grpc port, the intention is this is a otpl collector sidecar.
Examples:
Kitchen sink:
use bitbazaar::logging::GlobalLog;
use tracing_subscriber::prelude::*;
use tracing::Level;
let temp_dir = tempfile::tempdir().unwrap();
let log = GlobalLog::builder()
.stdout(true, false)
.level_from(Level::DEBUG) // Debug and up for stdout, each defaults to INFO
.file("my_program.log", temp_dir)
.otlp(4317, "service-name", "0.1.0").level_from(Level::INFO)
.build().unwrap();
log.register_global()?; // Register it as the global sub, this can only be done onceImplementations§
source§impl GlobalLog
impl GlobalLog
sourcepub fn builder() -> GlobalLogBuilder
pub fn builder() -> GlobalLogBuilder
Create a builder to configure the global logger.
sourcepub fn setup_quick_stdout_global_logging(
level_from: Level,
) -> RResult<(), AnyErr>
pub fn setup_quick_stdout_global_logging( level_from: Level, ) -> RResult<(), AnyErr>
A managed wrapper on creation of the GlobalLog and registering it as the global logger.
Sets up console logging only. Should only be used for quick logging, as an example and testing.
sourcepub fn register_global(self) -> RResult<(), AnyErr>
pub fn register_global(self) -> RResult<(), AnyErr>
Register the logger as the global logger/tracer/metric manager, can only be done once during the lifetime of the program.
If you need temporary globality, use the GlobalLog::with_tmp_global method.
sourcepub fn set_span_parent_from_http_headers(
&self,
span: &Span,
headers: &HeaderMap,
) -> RResult<(), AnyErr>
pub fn set_span_parent_from_http_headers( &self, span: &Span, headers: &HeaderMap, ) -> RResult<(), AnyErr>
sourcepub fn set_response_headers_from_ctx<B>(
&self,
response: &mut Response<B>,
) -> RResult<(), AnyErr>
pub fn set_response_headers_from_ctx<B>( &self, response: &mut Response<B>, ) -> RResult<(), AnyErr>
sourcepub fn with_tmp_global<T>(&self, f: impl FnOnce() -> T) -> RResult<T, AnyErr>
pub fn with_tmp_global<T>(&self, f: impl FnOnce() -> T) -> RResult<T, AnyErr>
Temporarily make the logger global, for the duration of the given closure.
If you want to make the logger global permanently, use the GlobalLog::register_global method.
Auto Trait Implementations§
impl Freeze for GlobalLog
impl !RefUnwindSafe for GlobalLog
impl Send for GlobalLog
impl Sync for GlobalLog
impl Unpin for GlobalLog
impl !UnwindSafe for GlobalLog
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request