Struct bitbazaar::log::GlobalLog

source ·
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 once

Implementations§

source§

impl GlobalLog

source

pub fn builder() -> GlobalLogBuilder

Create a builder to configure the global logger.

source

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.

source

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.

source

pub fn meter( &self, name: impl Into<Cow<'static, str>>, ) -> RResult<Meter, AnyErr>

source

pub fn set_span_parent_from_http_headers( &self, span: &Span, headers: &HeaderMap, ) -> RResult<(), AnyErr>

source

pub fn set_response_headers_from_ctx<B>( &self, response: &mut Response<B>, ) -> RResult<(), AnyErr>

source

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.

source

pub fn flush(&self) -> RResult<(), AnyErr>

source

pub fn shutdown(&mut self) -> RResult<(), AnyErr>

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FutureExt for T

source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more