Skip to content

Commit 471ec38

Browse files
committed
feat: [#176] change logging level for SQL statements
- SQL statements are only logged when global loggin level is `Debug`. - Slow SQL statements are only logged when global logging level is `info`.
1 parent 644d33a commit 471ec38

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/databases/mysql.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ impl Database for Mysql {
3434
async fn new(database_url: &str) -> Self {
3535
let connection_options = MySqlConnectOptions::from_str(database_url)
3636
.expect("Unable to create connection options.")
37-
.log_statements(log::LevelFilter::Error)
38-
.log_slow_statements(log::LevelFilter::Warn, Duration::from_secs(1));
37+
.log_statements(log::LevelFilter::Debug)
38+
.log_slow_statements(log::LevelFilter::Info, Duration::from_secs(1));
3939

4040
let db = MySqlPoolOptions::new()
4141
.connect_with(connection_options)

src/databases/sqlite.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ impl Database for Sqlite {
3434
async fn new(database_url: &str) -> Self {
3535
let connection_options = SqliteConnectOptions::from_str(database_url)
3636
.expect("Unable to create connection options.")
37-
.log_statements(log::LevelFilter::Error)
38-
.log_slow_statements(log::LevelFilter::Warn, Duration::from_secs(1));
37+
.log_statements(log::LevelFilter::Debug)
38+
.log_slow_statements(log::LevelFilter::Info, Duration::from_secs(1));
3939

4040
let db = SqlitePoolOptions::new()
4141
.connect_with(connection_options)
@@ -259,7 +259,7 @@ impl Database for Sqlite {
259259
}
260260

261261
async fn get_categories(&self) -> Result<Vec<Category>, database::Error> {
262-
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")
262+
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;")
263263
.fetch_all(&self.pool)
264264
.await
265265
.map_err(|_| database::Error::Error)

0 commit comments

Comments
 (0)