Skip to content

Commit

Permalink
feat: [#176] change logging level for SQL statements
Browse files Browse the repository at this point in the history
- SQL statements are only logged when global loggin level is `Debug`.
- Slow SQL statements are only logged when global logging level is
  `info`.
  • Loading branch information
josecelano committed Dec 20, 2023
1 parent 644d33a commit 471ec38
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/databases/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ impl Database for Mysql {
async fn new(database_url: &str) -> Self {
let connection_options = MySqlConnectOptions::from_str(database_url)
.expect("Unable to create connection options.")
.log_statements(log::LevelFilter::Error)
.log_slow_statements(log::LevelFilter::Warn, Duration::from_secs(1));
.log_statements(log::LevelFilter::Debug)
.log_slow_statements(log::LevelFilter::Info, Duration::from_secs(1));

let db = MySqlPoolOptions::new()
.connect_with(connection_options)
Expand Down
6 changes: 3 additions & 3 deletions src/databases/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ impl Database for Sqlite {
async fn new(database_url: &str) -> Self {
let connection_options = SqliteConnectOptions::from_str(database_url)
.expect("Unable to create connection options.")
.log_statements(log::LevelFilter::Error)
.log_slow_statements(log::LevelFilter::Warn, Duration::from_secs(1));
.log_statements(log::LevelFilter::Debug)
.log_slow_statements(log::LevelFilter::Info, Duration::from_secs(1));

let db = SqlitePoolOptions::new()
.connect_with(connection_options)
Expand Down Expand Up @@ -259,7 +259,7 @@ impl Database for Sqlite {
}

async fn get_categories(&self) -> Result<Vec<Category>, database::Error> {
query_as::<_, Category>("SELECT tc.category_id, tc.name, COUNT(tt.category_id) as num_torrents FROM torrust_categories tc LEFT JOIN torrust_torrents tt on tc.category_id = tt.category_id GROUP BY tc.name")
query_as::<_, Category>("SELECT tc.category_id, tc.name, COUNT(tt.category_id) as num_torrents FROM torrust_categories tc LEFT JOIN torrust_torrents tt on tc.category_id = tt.category_id GROUP BY tc.name;")
.fetch_all(&self.pool)
.await
.map_err(|_| database::Error::Error)
Expand Down

0 comments on commit 471ec38

Please sign in to comment.