Unable to log queries even though .log_statements(LevelFilter::Trace) is used?
#3777
-
|
It seems like much of the community here already has statement logging by default but I have not observed any such case (I could be wrong here as I don't see any logs coming through). Here's a minimal viable example: use std::str::FromStr;
use sqlx::{
sqlite::{SqliteConnectOptions, SqlitePoolOptions},
ConnectOptions,
};
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
dotenvy::dotenv().unwrap();
let db_url = std::env::var("DATABASE_URL").unwrap();
let options = SqliteConnectOptions::from_str(&db_url)
.unwrap()
.log_statements(tracing::log::LevelFilter::Trace);
let pool = SqlitePoolOptions::new()
.connect_with(options)
.await
.unwrap();
let mut connection = pool.acquire().await.unwrap();
sqlx::query!("INSERT INTO some (name) VALUES ('wee')")
.execute(&mut *connection)
.await
.unwrap();
let results = sqlx::query!("SELECT name from some")
.fetch_all(&mut *connection)
.await
.unwrap();
tracing::info!("All results: {:?}", results);
let _ = sqlx::query("SELECT name from some")
.fetch_all(&mut *connection)
.await
.unwrap();
}Output: Am I doing something wrong here? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
That just enables emission of tracing and log records at Using |
Beta Was this translation helpful? Give feedback.
That just enables emission of tracing and log records at
TRACElevel. You need to setRUST_LOG=sqlx::query=traceto actually get the logs.Using
LevelFiltermay have been a misstep in API design, since it's not actually being used as a filter here. We chose it instead ofLevelbecause it also has anOfflevel, but that may have been more intuitive to model asOption<Level>instead.