Config

Struct Config 

Source
pub struct Config { /* private fields */ }
Expand description

Configuration parameters for connecting to a Grafana Loki instance.

This struct follows the Builder Pattern, allowing you to specify metadata (labels) that will be attached to every log stream sent to Loki.

Only available when the loki feature is enabled.

§Example

let config = LokiConfig::new("[https://logs-prod-us-central1.grafana.net/loki/api/v1/push](https://logs-prod-us-central1.grafana.net/loki/api/v1/push)")
    .job("api-server")
    .app("billing-v2")
    .env("prod")
    .basic_auth(BasicAuth::some("12345", Some("your-api-key")))
    .worker_count(4);

let logger = LokiLogger::new(config);
let logger = Logger::new(logger);

Implementations§

Source§

impl Config

A network-based logging backend that pushes logs to Grafana Loki.

LokiService transforms internal Message objects into Loki’s JSON “Push” format. It uses a blocking HTTP client, which is intended to be executed within a dedicated background worker thread to avoid blocking the main application.

§Stream Labels

Every log sent via this service is tagged with the following labels:

  • job: The logical group (e.g., “logger-service”).
  • app: The specific application name.
  • env: The deployment environment (e.g., “production”, “dev”).
  • level: The severity of the log (automatically extracted from the message).
§Client Data
  • url: Base url for loki
  • connection_timeout: Connection timeout (how much time to wait for the connection to happen)
  • request_timeout: Request timeout (how much time to wait for the request’s response)
§Logger data:
  • max_retries: Maximum number of retries (only used in the LoggerFactory)
  • worker_count: Number of workers to use (only used in the LoggerFactory)
Source

pub fn new<S>(url: S) -> Self
where S: Into<String>,

Creates a new LokiConfig with default settings.

§Parameters
  • url: Base url for loki.
§Default Values:
Source

pub fn with_labels<S1, S2, S3, S4>(url: S1, app: S3, job: S2, env: S4) -> Self
where S1: Into<String>, S2: Into<String>, S3: Into<String>, S4: Into<String>,

Creates a new LokiConfig with customized labels default settings.

§Parameters
  • url: Base url for loki.
  • job: The logical group (e.g., “logger-service”).
  • app: The specific application name.
  • env: The deployment environment (e.g., “production”, “dev”).
  • level: The severity of the log (automatically extracted from the message).
§Default Values:
Source

pub fn get_url(&self) -> &str

Returns the destination Loki base URL.

Source

pub fn get_app(&self) -> &str

Returns the value of the app label.

Source

pub fn get_job(&self) -> &str

Returns the value of the job label.

Source

pub fn get_env(&self) -> &str

Returns the value of the env label.

Source

pub fn get_basic_auth(&self) -> Option<&BasicAuth>

Returns the Basic Authentication credentials if configured.

Source

pub fn get_bearer_auth(&self) -> Option<&str>

Returns the Bearer Token if configured.

Source

pub fn get_connection_timeout(&self) -> Duration

Returns the connection timeout duration.

Source

pub fn get_request_timeout(&self) -> Duration

Returns the request timeout duration.

Source

pub fn get_worker_count(&self) -> usize

Returns the number of background worker threads requested for this service.

Source

pub fn get_max_retries(&self) -> usize

Returns the maximum number of teries allowed for this service.

Source

pub fn url<S: Into<String>>(self, url: S) -> Self

Sets the destination Loki base URL (e.g., http://localhost:3100).

Source

pub fn app<S: Into<String>>(self, app: S) -> Self

Sets the app label to identify this specific application instance.

Source

pub fn job<S: Into<String>>(self, job: S) -> Self

Sets the job label used by Loki for indexing.

Source

pub fn env<S: Into<String>>(self, env: S) -> Self

Sets the env label used by Loki for indexing.

Source

pub fn worker_count(self, worker_count: usize) -> Self

Configures the number of parallel workers that should process logs for this service.

Source

pub fn max_retries(self, max_retries: usize) -> Self

Configures the number of maximum retries that the process should be attempted.

Source

pub fn basic_auth<BA>(self, basic_auth: Option<BA>) -> Self
where BA: Into<BasicAuth>,

Enables Basic Authentication for the Loki connection.

§Arguments
  • basic_auth Basic auth object representing the login credentials.
Source

pub fn bearer_auth<S>(self, token: Option<S>) -> Self
where S: Into<String>,

Enables Bearer Token authentication (e.g., JWT).

Source

pub fn connection_timeout<D: Into<Duration>>( self, connection_timeout: D, ) -> Self

Sets the connection timeout to try to log in loki.

Source

pub fn request_timeout<S: Into<Duration>>(self, request_timeout: S) -> Self

Sets the request timeout to try to log in loki.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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
§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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