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:
- CLI flag (
--log-dir,--audit-dir) — explicit override on theai-memory logs/ai-memory auditsubcommands. - Environment variable (
AI_MEMORY_LOG_DIR,AI_MEMORY_AUDIT_DIR) — useful forsystemdunits, Docker-e, and Kubernetes env injection. config.toml([logging] path,[audit] path) — the long-lived per-host setting maintainers write once.- Platform default — picked per-OS so a fresh install works out of the box without any configuration.
Platform defaults:
| OS | Logs | Audit |
|---|---|---|
| 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§
- Resolved
Dir - 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/vsaudit/). - Path
Source - Source layer that produced the resolved path. Returned alongside
the
PathBufso 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_osso 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 mode0700on Unix. On Windows defers tostd::fs::create_dir_alland 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 readingINVOCATION_ID/XDG_STATE_HOME/HOME/LOCALAPPDATAenv vars. - resolve_
audit_ dir - Resolve the audit log directory honouring the precedence ladder.
Mirror of
resolve_log_dirfor the audit subsystem. - resolve_
log_ dir - Resolve the operational log directory honouring the precedence ladder: CLI > env var > config > platform default.