fix log
This commit is contained in:
parent
9f6b73a7c0
commit
6f05da8620
5 changed files with 46 additions and 10 deletions
|
|
@ -16,14 +16,14 @@
|
||||||
echo "----------------------------"
|
echo "----------------------------"
|
||||||
echo "Benchmark on rpxy"
|
echo "Benchmark on rpxy"
|
||||||
#wrk -t8 -c100 -d30s http://127.0.0.1:8080/index.html
|
#wrk -t8 -c100 -d30s http://127.0.0.1:8080/index.html
|
||||||
rewrk -c 256 -t 8 -d 15s -h http://localhost:8080 --pct
|
rewrk -c 512 -t 4 -d 10s -h http://localhost:8080 --pct
|
||||||
|
|
||||||
echo "----------------------------"
|
echo "----------------------------"
|
||||||
echo "Benchmark on nginx"
|
echo "Benchmark on nginx"
|
||||||
# wrk -t8 -c100 -d30s http://127.0.0.1:8090/index.html
|
# wrk -t8 -c100 -d30s http://127.0.0.1:8090/index.html
|
||||||
rewrk -c 256 -t 8 -d 15s -h http://localhost:8090 --pct
|
rewrk -c 512 -t 4 -d 10s -h http://localhost:8090 --pct
|
||||||
|
|
||||||
echo "----------------------------"
|
echo "----------------------------"
|
||||||
echo "Benchmark on caddy"
|
echo "Benchmark on caddy"
|
||||||
# wrk -t8 -c100 -d30s http://127.0.0.1:8100/index.html
|
# wrk -t8 -c100 -d30s http://127.0.0.1:8100/index.html
|
||||||
rewrk -c 256 -t 8 -d 15s -h http://localhost:8100 --pct
|
rewrk -c 512 -t 4 -d 10s -h http://localhost:8100 --pct
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ services:
|
||||||
context: ../
|
context: ../
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
- LOG_LEVEL=debug
|
- LOG_LEVEL=info
|
||||||
- LOG_TO_FILE=false
|
- LOG_TO_FILE=false
|
||||||
ports:
|
ports:
|
||||||
- 127.0.0.1:8080:8080
|
- 127.0.0.1:8080:8080
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ where
|
||||||
listen_addr: SocketAddr,
|
listen_addr: SocketAddr,
|
||||||
tls_enabled: bool,
|
tls_enabled: bool,
|
||||||
) -> Result<Response<Body>> {
|
) -> Result<Response<Body>> {
|
||||||
req.log(&client_addr, Some("(Request from Client)"));
|
req.log_debug(&client_addr, Some("(Request from Client)"));
|
||||||
|
|
||||||
// Here we start to handle with server_name
|
// Here we start to handle with server_name
|
||||||
// Find backend application for given server_name, and drop if incoming request is invalid as request.
|
// Find backend application for given server_name, and drop if incoming request is invalid as request.
|
||||||
|
|
@ -98,7 +98,7 @@ where
|
||||||
return http_error(StatusCode::BAD_REQUEST);
|
return http_error(StatusCode::BAD_REQUEST);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
res_backend.log(
|
res_backend.log_debug(
|
||||||
&backend.server_name,
|
&backend.server_name,
|
||||||
&client_addr,
|
&client_addr,
|
||||||
Some("(Response from Backend)"),
|
Some("(Response from Backend)"),
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,17 @@ use std::fmt::Display;
|
||||||
// Functions of utils for request messages
|
// Functions of utils for request messages
|
||||||
pub trait ReqLog {
|
pub trait ReqLog {
|
||||||
fn log<T: Display + ToCanonical>(self, src: &T, extra: Option<&str>);
|
fn log<T: Display + ToCanonical>(self, src: &T, extra: Option<&str>);
|
||||||
|
fn log_debug<T: Display + ToCanonical>(self, src: &T, extra: Option<&str>);
|
||||||
|
fn build_message<T: Display + ToCanonical>(self, src: &T, extra: Option<&str>) -> String;
|
||||||
}
|
}
|
||||||
impl<B> ReqLog for &Request<B> {
|
impl<B> ReqLog for &Request<B> {
|
||||||
fn log<T: Display + ToCanonical>(self, src: &T, extra: Option<&str>) {
|
fn log<T: Display + ToCanonical>(self, src: &T, extra: Option<&str>) {
|
||||||
|
info!("{}", &self.build_message(src, extra));
|
||||||
|
}
|
||||||
|
fn log_debug<T: Display + ToCanonical>(self, src: &T, extra: Option<&str>) {
|
||||||
|
debug!("{}", &self.build_message(src, extra));
|
||||||
|
}
|
||||||
|
fn build_message<T: Display + ToCanonical>(self, src: &T, extra: Option<&str>) -> String {
|
||||||
let canonical_src = src.to_canonical();
|
let canonical_src = src.to_canonical();
|
||||||
|
|
||||||
let server_name = self.headers().get(header::HOST).map_or_else(
|
let server_name = self.headers().get(header::HOST).map_or_else(
|
||||||
|
|
@ -20,7 +28,7 @@ impl<B> ReqLog for &Request<B> {
|
||||||
},
|
},
|
||||||
|h| h.to_str().unwrap_or("<none>"),
|
|h| h.to_str().unwrap_or("<none>"),
|
||||||
);
|
);
|
||||||
info!(
|
format!(
|
||||||
"{} <- {} -- {} {:?} {:?} {:?} {}",
|
"{} <- {} -- {} {:?} {:?} {:?} {}",
|
||||||
server_name,
|
server_name,
|
||||||
canonical_src,
|
canonical_src,
|
||||||
|
|
@ -32,7 +40,7 @@ impl<B> ReqLog for &Request<B> {
|
||||||
.map_or_else(|| "", |v| v.as_str()),
|
.map_or_else(|| "", |v| v.as_str()),
|
||||||
self.headers(),
|
self.headers(),
|
||||||
extra.map_or_else(|| "", |v| v)
|
extra.map_or_else(|| "", |v| v)
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,18 @@ pub trait ResLog {
|
||||||
client_addr: &T2,
|
client_addr: &T2,
|
||||||
extra: Option<&str>,
|
extra: Option<&str>,
|
||||||
);
|
);
|
||||||
|
fn log_debug<T1: Display, T2: Display + ToCanonical>(
|
||||||
|
self,
|
||||||
|
server_name: &T1,
|
||||||
|
client_addr: &T2,
|
||||||
|
extra: Option<&str>,
|
||||||
|
);
|
||||||
|
fn build_message<T1: Display, T2: Display + ToCanonical>(
|
||||||
|
self,
|
||||||
|
server_name: &T1,
|
||||||
|
client_addr: &T2,
|
||||||
|
extra: Option<&str>,
|
||||||
|
) -> String;
|
||||||
}
|
}
|
||||||
impl<B> ResLog for &Response<B> {
|
impl<B> ResLog for &Response<B> {
|
||||||
fn log<T1: Display, T2: Display + ToCanonical>(
|
fn log<T1: Display, T2: Display + ToCanonical>(
|
||||||
|
|
@ -19,8 +31,24 @@ impl<B> ResLog for &Response<B> {
|
||||||
client_addr: &T2,
|
client_addr: &T2,
|
||||||
extra: Option<&str>,
|
extra: Option<&str>,
|
||||||
) {
|
) {
|
||||||
|
info!("{}", &self.build_message(server_name, client_addr, extra));
|
||||||
|
}
|
||||||
|
fn log_debug<T1: Display, T2: Display + ToCanonical>(
|
||||||
|
self,
|
||||||
|
server_name: &T1,
|
||||||
|
client_addr: &T2,
|
||||||
|
extra: Option<&str>,
|
||||||
|
) {
|
||||||
|
debug!("{}", &self.build_message(server_name, client_addr, extra));
|
||||||
|
}
|
||||||
|
fn build_message<T1: Display, T2: Display + ToCanonical>(
|
||||||
|
self,
|
||||||
|
server_name: &T1,
|
||||||
|
client_addr: &T2,
|
||||||
|
extra: Option<&str>,
|
||||||
|
) -> String {
|
||||||
let canonical_client_addr = client_addr.to_canonical();
|
let canonical_client_addr = client_addr.to_canonical();
|
||||||
info!(
|
format!(
|
||||||
"{} <- {} -- {} {:?} {:?} {}",
|
"{} <- {} -- {} {:?} {:?} {}",
|
||||||
canonical_client_addr,
|
canonical_client_addr,
|
||||||
server_name,
|
server_name,
|
||||||
|
|
@ -28,6 +56,6 @@ impl<B> ResLog for &Response<B> {
|
||||||
self.version(),
|
self.version(),
|
||||||
self.headers(),
|
self.headers(),
|
||||||
extra.map_or_else(|| "", |v| v)
|
extra.map_or_else(|| "", |v| v)
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue