google_cloud_logging/
google_cloud_logging.rs1use fastrace::Span;
18use fastrace::collector::Config;
19use fastrace::collector::ConsoleReporter;
20use fastrace::collector::SpanContext;
21use fastrace::prelude::SpanId;
22use fastrace::prelude::TraceId;
23use logforth::append;
24use logforth::diagnostic;
25use logforth::layout::GoogleCloudLoggingLayout;
26use serde::Serialize;
27
28#[derive(Serialize)]
29struct NestedStructuredValue {
30 c: String,
31 d: bool,
32}
33
34#[derive(Serialize)]
35struct MyStructuredValue {
36 a: i32,
37 b: NestedStructuredValue,
38}
39
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}