Selaa lähdekoodia

wallet: Log SQL statements in the Trace loglevel.

parazyd 4 vuotta sitten
vanhempi
sitoutus
be944c4d3a
2 muutettua tiedostoa jossa 16 lisäystä ja 10 poistoa
  1. 8 5
      src/wallet/cashierdb.rs
  2. 8 5
      src/wallet/walletdb.rs

+ 8 - 5
src/wallet/cashierdb.rs

@@ -1,11 +1,11 @@
-use incrementalmerkletree::bridgetree::BridgeTree;
-use std::{fs::create_dir_all, path::Path, str::FromStr};
+use std::{fs::create_dir_all, path::Path, str::FromStr, time::Duration};
 
 use async_std::sync::Arc;
-use log::{error, info, trace};
+use incrementalmerkletree::bridgetree::BridgeTree;
+use log::{error, info, trace, LevelFilter};
 use sqlx::{
     sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions},
-    Row, SqlitePool,
+    ConnectOptions, Row, SqlitePool,
 };
 
 use super::wallet_api::WalletApi;
@@ -64,11 +64,14 @@ impl CashierDb {
             }
         }
 
-        let connect_opts = SqliteConnectOptions::from_str(path)?
+        let mut connect_opts = SqliteConnectOptions::from_str(path)?
             .pragma("key", password)
             .create_if_missing(true)
             .journal_mode(SqliteJournalMode::Off);
 
+        connect_opts.log_statements(LevelFilter::Trace);
+        connect_opts.log_slow_statements(LevelFilter::Trace, Duration::from_micros(10));
+
         let conn = SqlitePoolOptions::new().connect_with(connect_opts).await?;
 
         info!("Opened connection at path: {:?}", path);

+ 8 - 5
src/wallet/walletdb.rs

@@ -1,12 +1,12 @@
-use incrementalmerkletree::bridgetree::BridgeTree;
-use std::{fs::create_dir_all, path::Path, str::FromStr};
+use std::{fs::create_dir_all, path::Path, str::FromStr, time::Duration};
 
 use async_std::sync::Arc;
-use log::{debug, error, info};
+use incrementalmerkletree::bridgetree::BridgeTree;
+use log::{debug, error, info, LevelFilter};
 use rand::rngs::OsRng;
 use sqlx::{
     sqlite::{SqliteConnectOptions, SqliteJournalMode},
-    Row, SqlitePool,
+    ConnectOptions, Row, SqlitePool,
 };
 
 use crate::{
@@ -60,11 +60,14 @@ impl WalletDb {
             }
         }
 
-        let connect_opts = SqliteConnectOptions::from_str(path)?
+        let mut connect_opts = SqliteConnectOptions::from_str(path)?
             .pragma("key", password)
             .create_if_missing(true)
             .journal_mode(SqliteJournalMode::Off);
 
+        connect_opts.log_statements(LevelFilter::Trace);
+        connect_opts.log_slow_statements(LevelFilter::Trace, Duration::from_micros(10));
+
         let conn = SqlitePool::connect_with(connect_opts).await?;
 
         info!("Opened connection at path {}", path);