forked from scylladb/scylla-rust-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.rs
26 lines (21 loc) · 971 Bytes
/
logging.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use anyhow::Result;
use scylla::transport::session::Session;
use scylla::SessionBuilder;
use std::env;
use tracing::info;
// To run this example, and view logged messages, RUST_LOG env var needs to be set
// This can be done using shell command presented below
// RUST_LOG=info cargo run --example logging
#[tokio::main]
async fn main() -> Result<()> {
// Install global collector configured based on RUST_LOG env var
// This collector will receive logs from the driver
tracing_subscriber::fmt::init();
let uri = env::var("SCYLLA_URI").unwrap_or_else(|_| "127.0.0.1:9042".to_string());
info!("Connecting to {}", uri);
let session: Session = SessionBuilder::new().known_node(uri).build().await?;
session.query("CREATE KEYSPACE IF NOT EXISTS ks WITH REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1}", &[]).await?;
// This query should generate a warning message
session.query("USE ks", &[]).await?;
Ok(())
}