GoogleCloudLoggingLayout

Struct GoogleCloudLoggingLayout 

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

A layout for Google Cloud Structured Logging.

See the Google documentation for more information about the structure of the format.

Example format:

{"severity":"INFO","timestamp":"2025-04-02T10:34:33.225602Z","message":"Hello label value!","logging.googleapis.com/labels":{"label1":"this is a label value"},"logging.googleapis.com/trace":"projects/project-id/traces/612b91406b684ece2c4137ce0f3fd668", "logging.googleapis.com/sourceLocation":{"file":"examples/google_cloud_logging","line":64,"function":"main"}}

If the trace project ID is set, a few keys are treated specially:

  • trace_id: Combined with trace project ID, set as the logging.googleapis.com/trace field.
  • span_id: Set as the logging.googleapis.com/spanId field.
  • trace_sampled: Set as the logging.googleapis.com/trace_sampled field.

Information may be stored either in the payload, or as labels. The payload allows a structured value to be stored, but is not indexed by default. Labels are indexed by default, but can only store strings.

§Examples

use logforth_layout_google_cloud_logging::GoogleCloudLoggingLayout;

let layout = GoogleCloudLoggingLayout::default();

Implementations§

Source§

impl GoogleCloudLoggingLayout

Source

pub fn trace_project_id(self, project_id: impl Into<String>) -> Self

Set the trace project ID for traces.

If set, the trace_id, span_id, and trace_sampled fields will be set in the log record, in such a way that they can be linked to traces in the Google Cloud Trace service.

§Examples
use logforth_layout_google_cloud_logging::GoogleCloudLoggingLayout;

let layout = GoogleCloudLoggingLayout::default().trace_project_id("project-id");
Source

pub fn label_keys( self, label_keys: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Extend the set of keys that should be treated as labels.

Any key found in a log entry, and referenced here, will be stored in the labels field rather than the payload. Labels are indexed by default, but can only store strings.

§Examples
use logforth_layout_google_cloud_logging::GoogleCloudLoggingLayout;

let layout = GoogleCloudLoggingLayout::default().label_keys(["label1", "label2"]);

Trait Implementations§

Source§

impl Clone for GoogleCloudLoggingLayout

Source§

fn clone(&self) -> GoogleCloudLoggingLayout

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 GoogleCloudLoggingLayout

Source§

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

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

impl Default for GoogleCloudLoggingLayout

Source§

fn default() -> Self

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

impl Layout for GoogleCloudLoggingLayout

Source§

fn format( &self, record: &Record<'_>, diags: &[Box<dyn Diagnostic>], ) -> Result<Vec<u8>, Error>

Format a log record with optional diagnostics.

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

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