pub struct PromptLogger { /* private fields */ }Expand description
Best-effort rolling JSONL writer.
Why: hook commands are short-lived (one entry per invocation), so the
logger is constructed at the start of the invocation, writes one line,
and drops at the end. There is no daemon path involved; cross-process
concurrency is handled by OpenOptions::append(true) which O_APPEND
atomically positions each write at end-of-file on POSIX. On Windows
(not a target for this crate) the same flag delivers similar guarantees
for writes under the 4 KiB pipe-atomicity threshold, which our JSONL
lines comfortably fit under.
What: holds an immutable PromptLogConfig. log resolves the active
filename (date + numeric suffix that fits under max_bytes), opens the
file in append mode, writes one line, then closes it. Every failure
path is a tracing::warn! to stderr; the caller never observes an
error.
Test: single_event_roundtrip, rotation_at_size_cap,
retention_prunes_old_files, disabled_mode_writes_nothing,
hash_mode_hashes_trigger_prompt.
Implementations§
Source§impl PromptLogger
impl PromptLogger
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Build a logger from the configured data_root and process env vars.
Why: keeps the call site in prompt_context.rs / inbox_check.rs to
a single line and centralises the env-parsing rules.
What: resolves <data_root> via trusty_common::resolve_data_dir
using the canonical trusty-memory app name, then layers env overrides
via PromptLogConfig::from_env_with_root. Returns a disabled logger
when the data dir cannot be resolved — the caller proceeds normally.
Test: covered indirectly by the integration tests.
Sourcepub fn from_config(config: PromptLogConfig) -> Self
pub fn from_config(config: PromptLogConfig) -> Self
Build a logger from an explicit config (test injection point).
Why: integration / unit tests want to pin a tempdir without polluting
process env. Same shape as from_env, different injection.
Test: every unit test in this module.
Sourcepub fn config(&self) -> &PromptLogConfig
pub fn config(&self) -> &PromptLogConfig
Active configuration (for tests / diagnostics).
Sourcepub fn log(&self, entry: PromptLogEntry)
pub fn log(&self, entry: PromptLogEntry)
Append one entry to the active log file.
Why: the public API surface — exactly one call per hook invocation.
Best-effort by contract.
What: short-circuits when enabled = false; otherwise computes the
active filename (creating the directory and pruning stale files as
needed), serialises the entry to a single JSON line, and appends it.
Any failure (mkdir, open, write, serde) is downgraded to a
tracing::warn! and discarded.
Test: see module-level tests.
Trait Implementations§
Source§impl Clone for PromptLogger
impl Clone for PromptLogger
Source§fn clone(&self) -> PromptLogger
fn clone(&self) -> PromptLogger
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for PromptLogger
impl RefUnwindSafe for PromptLogger
impl Send for PromptLogger
impl Sync for PromptLogger
impl Unpin for PromptLogger
impl UnsafeUnpin for PromptLogger
impl UnwindSafe for PromptLogger
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more