Skip to content

Commit

Permalink
Extract slow query threshold to constant
Browse files Browse the repository at this point in the history
  • Loading branch information
shssoichiro authored and abonander committed Apr 23, 2020
1 parent 627d829 commit 581bcf0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sqlx-core/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use std::time::Duration;

pub(crate) const SLOW_QUERY_THRESHOLD: Duration = Duration::from_secs(1);

/// Logs the query and execution time of a statement as it runs.
macro_rules! log_execution {
( $query:expr, $block:expr ) => {{
Expand All @@ -6,7 +10,7 @@ macro_rules! log_execution {
let timer = std::time::Instant::now();
let result = $block;
let elapsed = timer.elapsed();
if elapsed >= std::time::Duration::from_secs(1) {
if elapsed >= crate::logging::SLOW_QUERY_THRESHOLD {
log::warn!(
target: "sqlx::query",
"{} ..., elapsed: {:.3?}\n\n{}\n",
Expand Down

0 comments on commit 581bcf0

Please sign in to comment.