mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
fix(logging): host-side log fallback writes to ./data/logs, not a duplicate ./logs
_resolve_log_dir fell back to ./logs (relative to CWD) whenever /data was
absent — i.e. every host-side run (pytest, scripts, the dev orchestrator).
The container writes to /data/logs, whose host side is the compose mount
${ROBOCO_DATA_DIR:-./data}/logs, so ./logs and ./data/logs were two
different directories. Point the host-side fallback at that same
${ROBOCO_DATA_DIR:-./data}/logs, eliminating the duplicate ./logs at the
repo root.
This commit is contained in:
+6
-2
@@ -173,7 +173,11 @@ def _resolve_log_dir() -> Path | None:
|
||||
Order of precedence:
|
||||
1. $ROBOCO_LOG_DIR (explicit override).
|
||||
2. /data/logs — standard mount from docker-compose inside containers.
|
||||
3. ./logs — local dev fallback, relative to CWD.
|
||||
3. ${ROBOCO_DATA_DIR:-./data}/logs — host-side fallback. This is the SAME
|
||||
directory the compose mount maps to /data/logs, so a host-side run
|
||||
(pytest, a script, the dev orchestrator — where /data does not exist)
|
||||
writes into ./data/logs instead of creating a separate ./logs at the
|
||||
repo root that duplicates the real log location.
|
||||
4. None — disables file logging (caller just uses stdout).
|
||||
"""
|
||||
override = os.environ.get("ROBOCO_LOG_DIR")
|
||||
@@ -182,7 +186,7 @@ def _resolve_log_dir() -> Path | None:
|
||||
container_path = Path("/data/logs")
|
||||
if container_path.is_dir() or container_path.parent.is_dir():
|
||||
return container_path
|
||||
return Path("./logs")
|
||||
return Path(os.environ.get("ROBOCO_DATA_DIR", "./data")) / "logs"
|
||||
|
||||
|
||||
def get_logger(name: str | None = None) -> BoundLogger:
|
||||
|
||||
@@ -196,8 +196,11 @@ class _NonexistentPath:
|
||||
|
||||
|
||||
def test_resolve_log_dir_dev_fallback(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""When neither override nor container path exist, fall back to ./logs."""
|
||||
"""When neither override nor container path exist, fall back to the data dir's
|
||||
logs (./data/logs) — the SAME directory the compose mount maps to /data/logs,
|
||||
so a host-side run never creates a separate ./logs at the repo root."""
|
||||
monkeypatch.delenv("ROBOCO_LOG_DIR", raising=False)
|
||||
monkeypatch.delenv("ROBOCO_DATA_DIR", raising=False)
|
||||
|
||||
real_path = Path
|
||||
|
||||
@@ -209,7 +212,26 @@ def test_resolve_log_dir_dev_fallback(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
with patch("roboco.logging.Path", side_effect=fake_path):
|
||||
out = _resolve_log_dir()
|
||||
assert isinstance(out, Path)
|
||||
assert str(out) == "logs"
|
||||
assert str(out) == "data/logs"
|
||||
|
||||
|
||||
def test_resolve_log_dir_dev_fallback_honors_data_dir(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""The host-side fallback honors $ROBOCO_DATA_DIR so it matches the mount."""
|
||||
monkeypatch.delenv("ROBOCO_LOG_DIR", raising=False)
|
||||
monkeypatch.setenv("ROBOCO_DATA_DIR", "/srv/roboco/data")
|
||||
|
||||
real_path = Path
|
||||
|
||||
def fake_path(p: str) -> object:
|
||||
if str(p) == "/data/logs":
|
||||
return _NonexistentPath()
|
||||
return real_path(p)
|
||||
|
||||
with patch("roboco.logging.Path", side_effect=fake_path):
|
||||
out = _resolve_log_dir()
|
||||
assert str(out) == "/srv/roboco/data/logs"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user