Add debug logging (#39)

* Add debug for easier debugging

* fmt

* a couple more messages
This commit is contained in:
Lev Kokotov
2022-02-22 19:26:08 -08:00
committed by GitHub
parent af1716bcd7
commit dce72ba262
3 changed files with 61 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
use bytes::{Buf, BufMut, BytesMut};
///! Implementation of the PostgreSQL server (database) protocol.
///! Here we are pretending to the a Postgres client.
use log::{error, info};
use log::{debug, error, info};
use tokio::io::{AsyncReadExt, BufReader};
use tokio::net::{
tcp::{OwnedReadHalf, OwnedWriteHalf},
@@ -75,6 +75,8 @@ impl Server {
}
};
debug!("Sending StartupMessage");
// Send the startup packet telling the server we're a normal Postgres client.
startup(&mut stream, &user.name, database).await?;
@@ -95,6 +97,8 @@ impl Server {
Err(_) => return Err(Error::SocketError),
};
debug!("Message: {}", code);
match code {
// Authentication
'R' => {
@@ -104,6 +108,8 @@ impl Server {
Err(_) => return Err(Error::SocketError),
};
debug!("Auth: {}", auth_code);
match auth_code {
MD5_ENCRYPTED_PASSWORD => {
// The salt is 4 bytes.
@@ -135,6 +141,8 @@ impl Server {
Err(_) => return Err(Error::SocketError),
};
debug!("Error: {}", error_code);
match error_code {
// No error message is present in the message.
MESSAGE_TERMINATOR => (),
@@ -247,6 +255,8 @@ impl Server {
}
};
debug!("Sending CancelRequest");
let mut bytes = BytesMut::with_capacity(16);
bytes.put_i32(16);
bytes.put_i32(CANCEL_REQUEST_CODE);
@@ -290,6 +300,8 @@ impl Server {
let code = message.get_u8() as char;
let _len = message.get_i32();
debug!("Message: {}", code);
match code {
// ReadyForQuery
'Z' => {