pub struct GoogleCloudLoggingLayout { /* private fields */ }layout-google-cloud-logging only.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/tracefield.span_id: Set as thelogging.googleapis.com/spanIdfield.trace_sampled: Set as thelogging.googleapis.com/trace_sampledfield.
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>,
) -> GoogleCloudLoggingLayout
pub fn trace_project_id( self, project_id: impl Into<String>, ) -> GoogleCloudLoggingLayout
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");Examples found in repository?
40fn main() {
41 logforth::starter_log::builder()
42 .dispatch(|d| {
43 d.diagnostic(diagnostic::FastraceDiagnostic::default())
44 .append(
45 append::Stdout::default().with_layout(
46 GoogleCloudLoggingLayout::default()
47 .trace_project_id("project-id")
48 .label_keys(["label1"]),
49 ),
50 )
51 })
52 .apply();
53
54 fastrace::set_reporter(ConsoleReporter, Config::default());
55
56 {
57 let root = Span::root("root", SpanContext::new(TraceId::random(), SpanId(0)));
58 let _g = root.set_local_parent();
59
60 let structured_value = MyStructuredValue {
61 a: 1,
62 b: NestedStructuredValue {
63 c: "Hello".into(),
64 d: true,
65 },
66 };
67
68 log::info!(
69 label1 = "this is a label value",
70 notLabel:serde = structured_value;
71 "Hello label value!",
72 );
73 }
74}Sourcepub fn label_keys(
self,
label_keys: impl IntoIterator<Item = impl Into<String>>,
) -> GoogleCloudLoggingLayout
pub fn label_keys( self, label_keys: impl IntoIterator<Item = impl Into<String>>, ) -> GoogleCloudLoggingLayout
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"]);Examples found in repository?
40fn main() {
41 logforth::starter_log::builder()
42 .dispatch(|d| {
43 d.diagnostic(diagnostic::FastraceDiagnostic::default())
44 .append(
45 append::Stdout::default().with_layout(
46 GoogleCloudLoggingLayout::default()
47 .trace_project_id("project-id")
48 .label_keys(["label1"]),
49 ),
50 )
51 })
52 .apply();
53
54 fastrace::set_reporter(ConsoleReporter, Config::default());
55
56 {
57 let root = Span::root("root", SpanContext::new(TraceId::random(), SpanId(0)));
58 let _g = root.set_local_parent();
59
60 let structured_value = MyStructuredValue {
61 a: 1,
62 b: NestedStructuredValue {
63 c: "Hello".into(),
64 d: true,
65 },
66 };
67
68 log::info!(
69 label1 = "this is a label value",
70 notLabel:serde = structured_value;
71 "Hello label value!",
72 );
73 }
74}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