Skip to content

Commit

Permalink
chore: Use tracing's fields to get structured logs
Browse files Browse the repository at this point in the history
This also enables on services that can query this data to get useful metrics
  • Loading branch information
jaysonsantos committed Feb 24, 2023
1 parent c17c59f commit 4807087
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sqlx-core/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,16 @@ impl<'q> QueryLogger<'q> {
String::new()
};

let message = format!(
"{}; rows affected: {}, rows returned: {}, elapsed: {:.3?}{}",
summary, self.rows_affected, self.rows_returned, elapsed, sql
private_tracing_dynamic_event!(
target: "sqlx::query",
tracing_level,
summary,
db.statement = sql,
rows_affected = self.rows_affected,
rows_returned= self.rows_returned,
?elapsed,
sql,
);

private_tracing_dynamic_event!(target: "sqlx::query", tracing_level, message);
}
}
}
Expand Down

0 comments on commit 4807087

Please sign in to comment.