Add some logging so that with the env variable RUST_LOG=debug or similar, there is timestamped output to stderr

This commit is contained in:
Barry Pederson
2026-02-03 15:57:11 -08:00
parent 83d437c9ce
commit 1de0fa16db
6 changed files with 151 additions and 5 deletions
+7 -4
View File
@@ -1,5 +1,6 @@
use crate::repository::PasswordDirectory;
use common::request::Request;
use log::{error, info};
use std::io::{Error, Read, Write};
pub const RESPONSE_NO: [u8; 4] = [0x0, 0x2, b'N', b'O'];
@@ -18,19 +19,21 @@ impl<S: Read + Write> Handler<S> {
fn communicate(&mut self) -> Result<(), Error> {
let request = Request::from_stream(&mut self.stream)?;
println!("userid: {}", request.userid);
if self.repository.check_auth(&request) {
self.stream.write_all(&RESPONSE_OK)?
self.stream.write_all(&RESPONSE_OK)?;
info!("userid: {}, service: {}, realm: {} - OK", request.userid, request.service, request.realm);
} else {
self.stream.write_all(&RESPONSE_NO)?
self.stream.write_all(&RESPONSE_NO)?;
info!("userid: {}, service: {}, realm: {} - FAIL", request.userid, request.service, request.realm);
}
Ok(())
}
pub fn handle_client(&mut self) {
if let Err(error) = self.communicate() {
eprint!("{error}");
error!("{error}");
}
}
}