mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 06:24:16 +00:00
Decorate send/receive with trace logs for development
This commit is contained in:
parent
735c8c366a
commit
c895ef52fe
2 changed files with 18 additions and 2 deletions
|
@ -2,6 +2,7 @@ use crate::Encode;
|
|||
use bytes::BufMut;
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Terminate;
|
||||
|
||||
impl Encode for Terminate {
|
||||
|
|
|
@ -4,6 +4,7 @@ use futures::{
|
|||
task::{Context, Poll},
|
||||
Stream,
|
||||
};
|
||||
use std::fmt::Debug;
|
||||
use runtime::net::TcpStream;
|
||||
use sqlx_core::ConnectOptions;
|
||||
use sqlx_postgres_protocol::{Encode, Message, Terminate};
|
||||
|
@ -55,12 +56,16 @@ impl Connection {
|
|||
// Send client message to the server
|
||||
async fn send<T>(&mut self, message: T) -> io::Result<()>
|
||||
where
|
||||
T: Encode,
|
||||
T: Encode + Debug,
|
||||
{
|
||||
self.wbuf.clear();
|
||||
|
||||
log::trace!("send {:?}", message);
|
||||
|
||||
message.encode(&mut self.wbuf)?;
|
||||
|
||||
log::trace!("send buffer {:?}", bytes::Bytes::from(&*self.wbuf));
|
||||
|
||||
self.stream.inner.write_all(&self.wbuf).await?;
|
||||
self.stream.inner.flush().await?;
|
||||
|
||||
|
@ -102,7 +107,17 @@ where
|
|||
}
|
||||
|
||||
loop {
|
||||
match Message::decode(&mut self_.buffer)? {
|
||||
log::trace!("recv buffer {:?}", self_.buffer);
|
||||
|
||||
let message = Message::decode(&mut self_.buffer)?;
|
||||
|
||||
if log::log_enabled!(log::Level::Trace) {
|
||||
if let Some(message) = &message {
|
||||
log::trace!("recv {:?}", message);
|
||||
}
|
||||
}
|
||||
|
||||
match message {
|
||||
Some(Message::ParameterStatus(_body)) => {
|
||||
// TODO: Not sure what to do with these but ignore
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue