pub struct Log;Expand description
Logging helpers for access logs and server info.
Log::combined produces standard Combined Log Format lines compatible with
GoAccess, AWStats, and similar tools. All three server code paths (HTTP/1.1,
HTTP/2, HTTP/3) use it.
Implementations§
Source§impl Log
impl Log
Sourcepub fn request_response(
request: &Request,
response: &Response,
peer_addr: &SocketAddr,
) -> String
pub fn request_response( request: &Request, response: &Response, peer_addr: &SocketAddr, ) -> String
A multi-line debugging dump of a request and its response, headers
included — the values of Authorization, Proxy-Authorization,
Cookie, Set-Cookie and of RWS_CONFIG_LOG_REDACT_HEADERS shown as
REDACTED (since 18.33.0).
pub fn usage_information() -> String
Sourcepub fn current_user() -> String
pub fn current_user() -> String
The user rws runs as, for the startup banner: $USER, $LOGNAME or
%USERNAME%, else "unknown". Deliberately not whoami (what
FileExt::get_current_user runs): minimal container images such as
distroless have no whoami, and the banner’s unwrap() on that
error crashed the published Docker image at startup.
pub fn info(name: &str) -> String
Sourcepub fn json(
request: &Request,
response: &Response,
peer_addr: &SocketAddr,
) -> String
pub fn json( request: &Request, response: &Response, peer_addr: &SocketAddr, ) -> String
Returns a structured JSON log line for one request/response pair:
time, remote_addr, method, path, protocol, status, bytes,
then host, user_agent and referer when the request has them.
Enable with RWS_CONFIG_LOG_FORMAT=json. Useful for log aggregators
(Loki, Fluentd, Datadog) that ingest JSON from pod stdout.
Sourcepub fn log_access(
request: &Request,
response: &Response,
peer_addr: &SocketAddr,
)
pub fn log_access( request: &Request, response: &Response, peer_addr: &SocketAddr, )
Writes one access log line to stdout using the format configured by
RWS_CONFIG_LOG_FORMAT ("combined" or "json"). Call this instead of
Log::combined so that format selection is centralised.
Lines are buffered per thread and written by a background thread every
100 ms (and when a thread’s buffer passes 32 KiB, when the thread
exits, and at process exit); Log::flush_access_log writes them now.
Sourcepub fn reopen_access_log_on_sigusr1()
pub fn reopen_access_log_on_sigusr1()
Have SIGUSR1 reopen the access-log file (RWS_CONFIG_ACCESS_LOG)
before its next write, for logrotate; does nothing when the log goes
to stdout. The rws binary calls it at startup.
Sourcepub fn reopen_access_log()
pub fn reopen_access_log()
Reopen the access-log file before its next write — what SIGUSR1
does, for a program that moves the file itself.
Sourcepub fn flush_access_log()
pub fn flush_access_log()
Write out the buffered access-log lines now (they’re otherwise written
within 100 ms) — e.g. before exiting without returning from main.
Sourcepub fn access_log_line(
request: &Request,
response: &Response,
peer_addr: &SocketAddr,
) -> Option<String>
pub fn access_log_line( request: &Request, response: &Response, peer_addr: &SocketAddr, ) -> Option<String>
The access-log line for RWS_CONFIG_LOG_FORMAT: json (the rws
binary’s default), Combined Log Format for any other value (including
unset, in library use), or None for off/none — no per-request
line, e.g. behind a proxy that already logs or when benchmarking.
Taken from ServerConfig::current(), so it’s hot-reloadable.
Sourcepub fn combined(
request: &Request,
response: &Response,
peer_addr: &SocketAddr,
) -> String
pub fn combined( request: &Request, response: &Response, peer_addr: &SocketAddr, ) -> String
Returns a Combined Log Format (CLF) line for one request/response pair:
IP - - [DD/Mon/YYYY:HH:MM:SS +0000] "METHOD URI VERSION" STATUS SIZE
pub fn server_url_thread_count( protocol: &str, bind_addr: &String, thread_count: i32, ) -> String
Auto Trait Implementations§
impl Freeze for Log
impl RefUnwindSafe for Log
impl Send for Log
impl Sync for Log
impl Unpin for Log
impl UnsafeUnpin for Log
impl UnwindSafe for Log
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
map-response-body only.Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
trace only.Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
trace only.