guard_core_engine/request_logging.rs
1//! The request-logging pass: the reference pipeline's fourth check.
2//!
3//! This is the Rust family's port of
4//! `guard_core/core/checks/implementations/request_logging.py`. The check
5//! **never blocks**: it logs the request through the reference
6//! `log_activity` at `config.log_request_level` (with the check name, the
7//! muted set, and the sensitive-field redaction) and returns `None`. The
8//! reference only constructs it when the level is set (`applies_to`:
9//! `log_request_level is not None`), so an unset level means the check
10//! does not exist in the pipeline at all.
11//!
12//! The engine keeps the check's contract (the name, the never-blocks
13//! decision, the construction gate); the line composition lives on the
14//! facade stage (`guard_core_rs::request_logging`), which runs the family's
15//! `log_activity` shape - the reference's log line text is a `SHOULD`
16//! match, and the verdict contract (always `None`) is a `MUST`.
17//!
18//! # Example
19//!
20//! ```
21//! use guard_core_engine::request_logging::{constructs, decide};
22//!
23//! // The construction gate: an unset level installs nothing.
24//! assert!(!constructs(None));
25//! assert!(constructs(Some("INFO")));
26//!
27//! // The verdict contract: the check never blocks.
28//! assert!(decide().is_none());
29//! ```
30
31/// The check's stable name (`check_name`).
32pub const REQUEST_LOGGING_CHECK_NAME: &str = "request_logging";
33
34/// The construction gate (`applies_to`): the check exists only when
35/// `config.log_request_level` is set. The level is the reference's
36/// `"INFO" | "DEBUG" | "WARNING" | "ERROR" | "CRITICAL"` literal.
37#[must_use]
38pub const fn constructs(log_request_level: Option<&str>) -> bool {
39 log_request_level.is_some()
40}
41
42/// The check body: it never blocks, whatever the request carries.
43#[must_use]
44pub const fn decide() -> Option<core::convert::Infallible> {
45 None
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn the_gate_mirrors_the_reference_applies_to() {
54 assert!(!constructs(None));
55 for level in ["INFO", "DEBUG", "WARNING", "ERROR", "CRITICAL"] {
56 assert!(constructs(Some(level)));
57 }
58 }
59
60 #[test]
61 fn the_check_never_blocks() {
62 assert!(decide().is_none());
63 assert_eq!(REQUEST_LOGGING_CHECK_NAME, "request_logging");
64 }
65}