Initial codebase structure
- Complete Gemini server implementation with logging - Add comprehensive documentation (README.md, AGENTS.md) - Implement certificate management guidelines - Add .gitignore for security and build artifacts - All unit tests passing (14/14) - Ready for production deployment
This commit is contained in:
commit
1ed443ff2a
10 changed files with 639 additions and 0 deletions
52
src/logging.rs
Normal file
52
src/logging.rs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
use tokio::net::TcpStream;
|
||||
use tokio_rustls::server::TlsStream;
|
||||
|
||||
pub struct RequestLogger {
|
||||
client_ip: String,
|
||||
request_url: String,
|
||||
}
|
||||
|
||||
impl RequestLogger {
|
||||
pub fn new(stream: &TlsStream<TcpStream>, request_url: String) -> Self {
|
||||
let client_ip = extract_client_ip(stream);
|
||||
|
||||
Self {
|
||||
client_ip,
|
||||
request_url,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn log_success(self, status_code: u8) {
|
||||
println!("{} \"{}\" {}", self.client_ip, self.request_url, status_code);
|
||||
}
|
||||
|
||||
pub fn log_error(self, status_code: u8, error_message: &str) {
|
||||
eprintln!("{} \"{}\" {} \"{}\"", self.client_ip, self.request_url, status_code, error_message);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
fn extract_client_ip(stream: &TlsStream<TcpStream>) -> String {
|
||||
match stream.get_ref() {
|
||||
(tcp_stream, _) => {
|
||||
match tcp_stream.peer_addr() {
|
||||
Ok(addr) => addr.to_string(),
|
||||
Err(_) => "unknown".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_logging(_level: &str) {
|
||||
// Simple logging using stdout/stderr - systemd will capture this
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_basic_functionality() {
|
||||
// Basic test to ensure logging module compiles
|
||||
assert!(true);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue