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 7daa9ea
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions sqlx-core/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,15 @@ 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,
);

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

0 comments on commit 7daa9ea

Please sign in to comment.