basic/
basic.rs

1// A basic example demonstrating how to use the nano-gcp-logging crate
2// to send logs to Google Cloud Logging.
3use nano_gcp_logging::GcpLoggingLayer;
4use tracing::{error, info, warn};
5use tracing_subscriber::{layer::SubscriberExt, Registry};
6
7#[tokio::main]
8async fn main() -> Result<(), Box<dyn std::error::Error>> {
9    // Replace with your actual GCP project ID
10    let project_id = "your-gcp-project-id".to_string();
11
12    // Initialize the GCP logging layer
13    let gcp_layer = GcpLoggingLayer::new(project_id).await?;
14
15    // Set up the tracing subscriber with the GCP logging layer
16    let subscriber = Registry::default().with(gcp_layer);
17    tracing::subscriber::set_global_default(subscriber)?;
18
19    // Emit some log events
20    info!("Hello from nano-gcp-logging!");
21    warn!("This is a warning example.");
22    error!("This is an error example.");
23
24    Ok(())
25}