Struct Builder

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

Builder for the Logger

Implementations§

Source§

impl Builder

Source

pub fn new(log_name: &str, resource_type: &str) -> Self

Creates a Builder object.

§Parameters
  • log_name: The logName string to be used in the LogEntry
  • resource_type: The required type field set in the resource MonitoredResource object of the LogEntry. For example: k8s_container.
§Example
use slog_google::logger::Builder;
let (drain, _) = Builder::new(
    "projects/my-gcp-project/logs/my-log-id",
    "k8s_container",
)
.build();
Source

pub fn with_resource_labels(self, labels: Value) -> Result<Self, Box<dyn Error>>

Sets resource labels to be applied.

These labels will populate the labels field in the resource MonitoredResource object of the LogEntry.

§Example
use serde_json::json;
let resource_labels = json!(
{
    "pod_name": "dummy-value",
    "location": "europe-west1-b",
    "pod_name": std::env::var("HOSTNAME").unwrap_or_default(),
    "container_name": "my-app",
    "project_id": "my-gcp-project",
    "cluster_name": "my-gke-cluster",
    "namespace_name": "my-gke-namespace"
});

use slog_google::logger::Builder;
let (drain, _) = Builder::new(
    "projects/my-gcp-project/logs/my-log-id",
    "k8s_container",
)
.with_resource_labels(resource_labels)
.unwrap()
.build();
§Errors

Will return Err if labels does not parse as JSON.

Source

pub fn with_default_labels(self, labels: Value) -> Result<Self, Error>

Sets default labels to be applied in the labels field.

These will populate the labels top level field of the LogEntry. These labels are added in addition to any labels set in the logger statement.

§Example
use serde_json::json;
let default_labels = json!(
{
    "application": "my-application",
    "team": "my-team",
    "version": "my-app-version",
    "role": "my-app-role",
    "environment": "production",
    "platform": "gcp",
});
§Errors

Will return Err if labels does not parse as JSON.

Source

pub fn with_log_level_label(self, log_level_label: &str) -> Self

Sets the label name to store the log level

If set, the log level value is added under this label the labels top level field of the LogEntry

If not set, the log level is not propagated, but you will still have the severity, which is always there.

Source

pub fn build(self) -> (Logger, Receiver<WriteLogEntriesRequest>)

This returns a tuple with a Logger, which can be passed to the slog root logger as usual, and a std::sync::mpsc::Receiver channel. The Logger sends the WriteLogEntries it creates to this channel.

For instance you could output these to the console, if you have an external agent that reads the process’ output and ships it to Google Logging.

Trait Implementations§

Source§

impl Debug for Builder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Builder

Source§

fn default() -> Builder

Returns the “default value” for a type. Read more

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> 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> PolicyExt for T
where T: ?Sized,

Source§

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

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> SendSyncUnwindSafe for T
where T: Send + Sync + UnwindSafe + ?Sized,