Skip to main content

Module log_paths

Module log_paths 

Source
Expand description

User-configurable log directory resolution (PR-5 addendum, issue #487).

End users can set both [logging] path and [audit] path at every layer; the highest-priority value wins:

  1. CLI flag (--log-dir, --audit-dir) — explicit override on the ai-memory logs / ai-memory audit subcommands.
  2. Environment variable (AI_MEMORY_LOG_DIR, AI_MEMORY_AUDIT_DIR) — useful for systemd units, Docker -e, and Kubernetes env injection.
  3. config.toml ([logging] path, [audit] path) — the long-lived per-host setting maintainers write once.
  4. Platform default — picked per-OS so a fresh install works out of the box without any configuration.

Platform defaults:

OSLogsAudit
Linux${XDG_STATE_HOME:-$HOME/.local/state}/ai-memory/logs/…/audit/
macOS~/Library/Logs/ai-memory/~/Library/Logs/ai-memory/audit/
Windows%LOCALAPPDATA%\ai-memory\logs\…\audit\
systemd-managed daemon/var/log/ai-memory/ (if writable)…/audit/

§systemd detection

When INVOCATION_ID is present in the environment (set by systemd for unit-managed processes) and /var/log/ai-memory/ is writable, the resolver picks the system-wide path. Otherwise it falls through to the per-user XDG path.

§Security guard

The resolved directory must not be world-writable. If a 0777 path is configured (or selected by default on a malformed system), the resolver returns an error pointing at the resolution chain that landed there. Created parent directories use mode 0700 on Unix; on Windows the default ACL is sufficient.

See docs/security/audit-trail.md §“Log directory resolution” for the operator guide.

Structs§

ResolvedDir
Result of a directory-resolution call. The path itself plus the layer that produced it (used for error messages).

Enums§

DirKind
What kind of log directory we’re resolving — dictates the platform default suffix (logs/ vs audit/).
PathSource
Source layer that produced the resolved path. Returned alongside the PathBuf so error messages can name the precedence step that landed the user at a bad directory.

Constants§

AUDIT_DIR_ENV
Environment variable consulted for the audit log directory override.
LOG_DIR_ENV
Environment variable consulted for the operational log directory override. Read with std::env::var_os so non-UTF-8 paths on Windows pass through unchanged.

Functions§

enforce_not_world_writable
Reject world-writable directories. Returns Ok(()) if the path doesn’t exist yet (we’ll create it secure) or if it’s safely permissioned.
ensure_dir_secure
Create dir (and missing parents) with mode 0700 on Unix. On Windows defers to std::fs::create_dir_all and the default ACL.
expand_tilde
Tilde-expand a config string. Mirrors [crate::audit::expand_tilde] so this module stays self-contained for resolver-level tests.
platform_default
Compute the platform default for kind. Pure — no filesystem touch other than reading INVOCATION_ID / XDG_STATE_HOME / HOME / LOCALAPPDATA env vars.
resolve_audit_dir
Resolve the audit log directory honouring the precedence ladder. Mirror of resolve_log_dir for the audit subsystem.
resolve_log_dir
Resolve the operational log directory honouring the precedence ladder: CLI > env var > config > platform default.