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.
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 lokiconnection_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 theLoggerFactory)worker_count: Number of workers to use (only used in theLoggerFactory)
Sourcepub fn new<S>(url: S) -> Self
pub fn new<S>(url: S) -> Self
Creates a new LokiConfig with default settings.
§Parameters
url: Base url for loki.
§Default Values:
- App:
LOKI_DEFAULT_APP - Job:
LOKI_DEFAULT_JOB - Env:
LOKI_DEFAULT_ENV - Workers:
LOKI_DEFAULT_WORKERS - Connection timeout:
LOKI_DEFAULT_CONNECTION_TIMEOUT - Request timeout:
LOKI_DEFAULT_REQUEST_TIMEOUT - Maximum retries:
LOKI_DEFAULT_RETRIES
Sourcepub fn with_labels<S1, S2, S3, S4>(url: S1, app: S3, job: S2, env: S4) -> Self
pub fn with_labels<S1, S2, S3, S4>(url: S1, app: S3, job: S2, env: S4) -> Self
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:
- Workers:
LOKI_DEFAULT_WORKERS - Connection timeout:
LOKI_DEFAULT_CONNECTION_TIMEOUT - Request timeout:
LOKI_DEFAULT_REQUEST_TIMEOUT - Maximum retries:
LOKI_DEFAULT_RETRIES
Sourcepub fn get_basic_auth(&self) -> Option<&BasicAuth>
pub fn get_basic_auth(&self) -> Option<&BasicAuth>
Returns the Basic Authentication credentials if configured.
Sourcepub fn get_bearer_auth(&self) -> Option<&str>
pub fn get_bearer_auth(&self) -> Option<&str>
Returns the Bearer Token if configured.
Sourcepub fn get_connection_timeout(&self) -> Duration
pub fn get_connection_timeout(&self) -> Duration
Returns the connection timeout duration.
Sourcepub fn get_request_timeout(&self) -> Duration
pub fn get_request_timeout(&self) -> Duration
Returns the request timeout duration.
Sourcepub fn get_worker_count(&self) -> usize
pub fn get_worker_count(&self) -> usize
Returns the number of background worker threads requested for this service.
Sourcepub fn get_max_retries(&self) -> usize
pub fn get_max_retries(&self) -> usize
Returns the maximum number of teries allowed for this service.
Sourcepub fn url<S: Into<String>>(self, url: S) -> Self
pub fn url<S: Into<String>>(self, url: S) -> Self
Sets the destination Loki base URL (e.g., http://localhost:3100).
Sourcepub fn app<S: Into<String>>(self, app: S) -> Self
pub fn app<S: Into<String>>(self, app: S) -> Self
Sets the app label to identify this specific application instance.
Sourcepub fn job<S: Into<String>>(self, job: S) -> Self
pub fn job<S: Into<String>>(self, job: S) -> Self
Sets the job label used by Loki for indexing.
Sourcepub fn env<S: Into<String>>(self, env: S) -> Self
pub fn env<S: Into<String>>(self, env: S) -> Self
Sets the env label used by Loki for indexing.
Sourcepub fn worker_count(self, worker_count: usize) -> Self
pub fn worker_count(self, worker_count: usize) -> Self
Configures the number of parallel workers that should process logs for this service.
Sourcepub fn max_retries(self, max_retries: usize) -> Self
pub fn max_retries(self, max_retries: usize) -> Self
Configures the number of maximum retries that the process should be attempted.
Sourcepub fn basic_auth<BA>(self, basic_auth: Option<BA>) -> Self
pub fn basic_auth<BA>(self, basic_auth: Option<BA>) -> Self
Enables Basic Authentication for the Loki connection.
§Arguments
basic_authBasic auth object representing the login credentials.
Sourcepub fn bearer_auth<S>(self, token: Option<S>) -> Self
pub fn bearer_auth<S>(self, token: Option<S>) -> Self
Enables Bearer Token authentication (e.g., JWT).
Sourcepub fn connection_timeout<D: Into<Duration>>(
self,
connection_timeout: D,
) -> Self
pub fn connection_timeout<D: Into<Duration>>( self, connection_timeout: D, ) -> Self
Sets the connection timeout to try to log in loki.
Sourcepub fn request_timeout<S: Into<Duration>>(self, request_timeout: S) -> Self
pub fn request_timeout<S: Into<Duration>>(self, request_timeout: S) -> Self
Sets the request timeout to try to log in loki.
Trait Implementations§
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> 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more