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 thelogging.googleapis.com/trace
field.span_id
: Set as thelogging.googleapis.com/spanId
field.trace_sampled
: Set as thelogging.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
impl GoogleCloudLoggingLayout
Sourcepub fn trace_project_id(self, project_id: impl Into<String>) -> Self
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");
Sourcepub fn label_keys(
self,
label_keys: impl IntoIterator<Item = impl Into<String>>,
) -> Self
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
impl Clone for GoogleCloudLoggingLayout
Source§fn clone(&self) -> GoogleCloudLoggingLayout
fn clone(&self) -> GoogleCloudLoggingLayout
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more