add basic logger
This commit is contained in:
@@ -4,6 +4,7 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4.41"
|
||||
http-body-util = "0.1.3"
|
||||
hyper = { version = "1.6.0", features = ["full"] }
|
||||
hyper-util = { version = "0.1.11", features = ["full"] }
|
||||
|
20
theseus-server/src/logger.rs
Normal file
20
theseus-server/src/logger.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
#[macro_export]
|
||||
macro_rules! log {
|
||||
(info $text: literal$(, $($arg: expr),*$(,)?)?) => {
|
||||
let now = chrono::Local::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, false);
|
||||
println!(concat!("[{}] INFO ", $text), now, $($($arg),*)?);
|
||||
};
|
||||
|
||||
(debug $text: literal$(, $($arg: expr),*$(,)?)?) => {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
let now = chrono::Local::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, false);
|
||||
println!(concat!("[{}] DEBUG ", $text), now, $($($arg),*)?);
|
||||
}
|
||||
};
|
||||
|
||||
(err $text: literal$(, $($arg: expr),*$(,)?)?) => {
|
||||
let now = chrono::Local::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, false);
|
||||
println!(concat!("[{}] ERROR ", $text), now, $($($arg),*)?);
|
||||
};
|
||||
}
|
@@ -6,6 +6,7 @@ use hyper::{
|
||||
use hyper_util::rt::TokioIo;
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
mod logger;
|
||||
mod args;
|
||||
mod config;
|
||||
|
||||
@@ -61,11 +62,12 @@ async fn main() {
|
||||
};
|
||||
|
||||
loop {
|
||||
let Ok((stream, _)) = listener.accept().await else {
|
||||
let Ok((stream, addr)) = listener.accept().await else {
|
||||
eprintln!("unable to accept new connections");
|
||||
return;
|
||||
};
|
||||
let io = TokioIo::new(stream);
|
||||
log!(debug "new connection from {:?}", addr);
|
||||
let state_clone = state.clone();
|
||||
tokio::task::spawn(async move {
|
||||
if let Err(_) = http1::Builder::new().serve_connection(io, service_fn(move |req| {
|
||||
|
Reference in New Issue
Block a user